MCPcopy Create free account
hub / github.com/bailicangdu/node-elm / register

Method register

controller/admin/admin.js:90–154  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

88 })
89 }
90 async register(req, res, next){
91 const form = new formidable.IncomingForm();
92 form.parse(req, async (err, fields, files) => {
93 if (err) {
94 res.send({
95 status: 0,
96 type: 'FORM_DATA_ERROR',
97 message: '表单信息错误'
98 })
99 return
100 }
101 const {user_name, password, status = 1} = fields;
102 try{
103 if (!user_name) {
104 throw new Error('用户名错误')
105 }else if(!password){
106 throw new Error('密码错误')
107 }
108 }catch(err){
109 console.log(err.message, err);
110 res.send({
111 status: 0,
112 type: 'GET_ERROR_PARAM',
113 message: err.message,
114 })
115 return
116 }
117 try{
118 const admin = await AdminModel.findOne({user_name})
119 if (admin) {
120 console.log('该用户已经存在');
121 res.send({
122 status: 0,
123 type: 'USER_HAS_EXIST',
124 message: '该用户已经存在',
125 })
126 }else{
127 const adminTip = status == 1 ? '管理员' : '超级管理员'
128 const admin_id = await this.getId('admin_id');
129 const newpassword = this.encryption(password);
130 const newAdmin = {
131 user_name,
132 password: newpassword,
133 id: admin_id,
134 create_time: dtime().format('YYYY-MM-DD'),
135 admin: adminTip,
136 status,
137 }
138 await AdminModel.create(newAdmin)
139 req.session.admin_id = admin_id;
140 res.send({
141 status: 1,
142 message: '注册管理员成功',
143 })
144 }
145 }catch(err){
146 console.log('注册管理员失败', err);
147 res.send({

Callers 2

EFunction · 0.80
vendor.jsFile · 0.80

Calls 2

encryptionMethod · 0.95
getIdMethod · 0.80

Tested by

no test coverage detected