|
@@ -13,11 +13,9 @@ router.use(function timeLog(req, res, next) {
|
|
|
|
|
|
// 注册
|
|
// 注册
|
|
router.post("/register", async function (req, res) {
|
|
router.post("/register", async function (req, res) {
|
|
- const { account, name = "", password = "", account_type } = req.body;
|
|
|
|
-
|
|
|
|
|
|
+ const { account, name = "", password = "" } = req.body;
|
|
const user_id = uuidv4();
|
|
const user_id = uuidv4();
|
|
-
|
|
|
|
- if (await isHaveUserByUserId({ user_id, mobile: account, email: account })) {
|
|
|
|
|
|
+ if (await isHaveUserByUserId({ user_id, account,})) {
|
|
res.send({
|
|
res.send({
|
|
code: 500,
|
|
code: 500,
|
|
msg: "当前注册信息有重复,请检查之后重新提交!",
|
|
msg: "当前注册信息有重复,请检查之后重新提交!",
|
|
@@ -25,40 +23,50 @@ router.post("/register", async function (req, res) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
// 写入数据
|
|
// 写入数据
|
|
- const insertInfo = await auth_insert({
|
|
|
|
|
|
+ await auth_insert({
|
|
name,
|
|
name,
|
|
|
|
+ account,
|
|
user_id,
|
|
user_id,
|
|
- login_type: account_type,
|
|
|
|
- email: account_type === 1 ? "" : account,
|
|
|
|
- mobile: account_type === 2 ? "" : account,
|
|
|
|
password: aes_encrypt(password),
|
|
password: aes_encrypt(password),
|
|
create_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
|
|
create_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
|
|
update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
|
|
update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
|
|
});
|
|
});
|
|
- res.send("注册成功,请重新登陆!");
|
|
|
|
|
|
+
|
|
|
|
+ const token = await getToken(account, password)
|
|
|
|
+ res.json({
|
|
|
|
+ code: 200,
|
|
|
|
+ data: {
|
|
|
|
+ token
|
|
|
|
+ }
|
|
|
|
+ });
|
|
});
|
|
});
|
|
|
|
|
|
-// 登陆
|
|
|
|
-router.post("/", async function (req, res) {
|
|
|
|
- const { account, account_type, password } = req.body;
|
|
|
|
|
|
+async function getToken(account, password) {
|
|
const islogin = await isLoginUserByUserId({
|
|
const islogin = await isLoginUserByUserId({
|
|
password: aes_encrypt(password),
|
|
password: aes_encrypt(password),
|
|
- email: account,
|
|
|
|
- mobile: account,
|
|
|
|
|
|
+ account,
|
|
});
|
|
});
|
|
|
|
+ if(!islogin) return false
|
|
|
|
+ delete islogin.password;
|
|
|
|
+ delete islogin.login_type;
|
|
|
|
+ delete islogin.id;
|
|
|
|
+ return generateToken(islogin);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 登陆
|
|
|
|
+router.post("/", async function (req, res) {
|
|
|
|
+ const { account, password } = req.body;
|
|
|
|
+
|
|
|
|
+ const token = await getToken(account, password);
|
|
|
|
|
|
- if (!islogin) {
|
|
|
|
- res.status(404).json({
|
|
|
|
|
|
+ if (!token) {
|
|
|
|
+ res.json({
|
|
code: 404,
|
|
code: 404,
|
|
msg: "登录失败,当前用户不存在",
|
|
msg: "登录失败,当前用户不存在",
|
|
data: {},
|
|
data: {},
|
|
});
|
|
});
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- delete islogin.password;
|
|
|
|
- delete islogin.login_type;
|
|
|
|
- delete islogin.id;
|
|
|
|
- const token = generateToken(islogin);
|
|
|
|
res.json({
|
|
res.json({
|
|
code: 200,
|
|
code: 200,
|
|
msg: "登录成功",
|
|
msg: "登录成功",
|