HOANGLAOTA 11 months ago
commit b4c1bc6a83
  1. BIN
      public/assets/images/logo_MD1.png
  2. 6
      src/App.js
  3. 10
      src/_constants/register.js
  4. 33
      src/_containers/RegisterPage/RegisterPage.js
  5. 30
      src/_containers/RegisterPage/components/AccountAuthentication/AccountAuthentication.jsx
  6. 6
      src/_containers/RegisterPage/components/AddClassName/index.js
  7. 160
      src/_containers/RegisterPage/components/CreateAccount/index.js
  8. 4
      src/_containers/RegisterPage/components/RegisterSuccess/index.js
  9. 15
      src/_containers/RegisterPage/components/UpdateInformation/index.js
  10. 4
      src/_helpers/validatePhone.js

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 KiB

@ -6,6 +6,7 @@ import {
import { RegisterPage } from "./_containers/RegisterPage"; import { RegisterPage } from "./_containers/RegisterPage";
import { alertActions } from "./_actions"; import { alertActions } from "./_actions";
import { history } from "./_helpers"; import { history } from "./_helpers";
import { AccountAuthentication } from "./_containers/RegisterPage/components/AccountAuthentication/AccountAuthentication";
import ChooseOrg from "./_containers/RegisterPage/components/ChooseOrg"; import ChooseOrg from "./_containers/RegisterPage/components/ChooseOrg";
function App() { function App() {
String.prototype.capitalize = function () { String.prototype.capitalize = function () {
@ -42,6 +43,11 @@ function App() {
exact={true} exact={true}
component={RegisterPage} component={RegisterPage}
/> />
<RouteRedirectToAdmin
path="/:orgLevel/authentication"
exact={true}
component={AccountAuthentication}
/>
<Redirect from="*" to="/" /> <Redirect from="*" to="/" />
</Switch> </Switch>
</Router> </Router>

@ -19,4 +19,14 @@ export const registerValue = {
name: 'Phòng Giáo dục thành phố\nPhúc Yên - Vĩnh Phúc', name: 'Phòng Giáo dục thành phố\nPhúc Yên - Vĩnh Phúc',
color: '#3493B8' color: '#3493B8'
}, },
minhduc: {
path: 'minhduc',
province_alias: 'ha_noi',
district_alias: 'huyen_Ung_hoa',
organization: 'Minh Đức',
represent_code: 'MD1',
logo: '/assets/images/logo_MD1.png',
name: 'Trường THCS Minh Đức - Ứng Hoà - Hà Nội',
color: '#3493B8'
},
} }

@ -30,6 +30,7 @@ function RegisterPage() {
organization: '', organization: '',
}); });
const [dataCreateAccount, setDataCreateAccount] = useState({ const [dataCreateAccount, setDataCreateAccount] = useState({
phone: "",
email: "", email: "",
password: "", password: "",
rePassword: "", rePassword: "",
@ -71,7 +72,7 @@ function RegisterPage() {
const onClickYes = () => { const onClickYes = () => {
const data = { const data = {
email: dataCreateAccount.email, email: dataCreateAccount?.email ? dataCreateAccount.email : undefined,
password: dataCreateAccount.password, password: dataCreateAccount.password,
re_password: dataCreateAccount.rePassword, re_password: dataCreateAccount.rePassword,
role: dataStepRole.role, role: dataStepRole.role,
@ -84,19 +85,19 @@ function RegisterPage() {
gender: dataUpdateInfo.gender, gender: dataUpdateInfo.gender,
province_alias: dataAddressStudying.province, province_alias: dataAddressStudying.province,
district_alias: dataAddressStudying.district, district_alias: dataAddressStudying.district,
phone: dataUpdateInfo.phone, phone: dataCreateAccount?.phone ? dataCreateAccount.phone : undefined,
year_of_birth: dataUpdateInfo.birthday?.getFullYear(), year_of_birth: dataUpdateInfo.birthday?.getFullYear(),
school_id: dataAddressStudying?.school_id, school_id: dataAddressStudying?.school_id,
organization_code: dataAddressStudying?.organization, organization_code: dataAddressStudying?.organization,
}; };
data.birthday = moment(dataUpdateInfo.birthday).format("YYYY-MM-DD"); data.birthday = moment(dataUpdateInfo.birthday).format("YYYY-MM-DD");
setPopupMessageRegisterTeacher(false); setPopupMessageRegisterTeacher(false);
history.push(`/register/authentication`, { data: data }); history.push(`/${orgLevel}/authentication`, { data: data });
}; };
const onRegister = async () => { const onRegister = async () => {
const data = { const data = {
email: dataCreateAccount.email, email: dataCreateAccount?.email ? dataCreateAccount.email : undefined,
password: dataCreateAccount.password, password: dataCreateAccount.password,
re_password: dataCreateAccount.rePassword, re_password: dataCreateAccount.rePassword,
role: dataStepRole.role, role: dataStepRole.role,
@ -109,7 +110,7 @@ function RegisterPage() {
gender: dataUpdateInfo.gender, gender: dataUpdateInfo.gender,
province_alias: dataAddressStudying.province, province_alias: dataAddressStudying.province,
district_alias: dataAddressStudying.district, district_alias: dataAddressStudying.district,
phone: dataUpdateInfo.phone, phone: dataCreateAccount?.phone ? dataCreateAccount.phone : undefined,
year_of_birth: dataUpdateInfo.birthday?.getFullYear(), year_of_birth: dataUpdateInfo.birthday?.getFullYear(),
school_id: dataAddressStudying?.school_id, school_id: dataAddressStudying?.school_id,
organization_code: dataAddressStudying?.organization, organization_code: dataAddressStudying?.organization,
@ -120,11 +121,18 @@ function RegisterPage() {
let urlApi = `${API.baseURL}${API.register_teacher}`; let urlApi = `${API.baseURL}${API.register_teacher}`;
const result = await APIBase.apiBaseCaller("POST", urlApi, data); const result = await APIBase.apiBaseCaller("POST", urlApi, data);
if (result.status) { if (result.status) {
if(!!dataCreateAccount.phone) {
setMessageTeacher( setMessageTeacher(
"Đăng ký tài khoản thành công. Vui lòng xác thực để có thể đăng nhập và sử dụng tài khoản." "Đăng ký tài khoản thành công. Vui lòng xác thực để có thể đăng nhập và sử dụng tài khoản."
); );
setPopupMessageRegisterTeacher(true); setPopupMessageRegisterTeacher(true);
setStatusSuccessRegisterTeacher(true); setStatusSuccessRegisterTeacher(true);
} else {
setStatusRegister({
type: "success",
message: result.msg,
});
}
} else { } else {
if (!isEmpty(result?.message?.errors?.phone[0])) { if (!isEmpty(result?.message?.errors?.phone[0])) {
setMessageTeacher(result?.message?.errors?.phone[0]); setMessageTeacher(result?.message?.errors?.phone[0]);
@ -143,18 +151,30 @@ function RegisterPage() {
const newData = { const newData = {
...data, ...data,
class_nickname: dataClassName?.class_nickname, class_nickname: dataClassName?.class_nickname,
auto_active: 1
} }
apiCaller("/api_register/register", "POST", newData).then((res) => { apiCaller("/api_register/register", "POST", newData).then((res) => {
if (res.status) { if (res.status) {
if(!!dataCreateAccount.phone) {
setMessageTeacher(
"Đăng ký tài khoản thành công. Vui lòng xác thực để có thể đăng nhập và sử dụng tài khoản."
);
setPopupMessageRegisterTeacher(true);
setStatusSuccessRegisterTeacher(true);
} else {
setStatusRegister({ setStatusRegister({
type: "success", type: "success",
message: res.msg, message: res.msg,
}); });
} }
} else {
setMessageTeacher(result?.msg);
setPopupMessageRegisterTeacher(true);
setStatusSuccessRegisterTeacher(false);
}
}).catch((error) => { }).catch((error) => {
setMessageTeacher(error); setMessageTeacher(error);
setPopupMessageRegisterTeacher(true); setPopupMessageRegisterTeacher(true);
setStatusSuccessRegisterTeacher(false);
}); });
} }
}; };
@ -184,6 +204,7 @@ function RegisterPage() {
school: '' school: ''
}); });
setDataCreateAccount({ setDataCreateAccount({
phone: '',
email: "", email: "",
password: "", password: "",
rePassword: "", rePassword: "",

@ -1,11 +1,13 @@
import React from "react"; import React, { useState } from "react";
import { accountAuthenticationMethods } from "./AccountAuthentication.logic"; import { accountAuthenticationMethods } from "./AccountAuthentication.logic";
import { HeaderCloud } from "../../../../_components/Header"; import { HeaderCloud, HeaderTS } from "../../../../_components/Header";
import ModalConfirmOTP from "../../../../_components/Modal/ModalConfirmOTP/ModalConfirmOTP"; import ModalConfirmOTP from "../../../../_components/Modal/ModalConfirmOTP/ModalConfirmOTP";
import "./AccountAuthentication.scss"; import "./AccountAuthentication.scss";
import { Link } from "react-router-dom"; import { Link, useParams } from "react-router-dom";
import { PopUpYesNo } from "../../../../_components/Popup"; import { PopUpYesNo } from "../../../../_components/Popup";
import { history } from "../../../../_helpers"; import { history } from "../../../../_helpers";
import { registerValue } from "../../../../_constants/register";
import { HeaderLogoRegister } from "../../../../_components/Header/HeaderLogoRegister/HeaderLogoRegister";
// export const SuccessAuthentication = () => { // export const SuccessAuthentication = () => {
// return ( // return (
@ -55,12 +57,32 @@ const AccountAuthentication = () => {
handleGoBack, handleGoBack,
popupRegisterSuccess, popupRegisterSuccess,
messageReSendCode, messageReSendCode,
setPopupRegisterSuccess
} = accountAuthenticationMethods(); } = accountAuthenticationMethods();
const params = useParams();
const orgLevel = params?.orgLevel;
const [registerInfo, setRegisterInfo] = useState(registerValue?.[orgLevel] || undefined);
return ( return (
<div className="bg-register rel"> <div className="bg-register rel">
{!!registerInfo &&
(orgLevel === 'namdinh' ?
<HeaderCloud /> <HeaderCloud />
{popupRegisterSuccess && <PopUpYesNo message={"Xác thực tài khoản thành công!"} hideButtonNo={true} onClickYes={() => history.replace("/login")} labelYes={"Đồng ý"}/>} : <HeaderLogoRegister
srcImg={registerInfo?.logo}
name={registerInfo?.name}
color={registerInfo?.color}
/>
)}
{popupRegisterSuccess &&
<PopUpYesNo
message={"Xác thực tài khoản thành công!"}
onClickNo={() => history.goBack()}
labelNo='Quay lại'
labelYes={"Đi tới đăng nhập"}
onClickYes={() => window.location.replace('https://sundayenglish.com/login')}
/>
}
<div className="content_1 flex-center-column"> <div className="content_1 flex-center-column">
<div className="flex-center-column container_modal_confirmOTP"> <div className="flex-center-column container_modal_confirmOTP">
<ModalConfirmOTP <ModalConfirmOTP

@ -133,7 +133,7 @@ export default function AddClassName(props) {
<div className="sunE-custom-form login-form-container_content responsive_small_screen_margin_login"> <div className="sunE-custom-form login-form-container_content responsive_small_screen_margin_login">
<h2 className="title_register title text-center">ĐĂNG TÀI KHOẢN</h2> <h2 className="title_register title text-center">ĐĂNG TÀI KHOẢN</h2>
<h3 className="step_register_name text-center"> <h3 className="step_register_name text-center">
{`4. Thông tin giáo viên`} {`4. Thông tin lớp học`}
</h3> </h3>
<div className="add-class-content"> <div className="add-class-content">
<form <form
@ -146,8 +146,8 @@ export default function AddClassName(props) {
value={className} value={className}
setValue={setClassName} setValue={setClassName}
type="text" type="text"
name="Tên giáo viên" name="Tên lớp"
placeholder="Nhập tên giáo viên" placeholder="Nhập tên lớp"
required={true} required={true}
renderLabelIcon={renderClassIcon} renderLabelIcon={renderClassIcon}
autoFocus = {true} autoFocus = {true}

@ -5,75 +5,112 @@ import "./index.scss";
import { isEmail } from "../../../../_helpers/validateEmail"; import { isEmail } from "../../../../_helpers/validateEmail";
import { apiCaller } from "../../../../_helpers"; import { apiCaller } from "../../../../_helpers";
import { stepAuthConstants } from "../../../../_constants/auth"; import { stepAuthConstants } from "../../../../_constants/auth";
import { isPhone } from "../../../../_helpers/validatePhone";
import { renderPhoneIcon } from "../AddressStudying/renderIcon";
const CreateAccount = (props) => { const CreateAccount = (props) => {
const [email, setEmail] = useState(""); const [email, setEmail] = useState("");
const [phone, setPhone] = useState("");
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const [rePassword, setRePassword] = useState(""); const [rePassword, setRePassword] = useState("");
const [emailError, setEmailError] = useState(""); const [emailError, setEmailError] = useState("");
const [phoneError, setPhoneError] = useState("");
const [pwError, setPwError] = useState(""); const [pwError, setPwError] = useState("");
const [rePwError, setRePwError] = useState(""); const [rePwError, setRePwError] = useState("");
const [cacheEmailPass, setCacheEmailPass] = useState([]); const [cacheEmailPass, setCacheEmailPass] = useState([]);
const [cacheEmailFail, setCacheEmailFail] = useState([]); const [cacheEmailFail, setCacheEmailFail] = useState([]);
const [cachePhoneFail, setCachePhoneFail] = useState([]);
const [disabledBtn, setDisabledBtn] = useState(false); const [disabledBtn, setDisabledBtn] = useState(false);
useEffect(() => { useEffect(() => {
setPhone(props.data.phone);
setEmail(props.data.email); setEmail(props.data.email);
setPassword(props.data.password); setPassword(props.data.password);
setRePassword(props.data.rePassword); setRePassword(props.data.rePassword);
}, [props.data]); }, [props.data]);
async function handleSubmit(e) { const verifyEmail = async () => {
// setSubmitted(true); try {
// if (validateParam()) { const res = await apiCaller("/api_register/check_email", "POST", { email })
// dispatch(userActions.udpateInformation(inputs)); if (res?.status) {
// }
e.preventDefault();
if (!!email && password.length >= 6 && password === rePassword) {
if (cacheEmailPass.includes(email)) {
nextStep();
return;
} else if (cacheEmailFail.includes(email)) {
setDisabledBtn(true);
setEmailError(
"Email đã tồn tại trên hệ thống. Vui lòng quay lại đăng nhập!"
);
return;
} else {
await apiCaller("/api_register/check_email", "POST", {
email,
})
.then((res) => {
if (res.status) {
setCacheEmailPass([...cacheEmailPass, email]); setCacheEmailPass([...cacheEmailPass, email]);
nextStep(); return true;
setEmailError("");
setPwError("");
setRePwError("");
} }
}) setEmailError(res?.msg);
.catch((e) => { return false;
} catch (e) {
setCacheEmailFail([...cacheEmailFail, email]); setCacheEmailFail([...cacheEmailFail, email]);
if (e === "Email đã tồn tại trên hệ thống.") { if (e === "Email đã tồn tại trên hệ thống.") {
setDisabledBtn(true);
setEmailError( setEmailError(
"Email đã tồn tại trên hệ thống. Vui lòng quay lại đăng nhập!" "Email đã tồn tại trên hệ thống. Vui lòng quay lại đăng nhập!"
); );
} else { } else {
setEmailError(e); setEmailError(e);
} }
return; return false
}); }
}
const verifyPhone = async () => {
try {
const res = await apiCaller("/api_register/check_phone", "POST", { phone })
if (res?.status) {
// setCachePhonePass([...cachePhonePass, phone]);
return true;
}
setPhoneError(res?.msg);
return false;
} catch (e) {
setCachePhoneFail([...cachePhoneFail, phone]);
if (e === "Số điện thoại đã tồn tại trên hệ thống.") {
setPhoneError(
"Số điện thoại đã tồn tại trên hệ thống. Vui lòng quay lại đăng nhập!"
);
} else {
setPhoneError(e);
}
return false
}
} }
async function handleSubmit(e) {
e.preventDefault();
let isFormValid = true;
if(validateParam() ) {
if (cacheEmailFail.includes(email)) {
setEmailError(
"Email đã tồn tại trên hệ thống. Vui lòng quay lại đăng nhập!"
);
isFormValid = false
}
if (cachePhoneFail.includes(phone)) {
setPhoneError(
"Số điện thoại đã tồn tại trên hệ thống. Vui lòng quay lại đăng nhập!"
);
isFormValid = false
}
if (!!phone.length && !cachePhoneFail.includes(phone)) {
const isPhoneValid = await verifyPhone();
if(!isPhoneValid) isFormValid = false;
}
if (!!email.length && !cacheEmailFail.includes(email)) {
const isEmailValid = await verifyEmail();
if(!isEmailValid) isFormValid = false;
}
if (isFormValid) {
nextStep();
return; return;
} }
// checkEmail(); checkPhone()
checkEmail();
checkPw(); checkPw();
checkRePw(); checkRePw();
} }
}
const nextStep = () => { const nextStep = () => {
props.setData({ props.setData({
phone,
email, email,
password, password,
rePassword, rePassword,
@ -82,15 +119,18 @@ const CreateAccount = (props) => {
}; };
const checkEmail = () => { const checkEmail = () => {
// if (!isEmail(email)) { if (!!email.length && !isEmail(email)) {
// setEmailError("Định dạng email không đúng"); setEmailError("Định dạng email không đúng");
// } }
}; };
const checkPw = () => { const checkPw = () => {
if (password.length < 6 || password.trim() === "") { if (password.length < 6 || password.trim() === "") {
setPwError("Mật khẩu cần tối thiểu 6 kí tự và không gồm toàn dấu cách"); setPwError("Mật khẩu cần tối thiểu 6 kí tự và không gồm toàn dấu cách");
} }
if (password.length > 30) {
setPwError("Mật khẩu chứa tối đa 30 kí tự");
}
}; };
const checkRePw = () => { const checkRePw = () => {
@ -99,6 +139,19 @@ const CreateAccount = (props) => {
} }
}; };
const changePhone = (value) => {
const regex = /^[0-9\b]+$/;
if(!regex.test(value) && value !== '') {
return;
}
if (phoneError) {
if (isPhone(value)) {
setPhoneError("");
}
}
setPhone(value.trim());
};
const changeEmail = (value) => { const changeEmail = (value) => {
setDisabledBtn(false); setDisabledBtn(false);
if (emailError) { if (emailError) {
@ -110,8 +163,9 @@ const CreateAccount = (props) => {
}; };
const changePassword = (value) => { const changePassword = (value) => {
if(value?.length > 30) return;
if (pwError) { if (pwError) {
if (value.length >= 6) { if (value.length >= 6 && value.length <= 30) {
setPwError(""); setPwError("");
} }
} }
@ -133,14 +187,14 @@ const CreateAccount = (props) => {
const onBlurField = (type) => { const onBlurField = (type) => {
switch (type) { switch (type) {
case "email": { case "email": {
// if (email && !emailError) { if (email && !emailError) {
// checkEmail(); checkEmail();
// } }
return; return;
} }
case "password": { case "phone": {
if (password && !pwError) { if (phone && !phoneError) {
checkPw(); checkPhone();
} }
return; return;
} }
@ -159,15 +213,14 @@ const CreateAccount = (props) => {
function validateParam() { function validateParam() {
if ( if (
!!email && (isEmail(email) || !!phone.length) &&
password.length >= 6 && password.length >= 6 &&
rePassword === password && rePassword === password &&
password.trim() !== "" && password.trim() !== "" &&
!emailError &&
!phoneError &&
!disabledBtn !disabledBtn
) { ) {
if (emailError) {
return false
}
return true; return true;
} }
return false; return false;
@ -234,6 +287,21 @@ const CreateAccount = (props) => {
}} }}
autoFocus = {true} autoFocus = {true}
></InputText> ></InputText>
<InputText
value={phone}
setValue={changePhone}
type="text"
name="phone"
placeholder="Nhập số điện thoại xác thực tài khoản"
required={true}
renderLabelIcon={renderPhoneIcon}
errorText={phoneError}
setErrorText={setPhoneError}
onBlur={() => {
onBlurField("phone");
}}
autoFocus = {true}
></InputText>
<InputText <InputText
value={password} value={password}
setValue={changePassword} setValue={changePassword}

@ -26,8 +26,8 @@ const RegisterSuccess = ({handleReset}) => {
</div> </div>
<div className="success_message"> <div className="success_message">
<p>Bạn đã đăng tài khoản thành công!</p> <p>Bạn đã đăng tài khoản thành công!</p>
{/* <p>Email kích hot đã đưc gi đến đa ch email ca bn.</p> <p>Email kích hoạt đã được gửi đến địa chỉ email của bạn.</p>
<p>Hãy kiểm tra kích hoạt tài khoản.</p> */} <p>Hãy kiểm tra kích hoạt tài khoản.</p>
</div> </div>
<div className="back_login"> <div className="back_login">
{/* <Link to="/login"> */} {/* <Link to="/login"> */}

@ -60,20 +60,11 @@ const UpdateInformation = (props) => {
if (!fullname) { if (!fullname) {
setNameWarning("Vui lòng nhập họ tên"); setNameWarning("Vui lòng nhập họ tên");
} }
if (!phone) {
setPhoneWarning("Vui lòng nhập số điện thoại");
} else if (phone.length !== 10 && phone.length !== 11) {
setPhoneWarning("Số điện thoại hợp lệ có từ 10 -11");
} else if (phone && phone.length && phone[0] !== "0") {
setPhoneWarning("Định dạng số điện thoại không đúng");
}
} }
} }
function validateParam() { function validateParam() {
if (fullname.trim() && birthday && gender && phone) { if (fullname.trim() && birthday && gender) {
if (((phone.length != 10 && phone.length != 11) || phone[0] != "0"))
return false
return true; return true;
} }
return false; return false;
@ -222,7 +213,7 @@ const UpdateInformation = (props) => {
</div> </div>
</div> </div>
</div> </div>
<InputText {/* <InputText
className="field_item" className="field_item"
value={phone} value={phone}
setValue={changePhone} setValue={changePhone}
@ -239,7 +230,7 @@ const UpdateInformation = (props) => {
setErrorText={setPhoneWarning} setErrorText={setPhoneWarning}
onBlur={onBlurPhone} onBlur={onBlurPhone}
errorAbsolute={true} errorAbsolute={true}
></InputText> ></InputText> */}
</div> </div>
{/* <div className="right"> {/* <div className="right">
<div className="text-center field_detail_group_create_account"> <div className="text-center field_detail_group_create_account">

@ -0,0 +1,4 @@
export const isPhone = (str) => {
var re = /((0)+([0-9]{9,10}))\b/g;
return re.test(str);
};
Loading…
Cancel
Save