Skip to content

Commit

Permalink
test diff reg version
Browse files Browse the repository at this point in the history
  • Loading branch information
weiber2002 committed Feb 15, 2024
1 parent f6812a3 commit ae0ae33
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions backend/routes/srcs/out/account/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ const env = require('dotenv')
env.config()

/*新增一筆使用者資料*/
async function insert(username, account, psw, advisingProfessor, img, visual) {
async function insert(username, account, psw, img, visual) {
await new Login({
username: username,
account: account,
userpsw: psw,
advisingProfessor: advisingProfessor,
img,
visual: visual._id,
})
.save()
.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 Down Expand Up @@ -63,15 +63,14 @@ async function insertVisual(name, account, email) {
const register = async (req, res) => {
const { username, password, Email } = req.body
const account = req.body.account.toLowerCase()
const advisingProfessor = JSON.parse(req.body.advisingProfessor)
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)
await insert(username, account, newPsw, advisingProfessor, parseFile(req.file), user)
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
return res.status(201).send({ username })
Expand All @@ -80,18 +79,15 @@ const register = async (req, res) => {
const secure_reg = async (req, res) => {
const { username, password, Email } = req.body
const account = req.body.account.toLowerCase()
const advisingProfessor = JSON.parse(req.body.advisingProfessor)
const newPsw = await encryptPsw(password)
if (req.file === undefined) throw new ErrorHandler(400, '請添加照片')
const query = { account }
const isRegistered = await Login.exists(query).catch(dbCatch)
if (isRegistered) throw new ErrorHandler(403, '帳號已存在')

const data = {
username,
account,
userpsw: newPsw,
advisingProfessor: advisingProfessor,
email: Email,
img: {
data: req.file.buffer,
Expand All @@ -105,28 +101,30 @@ const secure_reg = async (req, res) => {

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

const reg_v3 = async (req, res) => {
const account = req.body.account.toLowerCase()
// console.log(req.body.advisingProfessor)
// console.log(req.body)
const advisingProfessor = JSON.parse(req.body.advisingProfessor)
const Professors = JSON.parse(req.body.advisingProfessor)
const isRegistered = await Login.exists({ account }).catch(dbCatch)
if (isRegistered) throw new ErrorHandler(403, '帳號已存在')

if (isRegistered) throw new ErrorHandler(403, '777')

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

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

const data = {
username,
account,
advisingProfessor: advisingProfessor,
advisingProfessor: Professors,
userpsw: newPsw,
email: Email,
active,
img: parseFile(req.file),
}
// console.log(data)
const user = await insertVisual(username, account, Email, Professors)
await insert(username, account, newPsw, parseFile(req.file), user)

await Pending.findOneAndUpdate({ account }, data, {
upsert: true,
useFindAndModify: false,
Expand All @@ -152,7 +150,7 @@ const valid = require('../../../middleware/validation')
const rules = [
'account',
'password',
{ filename: 'required', field: 'username' },
{ filename: 'required', field: ['username', 'advisingProfessor'] },
'Email',
'ConfirmPassword',
]
Expand Down

0 comments on commit ae0ae33

Please sign in to comment.