func (s *AuthServiceServer) Login(ctx context.Context, req *v1.LoginRequest) (*v1.LoginResponse, error) {
	ui, err := s.rep.UserInfo(ctx, req.Username)
	if err != nil {
		if err == sql.ErrNoRows {
			return nil, errors.ErrInvalidCredentials
		}
		return nil, err
	}
	if ui.FailedLogins >= 3 {
		return nil, errors.ErrLoginBlockedAccount
	}
	if err := bcrypt.CompareHashAndPassword([]byte(ui.Password), []byte(req.Password)); err != nil {
		if err := s.rep.IncreaseFailedLoginCount(ctx, req.Username); err != nil {
			return nil, fmt.Errorf("service/v1 login failed to increase unsuccessful login count: %v", err)
		}
		if ui.FailedLogins == 2 {
			return nil, errors.ErrAccountBlocked
		}
		return nil, errors.ErrInvalidCredentials
	}
	if err := s.rep.ResetLoginCount(ctx, req.Username); err != nil {
		return nil, fmt.Errorf("service/v1 login failed to reset unsuccessful login count: %v", err)
	}
	return &v1.LoginResponse{
		UserID: ui.UserID,
	}, nil
}
Login implements AuthService Login function
package v1
import (
	"context"
	"database/sql"
	"fmt"
	v1 "optisam-backend/auth-service/pkg/api/v1"
	"optisam-backend/auth-service/pkg/oauth2/errors"
	repoV1 "optisam-backend/auth-service/pkg/repository/v1"
	"optisam-backend/common/optisam/logger"
	"optisam-backend/common/optisam/token/claims"
	"go.uber.org/zap"
	"golang.org/x/crypto/bcrypt"
)
type AuthServiceServer struct {
	rep repoV1.Repository
}
func NewAuthServiceServer(rep repoV1.Repository) *AuthServiceServer {
	return &AuthServiceServer{rep: rep}
}