Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/routes/Schemas/user_pending.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const User_pending_Schema = new Schema({
account: { type: String, required: true, lowercase: true, unique: true }, //學號
userpsw: String, //密碼
email: { type: mongoose.SchemaTypes.Email, required: true },
advisingProfessor: [{ label: String, value: String }],
active: String,
img: {
data: Buffer,
Expand Down
1 change: 0 additions & 1 deletion backend/routes/Schemas/user_visual_new.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ Profile_Schema.virtual('imgSrc').get(buf2url('userimage'))
Profile_Schema.statics.smartQuery = function (keywords) {
if (!keywords) return []
const reg = new RegExp(keywords.replace(' ', '|'), 'i')
// console.log(reg)
const query = {
$or: [
{ account: reg },
Expand Down
5 changes: 4 additions & 1 deletion backend/routes/srcs/in/account/auth/handlePending.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const sendmail = require('../../../../middleware/mail')
*/
const manage = async (req, res, next) => {
const { account, acceptUser } = req.body
const { username, userpsw, facebookID, email } = await Pending.findOne({ account }).catch(dbCatch)
const { username, userpsw, facebookID, email, advisingProfessor } = await Pending.findOne({
account,
}).catch(dbCatch)
if (!username) throw new ErrorHandler(404, 'user not found')
if (!acceptUser) {
await Pending.deleteMany({ account }).catch(dbCatch)
Expand All @@ -30,6 +32,7 @@ const manage = async (req, res, next) => {
username,
account,
publicEmail: email,
advisingProfessor,
})
.save()
.catch(dbCatch)
Expand Down
7 changes: 5 additions & 2 deletions backend/routes/srcs/in/account/auth/showPending.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ const asyncHandler = require('express-async-handler')
* @apiError (500) {String} description 資料庫錯誤
*/
const manage = async (req, res, next) => {
const pendings = await Pending.find({}, 'username account email img').catch(dbCatch)
const pend = pendings.map(({ username, account, email, imgSrc }) => ({
const pendings = await Pending.find({}, 'username account email img advisingProfessor').catch(
dbCatch,
)
const pend = pendings.map(({ username, account, email, imgSrc, advisingProfessor }) => ({
username,
account,
email,
imgSrc,
advisingProfessor,
}))
return res.send({ pendings: pend })
}
Expand Down
19 changes: 12 additions & 7 deletions backend/routes/srcs/out/account/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ async function insert(username, account, psw, img, visual) {
.catch(dbCatch)
}

async function insertVisual(name, account, email) {
async function insertVisual(name, account, email, advisingProfessor) {
return await new Visual({
advisingProfessor: advisingProfessor,
username: name,
account: account,
publicEmail: email,
Expand All @@ -46,6 +47,7 @@ async function insertVisual(name, account, email) {
* @apiparam {String} password 密碼(以後建議在前端加密)
* @apiparam {String} ConfirmPassword 二次密碼
* @apiparam {String} username 使用者名字
* @apiparam {String} advisingProfessor 指導教授
* @apiparam {String} Email 信箱
* @apiparam {String} isGraduated false則寄送email給account@ntu.edu.tw(newRule=version3才需要)
*
Expand All @@ -61,14 +63,13 @@ async function insertVisual(name, account, email) {
const register = async (req, res) => {
const { username, password, Email } = req.body
const account = req.body.account.toLowerCase()

const Professors = JSON.parse(req.body.advisingProfessor)
//密碼加密
const newPsw = await encryptPsw(password)

const query = { account }
const isRegistered = await Login.exists(query).catch(dbCatch)
if (isRegistered) throw new ErrorHandler(403, '帳號已存在')
const user = await insertVisual(username, account, Email)
const user = await insertVisual(username, account, Email, Professors)
await insert(username, account, newPsw, parseFile(req.file), user)
req.session.loginName = username
req.session.loginAccount = account
Expand All @@ -83,7 +84,6 @@ const secure_reg = async (req, res) => {
const query = { account }
const isRegistered = await Login.exists(query).catch(dbCatch)
if (isRegistered) throw new ErrorHandler(403, '帳號已存在')

const data = {
username,
account,
Expand All @@ -101,18 +101,23 @@ const secure_reg = async (req, res) => {

const sendmail = require('../../../middleware/mail')
const template = require('./mailTemplate/template_generator')

const reg_v3 = async (req, res) => {
// The current version
const account = req.body.account.toLowerCase()
const Professors = JSON.parse(req.body.advisingProfessor)
const isRegistered = await Login.exists({ account }).catch(dbCatch)

if (isRegistered) throw new ErrorHandler(403, '帳號已存在')

const { username, password, Email } = req.body
const newPsw = await encryptPsw(password)

const active = Math.random().toString(36).substring(2)

const data = {
username,
account,
advisingProfessor: Professors,
userpsw: newPsw,
email: Email,
active,
Expand Down Expand Up @@ -144,7 +149,7 @@ const valid = require('../../../middleware/validation')
const rules = [
'account',
'password',
{ filename: 'required', field: 'username' },
{ filename: 'required', field: ['username', 'advisingProfessor'] },
'Email',
'ConfirmPassword',
]
Expand Down
1 change: 1 addition & 0 deletions client/src/views/auth/register/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Register = () => {
account: '',
email: '',
imgSrc: '',
advisingProfessor: [],
})
const [isPending, setIsPending] = useState(true)
const [applicants, setApplicants] = useState([])
Expand Down
Loading