public virtual async Task <ActionResult> EmailConfirmation(EmailConfirmationViewModel model) { CheckModelState(); _unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant); var userId = Convert.ToInt64(SimpleStringCipher.Decrypt(model.UserId)); var user = await _userManager.GetUserByIdAsync(userId); if (user == null || user.EmailConfirmationCode.IsNullOrEmpty() || user.EmailConfirmationCode != model.ConfirmationCode) { throw new UserFriendlyException(L("InvalidEmailConfirmationCode"), L("InvalidEmailConfirmationCode_Detail")); } user.IsEmailConfirmed = true; user.EmailConfirmationCode = null; await _userManager.UpdateAsync(user); var tenancyName = user.TenantId.HasValue ? (await _tenantManager.GetByIdAsync(user.TenantId.Value)).TenancyName : ""; return(RedirectToAction( "Login", new { successMessage = L("YourEmailIsConfirmedMessage"), tenancyName = tenancyName, userNameOrEmailAddress = user.UserName })); }
public async Task <JsonResult> ReSendEmailConfirmationCode([FromBody] EmailConfirmationViewModel input) { // 校验验证码 // ValuedationCode(VerificationImgType.RegisterActive, input.Code); await VerifyImgCodeAsync(CaptchaType.TenantUserRegisterActiveEmail, input.Code); // 校验 resetcode错误 var user = _userManager.Users .Where(o => o.EmailAddress == input.EmailAddress) .FirstOrDefault(); if (user == null) { return(new JsonResult(false)); } if (user.IsEmailConfirmed || user.IsActive) { throw new UserFriendlyException("此用户已经激活!"); } // 发送激活码 var activeCode = await SendMailAndReturnCode("52ABP官方 - 激活账号邮件", "请点击链接进行激活: {0}Account/RegisterResult?code={1}", user); user.EmailConfirmationCode = activeCode; await _userManager.UpdateAsync(user); return(new JsonResult(true)); }
public virtual async Task <ActionResult> EmailConfirmation(EmailConfirmationViewModel model) { string tenancyName; this.CheckModelState(); IActiveUnitOfWork current = this._unitOfWorkManager.Current; current.DisableFilter(new string[] { "MayHaveTenant" }); long num = Convert.ToInt64(SimpleStringCipher.Decrypt(model.UserId, "gsKnGZ041HLL4IM8")); FuelWerx.Authorization.Users.User userByIdAsync = await this._userManager.GetUserByIdAsync(num); if (userByIdAsync == null || userByIdAsync.EmailConfirmationCode.IsNullOrEmpty() || userByIdAsync.EmailConfirmationCode != model.ConfirmationCode) { throw new UserFriendlyException(this.L("InvalidEmailConfirmationCode"), this.L("InvalidEmailConfirmationCode_Detail")); } userByIdAsync.IsEmailConfirmed = true; userByIdAsync.EmailConfirmationCode = null; await this._userManager.UpdateAsync(userByIdAsync); if (!userByIdAsync.TenantId.HasValue) { tenancyName = ""; } else { TenantManager tenantManager = this._tenantManager; int? tenantId = userByIdAsync.TenantId; tenancyName = (await tenantManager.GetByIdAsync(tenantId.Value)).TenancyName; } string str = tenancyName; ActionResult action = this.RedirectToAction("Login", new { successMessage = this.L("YourEmailIsConfirmedMessage"), tenancyName = str, userNameOrEmailAddress = userByIdAsync.UserName }); return(action); }
public async Task <IActionResult> ConfirmEmail(EmailConfirmationViewModel model) { var response = await _authentication.ConfirmUserAsync(model); if (response != null) { return(Ok(response)); } return(BadRequest()); }
public virtual async Task <ActionResult> EmailConfirmation(EmailConfirmationViewModel input) { await SwitchToTenantIfNeeded(input.TenantId); await _accountAppService.ActivateEmail(input); return(RedirectToAction( "Login", new { successMessage = L("YourEmailIsConfirmedMessage"), userNameOrEmailAddress = (await _userManager.GetUserByIdAsync(input.UserId)).UserName })); }
private async Task <EmailConfirmationViewModel> GenerateConfirmationEmail(string email, string id) { string code = await ApiService <string> .GetApi($"/api/Account/GenerateConfirmationEmailTokenAsync/{id}"); string callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = id, code }, protocol: Request.Url.Scheme); EmailConfirmationViewModel emailConfirmationViewModel = new EmailConfirmationViewModel() { Subject = "dotNET Academy account bevestiging", Body = $"Gelieve uw dotNET Academy account te bevestigen door op deze link te klikken: {callbackUrl}" }; return(emailConfirmationViewModel); }
public async Task <ActionResult> Index(string userId, string token) { var result = await _userManager.ConfirmEmailAsync(userId, token); var viewModel = new EmailConfirmationViewModel(); if (result.Succeeded) { viewModel.Message = "Your email have been confirmed."; } else { viewModel.Message = "Oops... Something went wrong."; } return(View(viewModel)); }
public async Task <IActionResult> EmailConfirmationResend(EmailConfirmationViewModel vm) { var user = await userManager.FindByEmailAsync(vm.Email); if (user != null) { if (!user.EmailConfirmed) { await sendConfirmationLinkAsync(user); } vm.IsConfirmationLinkSent = true; return(View(vm)); } vm.Message = $"The Email {vm.Email} is not exist."; return(View(vm)); }
public async Task <IActionResult> LogIn(LogInViewModel vm, string returnUrl) { if (ModelState.IsValid) { var user = await userManager.FindByEmailAsync(vm.Email); if (user != null) { // check if user Email is confirmed if (!user.EmailConfirmed) { var emailConfirmationVM = new EmailConfirmationViewModel { Email = user.Email, UserName = user.UserName }; return(View("EmailConfirmationResend", emailConfirmationVM)); } var result = await signInManager.PasswordSignInAsync(user.UserName, vm.Password, vm.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { if (Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } return(RedirectToAction("Index", "Songs")); } else { vm.Message = "Invalid login attempt."; return(View(vm)); } } else { vm.Message = "This account is not exist."; return(View(vm)); } } // If we got this far, something failed, reset the loging form return(View()); }
public Task SendConfirmationEmailAsync(ApplicationUser user, string callback_url) { var engine = new RazorLightEngineBuilder() .UseMemoryCachingProvider() .Build(); string template = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "wwwroot", "Templates", "Emails", "Account", "ConfirmationEmail.cshtml")); EmailConfirmationViewModel model = new EmailConfirmationViewModel() { FirstName = user.FirstName, CallbackLink = callback_url, UnsubscribeLink = "www.google.com" }; string result = engine.CompileRenderAsync("Confirmation", template, model).Result; return(Execute(Options.SendGridKey, "Confirm Your Account", result, user.Email)); }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { string userJson = await ApiService <string> .PostApi($"/api/Account/FindByEmailAsync", model.Email); ApplicationUserViewModel user = new ApplicationUserViewModel(); if (userJson != null) { user = JsonConvert.DeserializeObject <ApplicationUserViewModel>(userJson); if (!user.EmailConfirmed) { // Don't reveal that the user does not exist or is not confirmed return(View("ForgotPasswordConfirmation")); } } // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await ApiService <string> .GetApi($"/api/Account/GeneratePasswordResetTokenAsync/{user.Id}"); string callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code }, Request.Url.Scheme); EmailConfirmationViewModel emailConfirmationViewModel = new EmailConfirmationViewModel() { Subject = "dotNET Academy wachtwoord reset", Body = $"Gelieve uw dotNET Academy wachtwoord te resetten door op deze link te klikken: {callbackUrl}" }; await ApiService <EmailConfirmationViewModel> .PostApi($"/api/Account/SendEmailAsync/{user.Id}", emailConfirmationViewModel); return(RedirectToAction("ForgotPasswordConfirmation", "Account")); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <DefaultResponse> ConfirmUserAsync(EmailConfirmationViewModel model) { if (string.IsNullOrWhiteSpace(model.UserId) || string.IsNullOrWhiteSpace(model.Token)) { return(null); } var user = await _userManager.FindByIdAsync(model.UserId); if (user is null) { return(null); } var result = await _userManager.ConfirmEmailAsync(user, model.Token); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, "Member"); var accessToken = await GenerateAccessWithClaims(user); var refreshToken = await _tokenHandler.GenerateRefreshTokenAsync(user); _sessionContext.Add(new Session { User = user, RefreshToken = refreshToken, Fingerprint = model.Fingerprint, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, ExpiresAt = DateTime.Now.AddSeconds(_jwtConfig.RefreshExpirationTime) }); if (await _context.SaveChangesAsync() > 0) { return(new DefaultResponse(accessToken, refreshToken, _jwtConfig.AccessExpirationTime)); } } return(null); }
public async Task SendEmailAsync([FromUri] string id, [FromBody] EmailConfirmationViewModel model) { await _accountBl.SendEmailAsync(id, model.Subject, model.Body); }