Register the date of the last login
This commit is contained in:
parent
5315870dbd
commit
6cd5b1bc5e
1 changed files with 20 additions and 6 deletions
|
@ -1,6 +1,8 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
log "github.com/cihub/seelog"
|
||||
|
||||
"bytes"
|
||||
|
@ -11,11 +13,12 @@ import (
|
|||
)
|
||||
|
||||
type user struct {
|
||||
ID int `sql:"type:serial"`
|
||||
Username string `sql:"type:varchar(255),unique"`
|
||||
Password []byte
|
||||
Salt []byte
|
||||
Role string `sql:"type:varchar(255)"`
|
||||
ID int `sql:"type:serial"`
|
||||
Username string `sql:"type:varchar(255),unique"`
|
||||
Password []byte
|
||||
Salt []byte
|
||||
Role string `sql:"type:varchar(255)"`
|
||||
LastLogin time.Time
|
||||
}
|
||||
|
||||
func (db *pgDB) AddUser(name string, pass string) error {
|
||||
|
@ -66,7 +69,18 @@ func (db *pgDB) ValidPassword(name string, pass string) bool {
|
|||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return bytes.Compare(u.Password, hash) == 0
|
||||
if bytes.Compare(u.Password, hash) != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
_, err = db.sql.Model(&user{}).
|
||||
Set("last_login = CURRENT_TIMESTAMP").
|
||||
Where("id = ?", u.ID).
|
||||
Update()
|
||||
if err != nil {
|
||||
log.Error("Error updating last login for ", u.Username, ": ", err)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (db *pgDB) SetPassword(name string, pass string) error {
|
||||
|
|
Reference in a new issue