User.js
1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
//for DB manipulate
const UserStorage = require("./UserStorage");
const {pool} = require("../config/db");
const { logger } = require("../config/winston");
const jwt = require("jsonwebtoken");
class User {
constructor(body) {
this.body = body;
}
async login() {
const client = this.body;
try {
const connection = await pool.getConnection(async (conn) => conn);
try {
const {id, password} = await UserStorage.getUserInfo(connection, client.id);
// console.log(id, password);
if (id) {
if (id === client.id && password === client.password) {
return { success: true};
}
return { success : false, msg: "비밀번호가 틀렸습니다."};
}
return {success: false, msg: "존재하지 않는 아이디입니다."};
} catch (err) {
return {success: false, msg: err};
} finally {
connection.release();
}
} catch (err) {
logger.error(`login DB Connection error\n: ${JSON.stringify(err)}`);
return false;
}
}
async register() {
const client = this.body;
try {
const connection = await pool.getConnection(async (conn) => conn);
try {
const response = await UserStorage.save(connection, client);
// console.log(response);
return response;
} catch (err) {
return {success: false, msg : err};
} finally {
connection.release();
}
} catch (err) {
logger.error(`usersaving DB Connection error\n: ${JSON.stringify(err)}`);
return false;
}
}
}
module.exports = User;