public async Task <IActionResult> ChangePwdInitialize(string username) { if (string.IsNullOrEmpty(username)) { throw new NotFoundException("Username is required"); } UserModel userModel = await _userService.Get(username); if (userModel == null) { throw new NotFoundException($"{username} does not exist"); } VerificationDetailModel vDetails = new VerificationDetailModel() { CreatedBy = User.Identity.Name, VerificationCode = _codeGenerationService.VerificationCode(), OwnerId = userModel.id.ToString() }; bool vResult = await _verificationService.Add(vDetails); if (vResult) { string template = await _templateService.GetTemplate(TemplateType.PASSWORD_RESET); if (!string.IsNullOrEmpty(template)) { template = template.Replace("$FULLNAME$", $"{userModel.lastname} {userModel.otherNames}"); template = template.Replace("$PASSWORD_URL$", $"{_configuration["domainUrl"]}/api/v2.0/auth/changepassword/{vDetails.VerificationCode}"); NotificationModel notificationModel = new NotificationModel() { Content = template, ContentType = EmailContentType.HTML, Title = "Password Reset", ToEmails = new List <string>() { userModel.email }, FromEmail = _configuration["EmailConfiguration:VerificationEmail"] }; await _emailService.Send(notificationModel); } } return(Ok(new ResponseModel() { code = ResponseCode.SUCCESSFULL, description = $"Please follow the link sent to your mail for password reset" })); }
public async Task <IActionResult> Post([FromBody] UserModel userModel) { UserModel um = await _userService.Get(userModel.email); VerificationDetailModel vDetails = new VerificationDetailModel() { CreatedBy = User.Identity.Name, VerificationCode = _codeGenerationService.VerificationCode() }; if (um != null) { vDetails.OwnerId = um.id.ToString(); ResponseModel responseModel = new ResponseModel(); responseModel.code = ResponseCode.FAIL; if (um.userStatus == UserStatus.PENDING) { bool vResult = await _verificationService.Add(vDetails); if (vResult) { string template = await _templateService.GetTemplate(TemplateType.EMAIL_CONFIRMATION); if (!string.IsNullOrEmpty(template)) { template = template.Replace("$FULLNAME$", $"{userModel.lastname} {userModel.otherNames}"); template = template.Replace("$VERIFICATION_URL$", $"{_configuration["domainUrl"]}/api/v2.0/user/verify/{um.id}/{vDetails.VerificationCode}"); NotificationModel notificationModel = new NotificationModel() { Content = template, ContentType = EmailContentType.HTML, Title = "Email Verification", ToEmails = new List <string>() { um.email }, FromEmail = _configuration["EmailConfiguration:VerificationEmail"] }; await _emailService.Send(notificationModel); } } responseModel.description = $"An email has been send to your email for verification"; } return(Ok(responseModel)); } bool result = await _userService.Add(userModel); if (result) { UserModel umm = await _userService.Get(userModel.email); vDetails.OwnerId = umm.id.ToString(); bool vResult = await _verificationService.Add(vDetails); if (vResult) { string template = await _templateService.GetTemplate(TemplateType.EMAIL_CONFIRMATION); if (!string.IsNullOrEmpty(template)) { template = template.Replace("$FULLNAME$", $"{userModel.lastname} {userModel.otherNames}"); template = template.Replace("$VERIFICATION_URL$", $"{_configuration["domainUrl"]}/api/v2.0/user/verify/{umm.id}/{vDetails.VerificationCode}"); NotificationModel notificationModel = new NotificationModel() { Content = template, ContentType = EmailContentType.HTML, Title = "Email Verification", ToEmails = new List <string>() { umm.email }, FromEmail = _configuration["EmailConfiguration:VerificationEmail"] }; await _emailService.Send(notificationModel); } } return(Ok(new ResponseModel() { code = ResponseCode.SUCCESSFULL, description = $"{userModel.email} has been created successfully", data = umm.id })); } throw new UnknownException("An error occurred while trying to create a your login details. Please try again or contact your administrator"); }