mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 13:38:43 +00:00
Merge pull request #19 from Nez27/feat/refactor-constant-controller
Refactor constant, controller and fix typo
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import Controller from './controllers/controller';
|
import Controller from './controllers/index';
|
||||||
import Service from './services/service';
|
import Service from './services/index';
|
||||||
import View from './views/view';
|
import View from './views/index';
|
||||||
import 'regenerator-runtime/runtime';
|
import 'regenerator-runtime/runtime';
|
||||||
import 'core-js/stable';
|
import 'core-js/stable';
|
||||||
|
|
||||||
@@ -12,5 +12,6 @@ export default class App {
|
|||||||
start() {
|
start() {
|
||||||
this.controller.registerController.init();
|
this.controller.registerController.init();
|
||||||
this.controller.loginController.init();
|
this.controller.loginController.init();
|
||||||
|
this.controller.homeController.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,26 @@
|
|||||||
export const DATABASE_URL =
|
export const DATABASE_URL =
|
||||||
'https://javascript-training-81f7a-default-rtdb.asia-southeast1.firebasedatabase.app';
|
'https://javascript-training-81f7a-default-rtdb.asia-southeast1.firebasedatabase.app';
|
||||||
export const TIME_OUT_SEC = 3;
|
export const TIME_OUT_SEC = 3;
|
||||||
export const REGEX_PASSWORD =
|
|
||||||
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
|
export const URL = {
|
||||||
|
LOGIN: 'login',
|
||||||
|
REGISTER: 'register',
|
||||||
|
HOME: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const BTN_CONTENT = {
|
||||||
|
GOT_IT: 'Got it!',
|
||||||
|
OK: 'Ok',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LOCAL_STORAGE = {
|
||||||
|
ACCESS_TOKEN: 'accessToken',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const TYPE_TOAST = { success: 'success', error: 'error' };
|
||||||
|
export const MARK_ICON = { success: 'check', error: 'error' };
|
||||||
|
|
||||||
|
export const REGEX = {
|
||||||
|
PASSWORD:
|
||||||
|
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/,
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
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!',
|
|
||||||
TIME_OUT_ERROR: 'Connection time out! Please try again!',
|
|
||||||
ERROR_CREDENTIAL: {
|
|
||||||
title: 'Error Credential',
|
|
||||||
message: 'Email or password not match! Please try again!',
|
|
||||||
},
|
|
||||||
DEFAULT_TITLE_ERROR_POPUP: 'Error',
|
|
||||||
USER_EXIST_ERROR: 'User is exists! Please try another email!',
|
|
||||||
};
|
|
||||||
|
|
||||||
export const BTN_CONTENT = {
|
|
||||||
GOT_IT: 'Got it!',
|
|
||||||
OK: 'Ok',
|
|
||||||
};
|
|
||||||
|
|
||||||
export const LOCAL_STORAGE = {
|
|
||||||
ACCESS_TOKEN: 'accessToken',
|
|
||||||
};
|
|
||||||
|
|
||||||
export const TYPE_POPUP = { success: 'success', error: 'error' };
|
|
||||||
export const MARK_ICON = { success: 'check', error: 'error' };
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
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_ERROR = 'Connection time out! Please try again!';
|
||||||
|
|
||||||
|
export const ERROR_CREDENTIAL = {
|
||||||
|
title: 'Error Credential',
|
||||||
|
message: 'Email or password not match! Please try again!',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DEFAULT_TITLE_ERROR_TOAST = 'Error';
|
||||||
|
|
||||||
|
export const USER_EXIST_ERROR = 'User is exists! Please try another email!';
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
export default class HomeController {
|
||||||
|
constructor(service, view) {
|
||||||
|
this.service = service;
|
||||||
|
this.homeView = view.homeView;
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
if (this.homeView) {
|
||||||
|
this.homeView.handlerTabsTransfer();
|
||||||
|
this.homeView.addCommonEventPage();
|
||||||
|
this.homeView.addEventSelectCategoryDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -1,3 +1,4 @@
|
|||||||
|
import HomeController from './homeController';
|
||||||
import LoginController from './loginController';
|
import LoginController from './loginController';
|
||||||
import RegisterController from './registerController';
|
import RegisterController from './registerController';
|
||||||
|
|
||||||
@@ -5,5 +6,6 @@ export default class Controller {
|
|||||||
constructor(service, view) {
|
constructor(service, view) {
|
||||||
this.registerController = new RegisterController(service, view);
|
this.registerController = new RegisterController(service, view);
|
||||||
this.loginController = new LoginController(service, view);
|
this.loginController = new LoginController(service, view);
|
||||||
|
this.homeController = new HomeController(service, view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,13 +4,13 @@ export default class LoginController {
|
|||||||
this.loginView = view.loginView;
|
this.loginView = view.loginView;
|
||||||
}
|
}
|
||||||
|
|
||||||
handlerValidateUser(email, password) {
|
handlerLoginUser(email, password) {
|
||||||
return this.service.userService.validateUser(email, password);
|
return this.service.userService.loginUser(email, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
if (this.loginView.isLoginPage()) {
|
if (this.loginView) {
|
||||||
this.loginView.addHandlerForm(this.handlerValidateUser.bind(this));
|
this.loginView.addHandlerForm(this.handlerLoginUser.bind(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export default class RegisterController {
|
|||||||
this.service = service;
|
this.service = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
hanlderCheckUserExist(email) {
|
handlerCheckUserExist(email) {
|
||||||
return this.service.userService.checkUserExist(email);
|
return this.service.userService.checkUserExist(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,9 +13,9 @@ export default class RegisterController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
if (this.registerView.isRegisterPage()) {
|
if (this.registerView) {
|
||||||
this.registerView.addHandlerForm(
|
this.registerView.addHandlerForm(
|
||||||
this.hanlderCheckUserExist.bind(this),
|
this.handlerCheckUserExist.bind(this),
|
||||||
this.handlerSaveUser.bind(this),
|
this.handlerSaveUser.bind(this),
|
||||||
);
|
);
|
||||||
this.registerView.addHandlerInputFormChange();
|
this.registerView.addHandlerInputFormChange();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { MESSAGE } from '../constants/constant';
|
import * as MESSAGE from '../constants/message';
|
||||||
import { REGEX_PASSWORD, TIME_OUT_SEC } from '../constants/config';
|
import { TIME_OUT_SEC } from '../constants/config';
|
||||||
import FirebaseService from '../services/firebaseService';
|
import FirebaseService from '../services/firebaseService';
|
||||||
|
import { REGEX_PASSWORD } from '../constants/variable';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate password
|
* Validate password
|
||||||
@@ -62,3 +63,16 @@ export const convertDataObjectToModel = (data) => {
|
|||||||
|
|
||||||
return { id, ...object.data };
|
return { id, ...object.data };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getSubdirectoryURL = () => {
|
||||||
|
const url = window.location.href;
|
||||||
|
const parts = url.split('/'); // Results: ['http:', '', 'example.com', '']
|
||||||
|
const subDirectory = parts[3]; // Get subdirectory url only
|
||||||
|
const index = subDirectory.indexOf('?'); // Remove query behind subDirectory
|
||||||
|
|
||||||
|
if (index !== -1) {
|
||||||
|
return subDirectory.substring(0, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return subDirectory;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user