public async Task <IHttpActionResult> ConfirmEmail(EmailConfirmationRequestModel model) { var result = await _service.ConfirmEmail(model); if (result.IsSuccess == false) { await _service.ResetProfile(model.Id); } return(Ok(result)); }
public async Task <EmailResponseModel> SendEmailConfirmationCode(EmailConfirmationRequestModel requestModel) { var company = requestModel.IsQueryAsTracking ? _repository.GetById(requestModel.Id) : _repository.AsNoTracking().SingleOrDefault(x => x.Id == requestModel.Id); if (company == null) { return(null); } EmailResponseModel response = new EmailResponseModel(); if (string.IsNullOrWhiteSpace(company.EmailConfirmationCode) || requestModel.IsResend) { company.EmailConfirmationCode = EmailHelper.GenerateVerificationCode(); company.EmailConfirmationCodeExpireTime = DateTime.Now.AddMinutes(30); if (company.IsChangeEmail) { await _emailService.SendConfirmationEmailToUser(company.AwaitingConfirmEmail, company.Name, company.EmailConfirmationCode, company.EmailConfirmationCodeExpireTime); } else if (!company.IsEmailConfirmed) { await _emailService.SendConfirmationEmailToUser(company.Email, company.Name, company.EmailConfirmationCode, company.EmailConfirmationCodeExpireTime); } if (requestModel.IsQueryAsTracking) { _repository.EditAsTenant(company); response.IsSuccess = await _repository.CommitAsync(); } else { response.ConfirmationCode = company.EmailConfirmationCode; response.ExpireTime = company.EmailConfirmationCodeExpireTime; } } return(response); }
public async Task SendEmailConfirmationCode(EmailConfirmationRequestModel model) { var user = _userManager.FindById(HttpContext.Current.User.Identity.GetUserId()); if (user.IsChangeEmail && !string.IsNullOrWhiteSpace(user.AwaitingConfirmEmail)) { if (string.IsNullOrWhiteSpace(user.EmailConfirmationCode) || model.IsResend) { user.EmailConfirmationCode = await _userManager.GenerateEmailConfirmationTokenAsync(user.Id); user.EmailConfirmed = true; user.EmailConfirmationCodeExpireTime = DateTime.Now.AddMinutes(30); await _emailService.SendConfirmationEmailToUser(user.AwaitingConfirmEmail, user.FullName(), user.EmailConfirmationCode, user.EmailConfirmationCodeExpireTime.GetValueOrDefault()); await _userManager.UpdateAsync(user); } } }
public async Task <EmailResponseModel> ConfirmEmail(EmailConfirmationRequestModel model) { EmailResponseModel response = new EmailResponseModel(); if (!string.IsNullOrWhiteSpace(model.ConfirmationCode) && !string.IsNullOrWhiteSpace(model.Id)) { var user = await _userManager.FindByIdAsync(model.Id); if (user.EmailConfirmationCodeExpireTime.HasValue && user.EmailConfirmationCodeExpireTime.GetValueOrDefault() < DateTime.Now) { response.IsSuccess = false; response.Message = "Your confirmation code has been expired."; } if (!string.IsNullOrWhiteSpace(user.EmailConfirmationCode) && string.Equals(model.ConfirmationCode?.ToLower(), user.EmailConfirmationCode?.ToLower())) { user.Email = user.AwaitingConfirmEmail; if (!user.UserName.IsReservedUsername()) { user.UserName = user.Email; } user.IsChangeEmail = false; user.AwaitingConfirmEmail = null; user.EmailConfirmationCode = null; user.EmailConfirmationCodeExpireTime = null; await _userManager.UpdateAsync(user); } else { response.IsSuccess = false; response.Message = "Your confirmation code is not valid"; } } return(response); }
public async Task <EmailResponseModel> ConfirmEmail(EmailConfirmationRequestModel requestModel) { var company = _repository.GetById(requestModel.Id); EmailResponseModel response = new EmailResponseModel(); if (company.EmailConfirmationCodeExpireTime.HasValue && company.EmailConfirmationCodeExpireTime.GetValueOrDefault() < DateTime.Now) { response.IsSuccess = false; response.Message = "Your confirmation code has been expired."; } else if (string.Equals(company.EmailConfirmationCode, requestModel.ConfirmationCode)) { company.IsEmailConfirmed = true; company.EmailConfirmationCode = null; if (!string.IsNullOrWhiteSpace(company.AwaitingConfirmEmail)) { company.Email = company.AwaitingConfirmEmail; } company.IsChangeEmail = false; company.EmailConfirmationCodeExpireTime = null; company.AwaitingConfirmEmail = null; _repository.EditAsTenant(company); await _repository.CommitAsync(); } else { response.IsSuccess = false; response.Message = "Your confirmation code is not valid"; } return(response); }
public async Task <IHttpActionResult> SendEmailConfirmationCode(EmailConfirmationRequestModel model) { await _service.SendEmailConfirmationCode(model); return(Ok(true)); }
public async Task <IHttpActionResult> ConfirmEmail(EmailConfirmationRequestModel requestModel) { var responseModel = await _service.ConfirmEmail(requestModel); return(Ok(responseModel)); }