refactor: update account login and ip address in LoginPassword

This commit is contained in:
Derrick Hammer 2024-02-13 19:52:18 -05:00
parent 23113d0f9c
commit 40b830d669
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 9 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"go.uber.org/fx"
"golang.org/x/crypto/bcrypt"
"gorm.io/gorm"
"time"
)
type AccountServiceParams struct {
@ -133,7 +134,7 @@ func (s AccountServiceDefault) AddPubkeyToAccount(user models.User, pubkey strin
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)
if err != nil {
@ -149,6 +150,13 @@ func (s AccountServiceDefault) LoginPassword(email string, password string) (str
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
}