-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sign Up Validate #38
Open
thanhbao922003
wants to merge
1
commit into
awesome-academy:master
Choose a base branch
from
thanhbao922003:fix_sign_up
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Sign Up Validate #38
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const { body, validationResult } = require('express-validator'); | ||
exports.registerValidation = [ | ||
body('name') | ||
.notEmpty().withMessage('Tên người dùng là bắt buộc.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.isLength({ min: 3, max: 50 }).withMessage('Tên người dùng phải có từ 3 đến 50 ký tự.'), | ||
|
||
body('email') | ||
.isEmail().withMessage('Email không hợp lệ.') | ||
.notEmpty().withMessage('Email là bắt buộc.'), | ||
|
||
body('phone_number') | ||
.notEmpty().withMessage('Số điện thoại là bắt buộc.') | ||
.matches(/^\d{10,15}$/).withMessage('Số điện thoại không hợp lệ.'), | ||
|
||
body('date_of_birth') | ||
.notEmpty().withMessage('Ngày sinh là bắt buộc.') | ||
.isDate().withMessage('Ngày sinh không hợp lệ.'), | ||
|
||
body('gender') | ||
.notEmpty().withMessage('Giới tính là bắt buộc.') | ||
.isIn(['male', 'female', 'other']).withMessage('Giới tính không hợp lệ.'), | ||
|
||
body('address') | ||
.notEmpty().withMessage('Địa chỉ là bắt buộc.') | ||
.isLength({ max: 100 }).withMessage('Địa chỉ không được vượt quá 100 ký tự.'), | ||
|
||
body('role') | ||
.notEmpty().withMessage('Vai trò là bắt buộc.') | ||
.isIn(['user', 'professor']).withMessage('Vai trò không hợp lệ.'), | ||
|
||
body('department') | ||
.if(body('role').equals('professor')) | ||
.notEmpty().withMessage('Bộ phận là bắt buộc cho vai trò giáo sư.') | ||
.isLength({ max: 50 }).withMessage('Bộ phận không được vượt quá 50 ký tự.'), | ||
|
||
body('years_of_experience') | ||
.if(body('role').equals('professor')) | ||
.notEmpty().withMessage('Số năm kinh nghiệm là bắt buộc cho vai trò giáo sư.') | ||
.isInt({ min: 0 }).withMessage('Số năm kinh nghiệm phải là số nguyên không âm.'), | ||
|
||
body('password') | ||
.notEmpty().withMessage('Mật khẩu là bắt buộc.') | ||
.isLength({ min: 6 }).withMessage('Mật khẩu phải có ít nhất 6 ký tự.') | ||
.matches(/[A-Z]/).withMessage('Mật khẩu phải có ít nhất một ký tự chữ hoa.') | ||
.matches(/[0-9]/).withMessage('Mật khẩu phải có ít nhất một số.'), | ||
|
||
body('identity_card') | ||
.notEmpty().withMessage('Chứng minh thư là bắt buộc.') | ||
.isLength({ min: 9, max: 12 }).withMessage('Chứng minh thư phải có từ 9 đến 12 ký tự.'), | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ block content | |
button.ms-2.mb-1.btn-close(type='button' data-bs-dismiss='toast' aria-label='Close') | ||
.toast-body | ||
| #{t('signup.signup-success-msg')} | ||
|
||
#toastNoAutohideError.toast(role='alert' aria-live='assertive' aria-atomic='true' data-bs-delay="2000" style='opacity: 1; display: none') | ||
.toast-header.text-danger | ||
i(data-feather='alert-octagon').me-2 | ||
|
@@ -28,6 +29,19 @@ block content | |
form#registerForm.shadow.p-4.custom-width(action='/register' method='POST') | ||
.text-center.wow.fadeInUp(data-wow-delay='0.1s') | ||
h1.mb-5.bg-white.text-center.px-3 #{t('home.signup')} | ||
|
||
.row.g-3 | ||
if errors && errors.length > 0 | ||
.col-12 | ||
.alert.alert-danger | ||
p Vui lòng sửa lỗi: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I18n text |
||
if (role === 'professor') | ||
if errors.some(error => error.msg.includes('Bộ phận') || error.msg.includes('Số năm kinh nghiệm')) | ||
each error in errors | ||
p= error.msg | ||
each error in errors | ||
p= error.msg | ||
|
||
.row.g-3 | ||
.col-12 | ||
.form-floating | ||
|
@@ -63,11 +77,11 @@ block content | |
option(value='professor') #{t('admin-user.professor')} | ||
label(for='role') #{t('signup.role')} | ||
.col-12.form-floating.department-field(style='display: none;') | ||
input#department.form-control(type='text' placeholder='Department' name='department') | ||
label(for='department') #{t('signup.department')} | ||
input#department.form-control(type='text' placeholder='Department' name='department') | ||
label(for='department') #{t('signup.department')} | ||
.col-12.form-floating.years-experience-field(style='display: none;') | ||
input#years_of_experience.form-control(type='number' placeholder='Years of Experience' name='years_of_experience') | ||
label(for='years_of_experience') #{t('signup.years-of-experience')} | ||
input#years_of_experience.form-control(type='number' placeholder='Years of Experience' name='years_of_experience') | ||
label(for='years_of_experience') #{t('signup.years-of-experience')} | ||
.col-12 | ||
.form-floating | ||
input#password.form-control(type='password' placeholder='Password' name='password' required) | ||
|
@@ -89,6 +103,7 @@ block content | |
<!-- Signup End --> | ||
|
||
include partial/footer | ||
|
||
script. | ||
document.querySelector("#registerForm").addEventListener("submit", async function(event) { | ||
event.preventDefault(); | ||
|
@@ -106,7 +121,6 @@ block content | |
additional_info: formData.get("additional_info"), | ||
department: formData.get("department"), | ||
years_of_experience: formData.get("years_of_experience"), | ||
|
||
}; | ||
|
||
try { | ||
|
@@ -127,11 +141,13 @@ block content | |
} catch (error) { | ||
const toastElement = document.getElementById("toastNoAutohideError"); | ||
toastElement.style.removeProperty("display"); | ||
toastElement.querySelector('.toast-body').textContent = error.responseJSON.errors[0].msg; // Chỉ hiển thị lỗi đầu tiên | ||
setTimeout(() => { | ||
toastElement.style.display = "none"; | ||
}, 2000); | ||
} | ||
}); | ||
|
||
document.querySelector("#role").addEventListener("change", function () { | ||
const isProfessor = this.value === "professor"; | ||
document.querySelector(".department-field").style.display = isProfessor ? "block" : "none"; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ủa htrc c suggest là dùng
class-validator
mà ta ơi