refactor: update account login and ip address in LoginPassword
This commit is contained in:
parent
23113d0f9c
commit
40b830d669
|
@ -8,6 +8,7 @@ import (
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AccountServiceParams struct {
|
type AccountServiceParams struct {
|
||||||
|
@ -133,7 +134,7 @@ func (s AccountServiceDefault) AddPubkeyToAccount(user models.User, pubkey strin
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (s AccountServiceDefault) LoginPassword(email string, password string) (string, *models.User, error) {
|
func (s AccountServiceDefault) LoginPassword(email string, password string, ip string) (string, *models.User, error) {
|
||||||
valid, user, err := s.ValidLogin(email, password)
|
valid, user, err := s.ValidLogin(email, password)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -149,6 +150,13 @@ func (s AccountServiceDefault) LoginPassword(email string, password string) (str
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
err = s.updateAccountInfo(user.ID, models.User{LastLoginIP: ip, LastLogin: &now})
|
||||||
|
if err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return token, nil, nil
|
return token, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue