Fix name of variable constant file and format code

This commit is contained in:
2023-08-29 16:15:20 +07:00
parent 6feebb663d
commit df04a23cc7
6 changed files with 27 additions and 19 deletions
@@ -0,0 +1,5 @@
export const DATABASE_URL =
'https://javascript-training-81f7a-default-rtdb.asia-southeast1.firebasedatabase.app';
export const TIME_OUT_SEC = 3;
export const REGEX_PASSWORD =
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
@@ -1,12 +1,9 @@
export const databaseURL =
'https://javascript-training-81f7a-default-rtdb.asia-southeast1.firebasedatabase.app';
export const regex =
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
export const PASSWORD_NOT_MATCH = 'Password not match! Please try again!';
export const PASSWORD_NOT_STRONG =
'Password must at least one uppercase, one lowercase letter, one number and one special character!';
export const ERROR_MESSAGE_DEFAULT = 'Something went wrong!';
export const TIME_OUT_SEC = 3;
export const MESSAGE = {
PASSWORD_NOT_MATCH: 'Password not match! Please try again!',
PASSWORD_NOT_STRONG:
'Password must at least one uppercase, one lowercase letter, one number and one special character!',
ERROR_MESSAGE_DEFAULT: 'Something went wrong!',
};
export const TIME_OUT_ERROR = {
status: 408,
message: 'Connection time out! Please try again!',
@@ -1,8 +1,12 @@
import { TIME_OUT_SEC, TIME_OUT_ERROR, regex } from '../constants/constant';
import {
TIME_OUT_SEC,
TIME_OUT_ERROR,
REGEX_PASSWORD,
} from '../constants/constant';
import FirebaseService from '../services/firebaseService';
export const validatePassword = (password) => {
return regex.test(password);
return REGEX_PASSWORD.test(password);
};
export const timeout = (s) => {
@@ -13,10 +17,6 @@ export const timeout = (s) => {
});
};
export const createIdUser = () => {
return new Date().getTime();
};
export const timeOutConnect = async (action) => {
const result = await Promise.race([action, timeout(TIME_OUT_SEC)]);
@@ -4,4 +4,8 @@ export default class User {
this.password = password;
this.walletName = walletName;
}
static createIdUser() {
return new Date().getTime();
}
}
@@ -7,12 +7,12 @@ import {
goOnline,
onValue,
} from 'firebase/database';
import { databaseURL } from '../constants/constant';
import { DATABASE_URL } from '../constants/config';
class FirebaseService {
constructor() {
const firebaseConfig = {
databaseURL,
DATABASE_URL,
};
this.app = initializeApp(firebaseConfig);
this.db = getDatabase(this.app);
@@ -36,8 +36,11 @@ class FirebaseService {
ref(this.db, path),
(snapshot) => {
let result = false;
// snapshot is a type of data by Firebase define
snapshot.forEach((childSnapshot) => {
const data = childSnapshot.val();
if (data[property] === value) {
result = true;
}
+1 -2
View File
@@ -3,7 +3,6 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="../styles/_main.scss" />
<title>Register - Money Lover</title>
</head>
<body>
@@ -55,6 +54,6 @@
<!-- End form -->
</div>
</div>
<script type="module" src="../js/main.js"></script>
<script type="module" src="../js/controller.js"></script>
</body>
</html>