Exemple #1
0
        public async Task <IActionResult> Login([FromBody] vmLoginUserRequest loggingUser)
        {
            var loginResponse = new SingleResponse <vmAuthorizedUserResponse>();

            try
            {
                var existedUserResponse = await _commonService.GetSingleUserForLoginAsync(loggingUser.Email);

                // if User does not exist or authentication fails
                if (existedUserResponse.Model == null || existedUserResponse.Model.UserID == 0 ||
                    !_passwordHasher.VerifyIdentityV3Hash(loggingUser.Password, existedUserResponse.Model.Password))
                {
                    throw new FamilyHubException(string.Format(CommonMessageDisplays.FailedAuthenticationMessage));
                }
                else
                {
                    // otherwise assign token and refreshtoken
                    loginResponse.Model = await _tokenService.AssignTokenToLoginUserAsync(existedUserResponse.Model);

                    loginResponse.Message = ResponseMessageDisplay.Success;
                }
            }
            catch (Exception ex)
            {
                loginResponse.SetError(ex);
            }


            return(loginResponse.ToHttpResponse());
        }