public async Task <IActionResult> Post(string verifyCode, [FromBody] ChangePasswordModel changePasswordModel) { if (string.IsNullOrEmpty(verifyCode)) { throw new BadRequestException("Verification link is invalid"); } VerificationDetailModel verificationDetailModel = await _verificationService.Get(verifyCode); if (verificationDetailModel == null) { throw new BadRequestException("Verification link is invalid"); } if (verificationDetailModel.IsVerified) { throw new BadRequestException("Verification link has expired"); } long id; if (!long.TryParse(verificationDetailModel.OwnerId, out id)) { throw new BadRequestException("Verification link has expired"); } UserModel userModel = await _userService.Get(id); if (userModel == null) { throw new BadRequestException("Verification link has expired"); } //if (changePasswordModel.OldPassword != _encryptionService.Decrypt(userModel.passwordHash)) //{ // throw new BadRequestException("Old Password is incorrect"); //} userModel.passwordHash = _encryptionService.Encrypt(changePasswordModel.NewPassword); bool result = await _userService.ChangePassword(userModel); if (result) { return(Ok(new ResponseModel() { code = ResponseCode.SUCCESSFULL, description = "Password change request was successful" })); } throw new UnknownException("Change password request failed"); }
public async Task <IActionResult> Verify(long id, string vcode) { if (string.IsNullOrEmpty(vcode)) { throw new BadRequestException("Bad request. PLease try again"); } var udetails = await _userService.Get(id); if (udetails == null) { throw new BadRequestException("Verification details is invalid"); } VerificationDetailModel vdetails = await _verificationService.Get(vcode); if (vdetails == null) { throw new BadRequestException($"Verification link is invalid"); } if (vdetails.IsVerified) { throw new BadRequestException($"Verification link has been used"); } udetails.userStatus = UserStatus.ACTIVE; bool result = await _userService.UpdateStatus(udetails); if (result) { await _verificationService.InValidateCode(vcode, id.ToString()); return(Ok(new ResponseModel() { code = ResponseCode.SUCCESSFULL, description = "Verification is successful" })); } else { throw new BadRequestException("Verification process failed. Please try again or contact your administrator"); } }
public HttpResponseMessage Get(string clientKey, string instance, ValidationType type, string lang, string t) { var model = verificationService.Get(clientKey, instance, type, lang); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(model.Stream) }; result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = model.FileName }; result.Content.Headers.ContentType = new MediaTypeHeaderValue(model.ContentType); result.Content.Headers.ContentLength = model.Stream.Length; return(result); }