User.js
1.07 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
'use strict';
//for DB manipulate
const UserStorage = require("./UserStorage");
class User {
constructor(body) {
this.body = body;
}
async login() {
const client = this.body;
try {
const {id, password} = await UserStorage.getUserInfo(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};
}
}
async register() {
const client = this.body;
try {
const response = await UserStorage.save(client);
// console.log(response);
return response;
} catch (err) {
return {success: false, msg : err};
}
}
}
module.exports = User;