コード例 #1
0
ファイル: AuthService.cs プロジェクト: lecogrunge/Bolao
        public async Task <LoginResponse> LoginAsync(LoginRequest request)
        {
            LoginResponse response = new LoginResponse();

            // E-mail validation
            Email            email          = new Email(request.Email);
            EmailValidator   emailValidator = new EmailValidator();
            ValidationResult emailResult    = await emailValidator.ValidateAsync(email);

            if (!emailResult.IsValid)
            {
                response.AddErrorValidationResult(emailResult);
                return(response);
            }

            // Verify if user exists
            User user = await _unitOfWork.UserRepository.AuthUserAsync(email.EmailAddress, request.Password.CryptPassword());

            if (user == null)
            {
                response.SetError(new ErrorResponse(string.Empty, Msg.InvalidAuth));
                return(response);
            }

            // Verify if user is active
            bool userActive = await _unitOfWork.UserRepository.VerifyUserIsActiveByEmailAsync(request.Email);

            if (userActive == false)
            {
                response.SetError(new ErrorResponse(string.Empty, Msg.AccountInactive));
                return(response);
            }

            response.IdUser    = user.UserId;
            response.FirstName = user.Name;

            return(response);
        }