Check username and password strength

Changes:
- Check username availability
- Measure password strength

GitLab: #12
Change-Id: Ia384aaec01186cc874ddd6dfb4997da91a333a66
diff --git a/client/package.json b/client/package.json
index 6eb5ca7..3bfa307 100644
--- a/client/package.json
+++ b/client/package.json
@@ -40,6 +40,7 @@
     "@testing-library/user-event": "^14.4.3",
     "@types/jest": "^28.1.8",
     "axios": "^0.27.2",
+    "check-password-strength": "^2.0.7",
     "dayjs": "^1.11.5",
     "emoji-picker-react": "^3.6.1",
     "framer-motion": "^7.3.5",
diff --git a/client/src/enums/password-strength.ts b/client/src/enums/password-strength.ts
new file mode 100644
index 0000000..d5805ba
--- /dev/null
+++ b/client/src/enums/password-strength.ts
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2022 Savoir-faire Linux Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this program.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+export enum PasswordStrength {
+  TooWeak,
+  Weak,
+  Medium,
+  Strong,
+}
diff --git a/client/src/enums/status-code.ts b/client/src/enums/status-code.ts
new file mode 100644
index 0000000..d0db9b4
--- /dev/null
+++ b/client/src/enums/status-code.ts
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2022 Savoir-faire Linux Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this program.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+export enum StatusCode {
+  Ok = 200,
+  Created = 201,
+  Accepted = 202,
+  NoContent = 204,
+  BadRequest = 400,
+  Unauthorized = 401,
+  Forbidden = 403,
+  NotFound = 404,
+  NotAcceptable = 406,
+  Conflict = 409,
+  Gone = 410,
+  ImATeapot = 418,
+  TooManyRequests = 429,
+  InternalServerError = 500,
+  NotImplemented = 501,
+}
diff --git a/client/src/utils/auth.ts b/client/src/utils/auth.ts
new file mode 100644
index 0000000..470486f
--- /dev/null
+++ b/client/src/utils/auth.ts
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2022 Savoir-faire Linux Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this program.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+import { passwordStrength } from 'check-password-strength';
+import { LookupResolveValue } from 'jami-web-common';
+
+import { PasswordStrength } from '../enums/password-strength';
+import { StatusCode } from '../enums/status-code';
+
+interface PasswordStrengthResult {
+  id: number;
+  value: string;
+  contains: string[];
+  length: number;
+}
+
+export interface PasswordCheckResult {
+  strong: boolean;
+  value: string;
+}
+
+// TODO: Find a way to do it differently or remove this check from account creation.
+// It doesn't work if the server has secured this path, so I tweaked the server for test.
+// The tweak is to remove secured of apiRouter middleware in the server (app.ts).
+export async function isNameRegistered(name: string): Promise<boolean> {
+  try {
+    const response: Response = await fetch(`api/ns/name/${name}`);
+    if (response.status === StatusCode.Ok) {
+      const data: LookupResolveValue = await response.json();
+      return data.name === name;
+    }
+    return false;
+  } catch (err) {
+    return true;
+  }
+}
+
+export function checkPasswordStrength(password: string): PasswordCheckResult {
+  const strengthResult: PasswordStrengthResult = passwordStrength(password);
+
+  const checkResult: PasswordCheckResult = {
+    strong: strengthResult.id === PasswordStrength.Strong.valueOf(),
+    value: strengthResult.value,
+  };
+
+  return checkResult;
+}
diff --git a/client/src/utils/constants.ts b/client/src/utils/constants.ts
new file mode 100644
index 0000000..06d1b92
--- /dev/null
+++ b/client/src/utils/constants.ts
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2022 Savoir-faire Linux Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this program.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+export const jamiUsernamePattern = '^[a-zA-Z0-9-_]{3,32}$';
+
+export const inputWidth = 260;
+
+export const jamiLogoDefaultSize = '512px';
diff --git a/client/src/utils/utils.ts b/client/src/utils/utils.ts
index c602020..8f2f1cb 100644
--- a/client/src/utils/utils.ts
+++ b/client/src/utils/utils.ts
@@ -15,7 +15,6 @@
  * License along with this program.  If not, see
  * <https://www.gnu.org/licenses/>.
  */
-
 import { ReactNode } from 'react';
 
 export type WithChildren = {
diff --git a/client/vite.config.ts b/client/vite.config.ts
index ee35cfc..f62be3c 100644
--- a/client/vite.config.ts
+++ b/client/vite.config.ts
@@ -24,7 +24,7 @@
     host: '0.0.0.0',
     port: 3000,
     proxy: {
-      '^/(api)|(auth)|(setup)': {
+      '^/(api)|^/(auth)|^/(setup)': {
         target: 'http://localhost:3001',
         secure: false,
       },
diff --git a/package-lock.json b/package-lock.json
index bd86b70..401cfae 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -83,6 +83,7 @@
         "@testing-library/user-event": "^14.4.3",
         "@types/jest": "^28.1.8",
         "axios": "^0.27.2",
+        "check-password-strength": "^2.0.7",
         "dayjs": "^1.11.5",
         "emoji-picker-react": "^3.6.1",
         "framer-motion": "^7.3.5",
@@ -6007,6 +6008,11 @@
         "node": ">= 0.8.0"
       }
     },
+    "node_modules/check-password-strength": {
+      "version": "2.0.7",
+      "resolved": "https://registry.npmjs.org/check-password-strength/-/check-password-strength-2.0.7.tgz",
+      "integrity": "sha512-VyklBkB6dOKnCIh63zdVr7QKVMN9/npwUqNAXxWrz8HabVZH/n/d+lyNm1O/vbXFJlT/Hytb5ouYKYGkoeZirQ=="
+    },
     "node_modules/cheerio": {
       "version": "1.0.0-rc.12",
       "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.12.tgz",
@@ -21892,6 +21898,11 @@
       "integrity": "sha512-Pj779qHxV2tuapviy1bSZNEL1maXr13bPYpsvSDB68HlYcYuhlDrmGd63i0JHMCLKzc7rUSNIrpdJlhVlNwrxA==",
       "dev": true
     },
+    "check-password-strength": {
+      "version": "2.0.7",
+      "resolved": "https://registry.npmjs.org/check-password-strength/-/check-password-strength-2.0.7.tgz",
+      "integrity": "sha512-VyklBkB6dOKnCIh63zdVr7QKVMN9/npwUqNAXxWrz8HabVZH/n/d+lyNm1O/vbXFJlT/Hytb5ouYKYGkoeZirQ=="
+    },
     "cheerio": {
       "version": "1.0.0-rc.12",
       "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.12.tgz",
@@ -25435,6 +25446,7 @@
         "@types/react-modal": "^3.13.1",
         "@vitejs/plugin-react": "^2.1.0",
         "axios": "^0.27.2",
+        "check-password-strength": "^2.0.7",
         "dayjs": "^1.11.5",
         "emoji-picker-react": "^3.6.1",
         "eslint-plugin-react": "^7.31.8",