-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser.js
61 lines (54 loc) · 1.82 KB
/
user.js
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
//用户注册登录
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('test.db');
var Promise = require('bluebird');
exports.register=(name,password)=>{
return new Promise(
(resolve,reject)=>{
db.run('INSERT INTO user(name, password) VALUES (?,?)',[name,password],function(err){
if(err)
{
console.log("err");
reject(err);
}
else
{
console.log("insert");
resolve(this.lastID);
}
});
});
};
exports.check=(name,password)=>{
return new Promise(
(resolve,reject)=>{
db.all('select * from user where name=? and password=?',[name,password],function(err,res){
if(!err)
{
if(res.length==0)
{
console.log(res.length);
resolve(false);
}
else
{
console.log("true");
resolve(true);
}
}
else
reject(err);
});
});
};
exports.login=(name,password)=>{
return new Promise(
(resolve,reject)=>{
db.get('select * from user where name=? and password=?',[name,password],function(err,res){
if(err)
reject(err);
else
resolve(res.id);
});
});
};