feat: login and logout

This commit is contained in:
Leon
2025-12-05 14:03:57 +08:00
parent b2cf39e731
commit 35938aaa13
5 changed files with 104 additions and 2 deletions

View File

@@ -48,3 +48,17 @@ func (ur *UserRepository) FindByUsername(username string) (*User, error) {
}
return &user, nil
}
func (ur *UserRepository) Login(id uint, token string) error {
if err := ur.db.Model(&User{}).Where("id = ?", id).Update("token", token).Error; err != nil {
return err
}
return nil
}
func (ur *UserRepository) Logout(id uint, token string) error {
if err := ur.db.Model(&User{}).Where("id = ?", id).Update("token", "").Error; err != nil {
return err
}
return nil
}