protected virtual async Task RegisterExternalUserAsync(ExternalLoginInfo externalLoginInfo, string emailAddress) { var userDto = await AccountAppService.RegisterAsync( new RegisterDto { AppName = "MVC", EmailAddress = Input.EmailAddress, Password = Input.Password, UserName = Input.UserName } ); var user = await UserManager.GetByIdAsync(userDto.Id); var userLoginAlreadyExists = user.Logins.Any(x => x.TenantId == user.TenantId && x.LoginProvider == externalLoginInfo.LoginProvider && x.ProviderKey == externalLoginInfo.ProviderKey); if (!userLoginAlreadyExists) { (await UserManager.AddLoginAsync(user, new UserLoginInfo( externalLoginInfo.LoginProvider, externalLoginInfo.ProviderKey, externalLoginInfo.ProviderDisplayName ))).CheckErrors(); } await SignInManager.SignInAsync(user, true); }
protected virtual async Task RegisterLocalUserAsync() { ValidateModel(); var userDto = await AccountAppService.RegisterAsync( new RegisterDto { AppName = "MVC", EmailAddress = Input.EmailAddress, Password = Input.Password, UserName = Input.UserName } ); var user = await UserManager.GetByIdAsync(userDto.Id); await SignInManager.SignInAsync(user, isPersistent: true); }
public virtual async Task <IActionResult> OnPostAsync() { await CheckSelfRegistrationAsync(); var registerDto = new RegisterDto() { AppName = "MVC" }; if (IsExternalLogin) { var externalLoginInfo = await SignInManager.GetExternalLoginInfoAsync(); if (externalLoginInfo == null) { Logger.LogWarning("External login info is not available"); return(RedirectToPage("./Login")); } registerDto.EmailAddress = Input.EmailAddress; registerDto.UserName = Input.EmailAddress; registerDto.Password = GeneratePassword(); } else { ValidateModel(); registerDto.EmailAddress = Input.EmailAddress; registerDto.Password = Input.Password; registerDto.UserName = Input.UserName; } var userDto = await AccountAppService.RegisterAsync(registerDto); var user = await UserManager.GetByIdAsync(userDto.Id); await SignInManager.SignInAsync(user, isPersistent : false); if (IsExternalLogin) { await AddToUserLogins(user); } return(Redirect(ReturnUrl ?? "~/")); //TODO: How to ensure safety? IdentityServer requires it however it should be checked somehow! }
protected override async Task RegisterLocalUserAsync() { ValidateModel(); var userDto = await AccountAppService.RegisterAsync( new RegisterDto { AppName = "Abp.EmailMarketing", EmailAddress = Input.EmailAddress, Password = Input.Password, UserName = Input.UserName } ); _abpIdentityUser = await UserManager.GetByIdAsync(userDto.Id); // Send user an email to confirm email address await SendEmailToAskForEmailConfirmationAsync(_abpIdentityUser); }
[UnitOfWork] //TODO: Will be removed when we implement action filter public virtual async Task <IActionResult> OnPostAsync() { ValidateModel(); await CheckSelfRegistrationAsync(); var registerDto = new RegisterDto { AppName = "MVC", EmailAddress = Input.EmailAddress, Password = Input.Password, UserName = Input.UserName }; var userDto = await AccountAppService.RegisterAsync(registerDto); var user = await UserManager.GetByIdAsync(userDto.Id); await UserManager.SetEmailAsync(user, Input.EmailAddress); await SignInManager.SignInAsync(user, isPersistent : false); return(Redirect(ReturnUrl ?? "/")); //TODO: How to ensure safety? IdentityServer requires it however it should be checked somehow! }