From ae052c735687d1090ae93cad76c895793bcfea41 Mon Sep 17 00:00:00 2001 From: YarikMix <43493788+YarikMix@users.noreply.github.com> Date: Thu, 29 Feb 2024 23:27:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=20=D0=BA=D0=BD?= =?UTF-8?q?=D0=BE=D0=BF=D0=BA=D0=B8-=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B8,?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B2=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B4=D0=B0=D1=86=D0=B8=D1=8E=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20=D1=80=D0=B5=D0=B3=D0=B8?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.sh | 1 - public/build/button.js | 1 + public/build/footer.js | 1 + public/build/header.js | 1 + public/build/home.js | 1 + public/build/image.js | 1 + public/build/input.js | 1 + public/build/link.js | 1 + public/build/login.js | 1 + public/build/main.js | 1 + public/build/not-found.js | 1 + public/build/note-editor.js | 1 + public/build/note.js | 1 + public/build/notes.js | 1 + public/build/profile.js | 1 + public/build/register.js | 1 + public/build/wrapper.js | 1 + public/config.js | 4 +- public/index.css | 1 - public/src/components/button/button.css | 8 +-- public/src/components/button/button.js | 15 +++--- public/src/components/header/header.js | 13 ++--- public/src/components/home/home.js | 9 +++- .../components/link-button/link-button.css | 27 ---------- .../components/link-button/link-button.hbs | 3 -- .../src/components/link-button/link-button.js | 43 --------------- public/src/pages/notFound/not-found.js | 10 ++-- public/src/pages/register/register.js | 25 ++++++++- public/src/shared/validation.js | 54 +++++++++++++++++++ 29 files changed, 130 insertions(+), 99 deletions(-) create mode 100644 public/build/button.js create mode 100644 public/build/footer.js create mode 100644 public/build/header.js create mode 100644 public/build/home.js create mode 100644 public/build/image.js create mode 100644 public/build/input.js create mode 100644 public/build/link.js create mode 100644 public/build/login.js create mode 100644 public/build/main.js create mode 100644 public/build/not-found.js create mode 100644 public/build/note-editor.js create mode 100644 public/build/note.js create mode 100644 public/build/notes.js create mode 100644 public/build/profile.js create mode 100644 public/build/register.js create mode 100644 public/build/wrapper.js delete mode 100644 public/src/components/link-button/link-button.css delete mode 100644 public/src/components/link-button/link-button.hbs delete mode 100644 public/src/components/link-button/link-button.js create mode 100644 public/src/shared/validation.js diff --git a/build.sh b/build.sh index 58d12c44..8c9bbdc6 100644 --- a/build.sh +++ b/build.sh @@ -16,4 +16,3 @@ handlebars -m public/src/components/input/input.hbs -f public/build/input.js handlebars -m public/src/components/wrapper/wrapper.hbs -f public/build/wrapper.js handlebars -m public/src/components/footer/footer.hbs -f public/build/footer.js handlebars -m public/src/components/button/button.hbs -f public/build/button.js -handlebars -m public/src/components/link-button/link-button.hbs -f public/build/link-button.js diff --git a/public/build/button.js b/public/build/button.js new file mode 100644 index 00000000..f6040716 --- /dev/null +++ b/public/build/button.js @@ -0,0 +1 @@ +!function(){var t=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["button.hbs"]=t({compiler:[8,">= 4.3.0"],main:function(t,n,l,e,a){var o,u=null!=n?n:t.nullContext||{},s=t.hooks.helperMissing,r="function",i=t.escapeExpression,t=t.lookupProperty||function(t,n){if(Object.prototype.hasOwnProperty.call(t,n))return t[n]};return'"},useData:!0})}(); \ No newline at end of file diff --git a/public/build/footer.js b/public/build/footer.js new file mode 100644 index 00000000..87e35fd0 --- /dev/null +++ b/public/build/footer.js @@ -0,0 +1 @@ +!function(){var e=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["footer.hbs"]=e({compiler:[8,">= 4.3.0"],main:function(e,a,t,n,r){return""},useData:!0})}(); \ No newline at end of file diff --git a/public/build/header.js b/public/build/header.js new file mode 100644 index 00000000..d8cc89da --- /dev/null +++ b/public/build/header.js @@ -0,0 +1 @@ +!function(){var n=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["header.hbs"]=n({compiler:[8,">= 4.3.0"],main:function(n,e,a,t,r){return''},useData:!0})}(); \ No newline at end of file diff --git a/public/build/home.js b/public/build/home.js new file mode 100644 index 00000000..25212cc3 --- /dev/null +++ b/public/build/home.js @@ -0,0 +1 @@ +!function(){var n=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["home.hbs"]=n({compiler:[8,">= 4.3.0"],main:function(n,t,e,s,l){var o=n.lookupProperty||function(n,t){if(Object.prototype.hasOwnProperty.call(n,t))return n[t]};return'
\n\n\t
\n\t\t

Попробуйте наши заметки!

\n\t
\n\n\t
\n\t\t

Ля-ля-ля

\n\t
\n\n\t
\n\t\t

Ня-ня-ня

\n\t
\n\n
'},useData:!0})}(); \ No newline at end of file diff --git a/public/build/image.js b/public/build/image.js new file mode 100644 index 00000000..23289f77 --- /dev/null +++ b/public/build/image.js @@ -0,0 +1 @@ +!function(){var e=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["image.hbs"]=e({compiler:[8,">= 4.3.0"],main:function(e,a,n,l,t){var o=e.lookupProperty||function(e,a){if(Object.prototype.hasOwnProperty.call(e,a))return e[a]};return''},useData:!0})}(); \ No newline at end of file diff --git a/public/build/input.js b/public/build/input.js new file mode 100644 index 00000000..9813a690 --- /dev/null +++ b/public/build/input.js @@ -0,0 +1 @@ +!function(){var l=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["input.hbs"]=l({1:function(l,n,e,a,t){return' \n'},compiler:[8,">= 4.3.0"],main:function(l,n,e,a,t){var o,s=null!=n?n:l.nullContext||{},c=l.hooks.helperMissing,i="function",r=l.escapeExpression,u=l.lookupProperty||function(l,n){if(Object.prototype.hasOwnProperty.call(l,n))return l[n]};return'
\n \n\n'+(null!=(r=u(e,"if").call(s,null!=n?u(n,"isPassword"):n,{name:"if",hash:{},fn:l.program(1,t,0),inverse:l.noop,data:t,loc:{start:{line:4,column:4},end:{line:6,column:11}}}))?r:"")+"
\n"},useData:!0})}(); \ No newline at end of file diff --git a/public/build/link.js b/public/build/link.js new file mode 100644 index 00000000..732bc4cd --- /dev/null +++ b/public/build/link.js @@ -0,0 +1 @@ +!function(){var n=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["link.hbs"]=n({1:function(n,l,t,e,a){var o,r=null!=l?l:n.nullContext||{},u=n.hooks.helperMissing,i="function",c=n.escapeExpression,n=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return'\t\n\t\t\n\t\n"},3:function(n,l,t,e,a){var o,r=null!=l?l:n.nullContext||{},u=n.hooks.helperMissing,i="function",c=n.escapeExpression,n=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return'\t\n\t\t'+c(typeof(o=null!=(o=n(t,"text")||(null!=l?n(l,"text"):l))?o:u)==i?o.call(r,{name:"text",hash:{},data:a,loc:{start:{line:9,column:2},end:{line:9,column:10}}}):o)+"\n\t\n"},compiler:[8,">= 4.3.0"],main:function(n,l,t,e,a){var o=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return null!=(t=o(t,"if").call(null!=l?l:n.nullContext||{},null!=l?o(l,"isBtn"):l,{name:"if",hash:{},fn:n.program(1,a,0),inverse:n.program(3,a,0),data:a,loc:{start:{line:1,column:0},end:{line:11,column:7}}}))?t:""},useData:!0})}(); \ No newline at end of file diff --git a/public/build/login.js b/public/build/login.js new file mode 100644 index 00000000..a0c80769 --- /dev/null +++ b/public/build/login.js @@ -0,0 +1 @@ +!function(){var n=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["login.hbs"]=n({compiler:[8,">= 4.3.0"],main:function(n,l,e,t,a){var o=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return'
\n\t
\n\t\t\n\t
\n
\n'},useData:!0})}(); \ No newline at end of file diff --git a/public/build/main.js b/public/build/main.js new file mode 100644 index 00000000..e9589cad --- /dev/null +++ b/public/build/main.js @@ -0,0 +1 @@ +!function(){var a=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["main.hbs"]=a({compiler:[8,">= 4.3.0"],main:function(a,n,e,t,i){return'
\n\n
'},useData:!0})}(); \ No newline at end of file diff --git a/public/build/not-found.js b/public/build/not-found.js new file mode 100644 index 00000000..c00870d6 --- /dev/null +++ b/public/build/not-found.js @@ -0,0 +1 @@ +!function(){var n=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["not-found.hbs"]=n({compiler:[8,">= 4.3.0"],main:function(n,e,l,t,a){var o=n.lookupProperty||function(n,e){if(Object.prototype.hasOwnProperty.call(n,e))return n[e]};return'
\r\n\t

Страница 404

\r\n
'},useData:!0})}(); \ No newline at end of file diff --git a/public/build/note-editor.js b/public/build/note-editor.js new file mode 100644 index 00000000..310f9109 --- /dev/null +++ b/public/build/note-editor.js @@ -0,0 +1 @@ +!function(){var e=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["note-editor.hbs"]=e({compiler:[8,">= 4.3.0"],main:function(e,t,a,n,i){return'
\n\n
'},useData:!0})}(); \ No newline at end of file diff --git a/public/build/note.js b/public/build/note.js new file mode 100644 index 00000000..d7d6330d --- /dev/null +++ b/public/build/note.js @@ -0,0 +1 @@ +!function(){var n=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["note.hbs"]=n({compiler:[8,">= 4.3.0"],main:function(n,a,e,t,s){return'
\n\t

Заголовок

\n\t

Первая строчка заметки

\n
'},useData:!0})}(); \ No newline at end of file diff --git a/public/build/notes.js b/public/build/notes.js new file mode 100644 index 00000000..ab20e30b --- /dev/null +++ b/public/build/notes.js @@ -0,0 +1 @@ +!function(){var e=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["notes.hbs"]=e({compiler:[8,">= 4.3.0"],main:function(e,n,a,t,s){return'
\n\n
'},useData:!0})}(); \ No newline at end of file diff --git a/public/build/profile.js b/public/build/profile.js new file mode 100644 index 00000000..59ad08ec --- /dev/null +++ b/public/build/profile.js @@ -0,0 +1 @@ +!function(){var e=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["profile.hbs"]=e({compiler:[8,">= 4.3.0"],main:function(e,n,l,a,t){var o=e.lookupProperty||function(e,n){if(Object.prototype.hasOwnProperty.call(e,n))return e[n]};return'
\n\t

Страница профиля

\n
'},useData:!0})}(); \ No newline at end of file diff --git a/public/build/register.js b/public/build/register.js new file mode 100644 index 00000000..7beefc4b --- /dev/null +++ b/public/build/register.js @@ -0,0 +1 @@ +!function(){var e=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["register.hbs"]=e({compiler:[8,">= 4.3.0"],main:function(e,t,n,r,l){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return'
\n\t
\n\t\t

Форма регистрации

\n\t
\n
\n'},useData:!0})}(); \ No newline at end of file diff --git a/public/build/wrapper.js b/public/build/wrapper.js new file mode 100644 index 00000000..f8b2b18c --- /dev/null +++ b/public/build/wrapper.js @@ -0,0 +1 @@ +!function(){var e=Handlebars.template;(Handlebars.templates=Handlebars.templates||{})["wrapper.hbs"]=e({compiler:[8,">= 4.3.0"],main:function(e,n,l,a,t){var r=e.lookupProperty||function(e,n){if(Object.prototype.hasOwnProperty.call(e,n))return e[n]};return'
\n\n
'},useData:!0})}(); \ No newline at end of file diff --git a/public/config.js b/public/config.js index 5bea6757..bb91152b 100644 --- a/public/config.js +++ b/public/config.js @@ -5,9 +5,7 @@ const mainPage = { home: { id: "home", linkToLogin: { - href: "/login", - text: "Попробовать", - type: "submit" + text: "Попробовать" } } } diff --git a/public/index.css b/public/index.css index efcc90e8..d161b6e8 100644 --- a/public/index.css +++ b/public/index.css @@ -14,7 +14,6 @@ @import "src/components/button/button.css"; @import "src/components/wrapper/wrapper.css"; @import "src/components/footer/footer.css"; -@import "src/components/link-button/link-button.css"; *, *::before, *::after { box-sizing: border-box; diff --git a/public/src/components/button/button.css b/public/src/components/button/button.css index 57f17d5d..d4d30c8c 100644 --- a/public/src/components/button/button.css +++ b/public/src/components/button/button.css @@ -1,16 +1,14 @@ .submit-btn{ - width: 100%; - min-width: 80px; display: flex; align-items: center; justify-content: center; background-color: #56A6F0; border-radius: 20px; + padding: 8px 16px; border: none; outline: none; color: #ffffff; text-align: center; - padding: 8px; box-shadow: 0 4px 4px rgba(0, 0, 0, 0.25); cursor: pointer; transition: 0.3s; @@ -22,4 +20,8 @@ .submit-btn:active{ transform: scale(0.98) +} + +.submit-btn.hidden { + display: none; } \ No newline at end of file diff --git a/public/src/components/button/button.js b/public/src/components/button/button.js index b59539b9..f951cd11 100644 --- a/public/src/components/button/button.js +++ b/public/src/components/button/button.js @@ -21,11 +21,12 @@ export class Button { } #addEventListeners(){ - this.self.addEventListener('click', (e) => { - console.log(e) - e.preventDefault() - this.#onSubmit() - }); + if (this.#onSubmit !== undefined) { + this.self.addEventListener('click', (e) => { + e.preventDefault() + this.#onSubmit() + }); + } } #removeEventListeners(){ @@ -33,7 +34,9 @@ export class Button { } remove(){ - this.#removeEventListeners(); + if (this.#onSubmit !== undefined) { + this.#removeEventListeners(); + } } render(){ diff --git a/public/src/components/header/header.js b/public/src/components/header/header.js index 28794e3c..9b60d0fa 100644 --- a/public/src/components/header/header.js +++ b/public/src/components/header/header.js @@ -4,7 +4,8 @@ import '../../../build/header.js'; import {AppEventMaker} from "../../modules/eventMaker.js"; import {UserStoreEvents} from "../../stores/user/events.js"; import {AppUserStore} from "../../stores/user/userStore.js"; -import {LinkButton} from "../link-button/link-button.js"; +import {router} from "../../modules/router.js"; +import {Button} from "../button/button.js"; export class Header { #parent; @@ -37,8 +38,6 @@ export class Header { AppEventMaker.subscribe(UserStoreEvents.SUCCSSESFUL_LOGIN, () => { - console.log("log hueg") - if (this.#avatarLink === undefined) { this.#avatarLink = new Link(document.querySelector(".right-container"), this.#config.avatarLink) this.#avatarLink.render() @@ -57,14 +56,16 @@ export class Header { }) AppEventMaker.subscribe(UserStoreEvents.LOGOUT, () => { - console.log(this.#avatar.self) - this.#avatarLink.self.hidden = true; this.#authPageLink.self.classList.remove("hidden"); }); } + handleButtonClick = () => { + router.redirect("/login") + } + render() { console.log("header render") @@ -84,7 +85,7 @@ export class Header { rightContainer.appendChild(this.#menu) if (this.#authPageLink === undefined) { - this.#authPageLink = new LinkButton(this.#menu, this.#config.menu.auth) + this.#authPageLink = new Button(this.#menu, this.#config.menu.auth, this.handleButtonClick) this.#authPageLink.render() } diff --git a/public/src/components/home/home.js b/public/src/components/home/home.js index ff4ac44b..971d4bd9 100644 --- a/public/src/components/home/home.js +++ b/public/src/components/home/home.js @@ -1,5 +1,6 @@ import "../../../build/home.js" -import {LinkButton} from "../link-button/link-button.js"; +import {router} from "../../modules/router.js"; +import {Button} from "../button/button.js"; export class Home { #parent; @@ -14,13 +15,17 @@ export class Home { return document.getElementById('home'); } + handleButtonClick = () => { + router.redirect("/login") + } + render() { this.#parent.insertAdjacentHTML( 'afterbegin', window.Handlebars.templates['home.hbs'](this.#config) ); - const link = new LinkButton(document.querySelector(".first"), this.#config.linkToLogin) + const link = new Button(document.querySelector(".first"), this.#config.linkToLogin, this.handleButtonClick) link.render() } diff --git a/public/src/components/link-button/link-button.css b/public/src/components/link-button/link-button.css deleted file mode 100644 index d750b7ac..00000000 --- a/public/src/components/link-button/link-button.css +++ /dev/null @@ -1,27 +0,0 @@ -.link-button{ - padding: 8px 16px; - display: flex; - align-items: center; - justify-content: center; - background-color: #56A6F0; - border-radius: 20px; - border: none; - outline: none; - color: #ffffff; - text-align: center; - box-shadow: 0 4px 4px rgba(0, 0, 0, 0.25); - cursor: pointer; - transition: 0.3s; -} - -.link-button:hover{ - transform: scale(1.05) -} - -.link-button:active{ - transform: scale(0.98) -} - -.link-button.hidden { - display: none; -} \ No newline at end of file diff --git a/public/src/components/link-button/link-button.hbs b/public/src/components/link-button/link-button.hbs deleted file mode 100644 index e72b0ff1..00000000 --- a/public/src/components/link-button/link-button.hbs +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/public/src/components/link-button/link-button.js b/public/src/components/link-button/link-button.js deleted file mode 100644 index 0eb2efa5..00000000 --- a/public/src/components/link-button/link-button.js +++ /dev/null @@ -1,43 +0,0 @@ -import {router} from "../../modules/router.js"; -import "../../../build/link-button.js" - -export class LinkButton { - #parent; - - #props = {}; - - id; - - constructor(parent, config) { - this.id = crypto.randomUUID(); - - this.#parent = parent; - - this.#props.id = this.id ; - this.#props.text = config.text; - this.#props.href = config.href; - } - - get self(){ - return document.getElementById(this.id); - } - - handleClick = (e) => { - e.preventDefault() - router.redirect(this.#props.href) - } - - #addListeners () { - this.self.addEventListener("click", this.handleClick) - } - - render() { - - this.#parent.insertAdjacentHTML( - 'beforeend', - window.Handlebars.templates['link-button.hbs'](this.#props) - ); - - this.#addListeners() - } -} diff --git a/public/src/pages/notFound/not-found.js b/public/src/pages/notFound/not-found.js index c15ab040..668898c1 100644 --- a/public/src/pages/notFound/not-found.js +++ b/public/src/pages/notFound/not-found.js @@ -1,5 +1,6 @@ import "../../../build/not-found.js" -import {LinkButton} from "../../components/link-button/link-button.js"; +import {router} from "../../modules/router.js"; +import {Button} from "../../components/button/button.js"; export default class NotFoundPage { #parent; @@ -19,9 +20,12 @@ export default class NotFoundPage { } remove() { - + this.#parent.innerHTML = ''; } + handleButtonClick = () => { + router.redirect("/") + } render() { console.log("404 page render") @@ -31,7 +35,7 @@ export default class NotFoundPage { window.Handlebars.templates['not-found.hbs'](this.#config) ); - const link = new LinkButton(this.self, this.#config.link) + const link = new Button(this.self, this.#config.link, this.handleButtonClick) link.render() } } diff --git a/public/src/pages/register/register.js b/public/src/pages/register/register.js index a24335ef..aaeb6241 100644 --- a/public/src/pages/register/register.js +++ b/public/src/pages/register/register.js @@ -5,6 +5,9 @@ import {Button} from "../../components/button/button.js"; import {ValidateLogin, ValidatePassword} from "../../shared/validation.js"; import {AppEventMaker} from "../../modules/eventMaker.js"; import {inputEvents} from "../../components/input/events.js"; +import {AppDispatcher} from "../../modules/dispathcer.js"; +import {UserActions} from "../../stores/user/userStore.js"; +import {router} from "../../modules/router.js"; export default class RegisterPage { #parent; @@ -29,6 +32,20 @@ export default class RegisterPage { return document.getElementById(this.#config.form.id) } + validateData = () => { + const validateLogin = this.#validateLogin() + const validatePassword = this.#validatePassword() + if (validateLogin && validatePassword) { + + AppDispatcher.dispatch({ + type: UserActions.LOGIN, + payload: this.#loginInput.value + }) + + router.redirect("/") + } + } + #validateLogin(){ delete this.#loginInput.self.dataset.error; @@ -52,6 +69,12 @@ export default class RegisterPage { if (!validationResult.result){ this.#passwordInput.throwError(validationResult.message); + this.#repeatPasswordInput.throwError(validationResult.message); + } + + if (this.#passwordInput.value !== this.#repeatPasswordInput.value) { + this.#passwordInput.throwError("Пароли не совпадают"); + this.#repeatPasswordInput.throwError("Пароли не совпадают"); } return validationResult.result; @@ -115,7 +138,7 @@ export default class RegisterPage { this.#link = new Link(this.form, this.#config.form.links.loginPage); this.#link.render(); - this.#submitBtn = new Button(this.form, this.#config.form.buttons.submitBtn); + this.#submitBtn = new Button(this.form, this.#config.form.buttons.submitBtn, this.validateData); this.#submitBtn.render(); this.#subscribeToEvents(); diff --git a/public/src/shared/validation.js b/public/src/shared/validation.js new file mode 100644 index 00000000..91ebe2b7 --- /dev/null +++ b/public/src/shared/validation.js @@ -0,0 +1,54 @@ +export const ValidatePassword = (value) => { + for (let index = 0; index < value.length; ++index){ + if (!(value.charCodeAt(index) >= 97 && value.charCodeAt(index) <= 122 || + value.charCodeAt(index) >= 64 && value.charCodeAt(index) <= 90 || + value.charCodeAt(index) >= 48 && value.charCodeAt(index) <= 57 || + value.charCodeAt(index) >= 35 && value.charCodeAt(index) <= 38)){ + return ValidationResult(false, "Пароль должен содержать только латинские символы, цифры или символы #$%&"); + } + } + + if (value === "") + { + return ValidationResult(false, "Пароль не может быть пустым!") + } + + if (value.length < 8){ + return ValidationResult(false, "Пароль должен быть не менее 8 символов!") + } + + if (value.length > 20){ + return ValidationResult(false, "Пароль должен быть короче 20 символов!") + } + + return ValidationResult(true) +} + +export const ValidateLogin = (value) => { + for (let index = 0; index < value.length; ++index){ + if (!(value.charCodeAt(index) >= 97 && value.charCodeAt(index) <= 122 || + value.charCodeAt(index) >= 64 && value.charCodeAt(index) <= 90 || + value.charCodeAt(index) >= 48 && value.charCodeAt(index) <= 57 )){ + return ValidationResult(false, "Логин должен содержать только латинские символы или цифры") + } + } + + if (value === "") + { + return ValidationResult(false, "Логин не может быть пустым!") + } + + if (value.length < 4){ + return ValidationResult(false, "Логин должен быть не менее 4 символов!") + } + + if (value.length > 12){ + return ValidationResult(false, "Логин должен быть короче 12 символов!") + } + + return ValidationResult(true) +} + +const ValidationResult = (result, message = null) => { + return {result, message} +} \ No newline at end of file