-
Notifications
You must be signed in to change notification settings - Fork 5
/
user.go
44 lines (40 loc) · 1.06 KB
/
user.go
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
package service
import (
"github.com/littlebutt/nasu/src/context"
"github.com/littlebutt/nasu/src/db"
"strconv"
"time"
)
const DEFAULT_PASSWORD = "21232f297a57a5a743894a0e4a801fc3"
func Login(password string) (success bool, isFirst bool, token string) {
var passwordFromDb string
if nasuMeta := db.NasuMetaRepo.QueryNasuMetaByType("PASSWORD"); nasuMeta != nil {
passwordFromDb = nasuMeta.MetaValue
}
if passwordFromDb == password {
success = true
token = password + "+" + strconv.Itoa(int(time.Now().Unix()))
isFirst = password == DEFAULT_PASSWORD
return
} else {
success = false
return
}
}
func ChangePassword(oldPassword string, newPassword string) (success bool) {
var passwordFromDb string
if nasuMeta := db.NasuMetaRepo.QueryNasuMetaByType("PASSWORD"); nasuMeta != nil {
passwordFromDb = nasuMeta.MetaValue
}
if passwordFromDb == oldPassword {
res := db.NasuMetaRepo.UpdateNasuMetaByType("PASSWORD", newPassword)
if res {
context.NasuContext.Password = newPassword
return true
} else {
return false
}
} else {
return false
}
}