feat: ci/cd
This commit is contained in:
@@ -41,38 +41,6 @@ func (s *Service) Register(ctx context.Context, input models.UserRegisterInput)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Service) RefreshTokens(ctx context.Context, rawToken string) (*TokenPair, error) {
|
||||
row, err := s.oauth.GetRefreshTokenByHash(ctx, sha256Hex(rawToken))
|
||||
if err != nil {
|
||||
return nil, models.ErrUnauthorized
|
||||
}
|
||||
|
||||
if time.Now().After(row.ExpiresAt) {
|
||||
return nil, models.ErrUnauthorized
|
||||
}
|
||||
|
||||
client, err := s.oauth.GetOAuthClientByID(ctx, row.ClientID)
|
||||
if err != nil {
|
||||
return nil, models.ErrInternal
|
||||
}
|
||||
|
||||
scopes := scopesFromJSON(row.Scopes)
|
||||
if !ScopesAllowed(client.Scopes, scopes) {
|
||||
return nil, ErrInvalidGrant
|
||||
}
|
||||
|
||||
if err := s.oauth.DeleteRefreshTokenByID(ctx, row.ID); err != nil {
|
||||
return nil, models.ErrInternal
|
||||
}
|
||||
|
||||
user, err := s.users.GetUserByID(ctx, row.UserID)
|
||||
if err != nil {
|
||||
return nil, models.ErrUnauthorized
|
||||
}
|
||||
|
||||
return s.issuePair(ctx, user, client.ID, scopes)
|
||||
}
|
||||
|
||||
func (s *Service) ValidateAccessToken(ctx context.Context, token string) (*TokenInfo, error) {
|
||||
token = strings.TrimSpace(token)
|
||||
if token == "" {
|
||||
@@ -105,15 +73,19 @@ func (s *Service) UpdateProfile(ctx context.Context, userID uuid.UUID, input mod
|
||||
if input.FirstName != "" {
|
||||
user.FirstName = input.FirstName
|
||||
}
|
||||
|
||||
if input.SecondName != "" {
|
||||
user.SecondName = input.SecondName
|
||||
}
|
||||
|
||||
if input.BirthDate != nil {
|
||||
user.BirthDate = input.BirthDate
|
||||
}
|
||||
|
||||
if input.Sex != "" {
|
||||
user.Sex = input.Sex
|
||||
}
|
||||
|
||||
if input.Password != "" {
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(input.Password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
@@ -121,15 +93,22 @@ func (s *Service) UpdateProfile(ctx context.Context, userID uuid.UUID, input mod
|
||||
}
|
||||
user.PasswordHash = string(hash)
|
||||
}
|
||||
|
||||
user.UpdatedAt = time.Now()
|
||||
|
||||
return s.users.UpdateUser(ctx, *user)
|
||||
}
|
||||
|
||||
func (s *Service) DeleteProfile(ctx context.Context, userID uuid.UUID, accessToken string) error {
|
||||
if err := s.oauth.DeleteRefreshTokensByUserID(ctx, userID); err != nil {
|
||||
return models.ErrInternal
|
||||
}
|
||||
|
||||
if err := s.users.DeleteUser(ctx, userID); err != nil {
|
||||
return models.ErrInternal
|
||||
}
|
||||
|
||||
_ = s.redis.Del(ctx, accessTokenPrefix+accessToken)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user