From d11fe19bab91e80d6f3b75ad080760fea73e8cf9 Mon Sep 17 00:00:00 2001 From: "@wwwjim" Date: Thu, 23 Jul 2020 01:57:44 -0700 Subject: [PATCH] reset password: loading states for edit account and sign in, adds reset password, adds validations to protect against light malice --- common/validations.js | 28 ++++++ components/system/components/Buttons.js | 34 +++++-- node_common/data/methods/update-user-by-id.js | 10 +- pages/api/sign-in.js | 4 + pages/api/users/create.js | 16 ++-- pages/api/users/delete.js | 1 - pages/api/users/update.js | 29 +++++- scenes/SceneEditAccount.js | 94 +++++++++++++++++-- scenes/SceneSignIn.js | 30 ++++-- 9 files changed, 213 insertions(+), 33 deletions(-) create mode 100644 common/validations.js diff --git a/common/validations.js b/common/validations.js new file mode 100644 index 00000000..43088e62 --- /dev/null +++ b/common/validations.js @@ -0,0 +1,28 @@ +import * as Strings from "~/common/strings"; + +const USERNAME_REGEX = new RegExp("^[a-zA-Z0-9_]{0,}[a-zA-Z]+[0-9]*$"); +const MIN_PASSWORD_LENGTH = 8; + +export const username = (text) => { + if (Strings.isEmpty(text)) { + return false; + } + + if (!USERNAME_REGEX.test(text)) { + return false; + } + + return true; +}; + +export const password = (text) => { + if (Strings.isEmpty(text)) { + return false; + } + + if (text.length < MIN_PASSWORD_LENGTH) { + return false; + } + + return true; +}; diff --git a/components/system/components/Buttons.js b/components/system/components/Buttons.js index ecd65b07..76ef69c8 100644 --- a/components/system/components/Buttons.js +++ b/components/system/components/Buttons.js @@ -58,10 +58,6 @@ const STYLES_BUTTON_PRIMARY = css` `; export const ButtonPrimary = (props) => { - if (props.type === "label") { - return