public async Task <HttpResponseData <SuccessfulLoginRespModel, ClientsApiErrorCodes> > DoLoginUser(LoginRequestModel Input) { var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, false, lockoutOnFailure : false); if (result.Succeeded) { _logger.LogInformation("User logged in."); var existingUser = await _userManager.FindByEmailAsync(Input.Email); AuthModel userAuth = new AuthModel(); userAuth.ID = existingUser.Id.ToString(); //its wrong not hours but days 30 default TODO: Change It userAuth.ValidUntil = DateTime.Now.AddMinutes(30); var finalEncrypted = _encrypterDecrypter.EncryptObject <AuthModel>(userAuth); string hash = _requestValidatorPartsHelper.CombineAndSaveHash(existingUser.Email, Guid.Parse(existingUser.Id)); _actionContext.HttpContext.Response.Headers.Add("X-AUTH-DASH", finalEncrypted); var internalRequest = new SuccessfulLoginRespModel() { AuthToken = finalEncrypted, X_Seq = hash, Id = existingUser.Id, DateCreated = DateTime.Now, DateExpired = DateTime.Now.AddMinutes(30) }; return(new HttpResponseData <SuccessfulLoginRespModel, ClientsApiErrorCodes>(internalRequest)); } /*if (result.RequiresTwoFactor) * { * return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }); * } * if (result.IsLockedOut) * { * _logger.LogWarning("User account locked out."); * return RedirectToPage("./Lockout"); * }*/ else { return(new HttpResponseData <SuccessfulLoginRespModel, ClientsApiErrorCodes>(ClientsApiErrorCodes.NotExistingUser)); } }
public async Task <HttpResponseData <SuccessfulLoginRespModel, ClientsApiErrorCodes> > FacialRecognition(LoginFacialRequestModel Input) { //Check if the hash thats was in headers returns null if (_requestValidatorPartsHelper.RetrieveValidateDiscardHash(Input.X_seq)) { List <string> hashValues = _requestValidatorPartsHelper.RetrieveHashValues(Input.X_seq); if (hashValues == null) { return(new HttpResponseData <SuccessfulLoginRespModel, ClientsApiErrorCodes>(ClientsApiErrorCodes.Unauthorized)); } string?id = hashValues[0]; if (id != null) { //Do Facial stuff _logger.LogInformation("User logged in."); var existingUser = await _userManager.FindByIdAsync(id); if (existingUser == null) { return(new HttpResponseData <SuccessfulLoginRespModel, ClientsApiErrorCodes>(ClientsApiErrorCodes.Unauthorized)); } var base64Img = Input.Base64Img.Replace("data:image/jpeg;base64,", ""); var response = await _flaskFaceAuthServices.IdentifyUser(new FlaskFaceAuthIdentifyUserRequestModel() { Base64Img = base64Img }); if (response.Success == false) { return(new HttpResponseData <SuccessfulLoginRespModel, ClientsApiErrorCodes>(ClientsApiErrorCodes.FlaskFaceAuthInternalError)); } if (response.Success == true && response.Data.IsMatch == false) { return(new HttpResponseData <SuccessfulLoginRespModel, ClientsApiErrorCodes>(ClientsApiErrorCodes.BiometricAuthenticationFailure)); } AuthModel userAuth = new AuthModel(); userAuth.ID = existingUser.Id.ToString(); //its wrong not hours but days 30 default TODO: Change It userAuth.ValidUntil = DateTime.Now.AddMinutes(30); var finalEncrypted = _encrypterDecrypter.EncryptObject <AuthModel>(userAuth); _actionContext.HttpContext.Response.Headers.Add("X-AUTH-DASH", finalEncrypted); var internalRequest = new SuccessfulLoginRespModel() { AuthToken = finalEncrypted, Id = existingUser.Id, DateCreated = DateTime.Now, DateExpired = DateTime.Now.AddMinutes(30) }; return(new HttpResponseData <SuccessfulLoginRespModel, ClientsApiErrorCodes>(internalRequest)); } else { return(new HttpResponseData <SuccessfulLoginRespModel, ClientsApiErrorCodes>(ClientsApiErrorCodes.Unauthorized)); } } else { return(new HttpResponseData <SuccessfulLoginRespModel, ClientsApiErrorCodes>(ClientsApiErrorCodes.UnauthorizedApplication)); } }