Exemplo n.º 1
0
        public async Task <ApplicationUserLoginDTO> Authenticate(ApplicationUserAuthRequest model)
        {
            var oUser = await _repository.Authenticate(model.UserNameOrEmail);

            if (oUser == null)
            {
                return(null);
            }

            if (!VerifyPasswordHash(model.Password, oUser.PasswordHash, oUser.PasswordSalt))
            {
                return(null);
            }

            return(_mapper.Map <ApplicationUserLoginDTO>(oUser));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Authenticate(ApplicationUserAuthRequest model)
        {
            Response oR = new Response();

            try
            {
                var oUser = await _service.Authenticate(model);

                if (oUser == null)
                {
                    oR.Status  = StatusCodes.Status400BadRequest;
                    oR.Message = Messages.InvalidUserNamePassword;

                    return(BadRequest(oR));
                }

                if (oUser.ApplicationUserStatusId == 2)
                {
                    oR.Status  = StatusCodes.Status400BadRequest;
                    oR.Message = Messages.AccountDisabled;

                    return(BadRequest(oR));
                }

                SetToken(oUser);

                oR.Status = StatusCodes.Status200OK;
                oR.Data   = oUser;

                return(Ok(oR));
            }
            catch (Exception ex)
            {
                oR.Status  = StatusCodes.Status500InternalServerError;
                oR.Message = Messages.InternalServerError;

                return(StatusCode(StatusCodes.Status500InternalServerError, oR));
            }
        }