public void RegisterTest() { RegisterViewModel input = new RegisterViewModel { EmailAddress = "test.com", IsExternalLogin = false, FirstName = "testmethod", Password = "******", Surname = "last", UserName = "******" }; throw new NotImplementedException(); }
public virtual async Task<ActionResult> Register(RegisterViewModel model) { try { CheckModelState(); //Get tenancy name and tenant if (!_multiTenancyConfig.IsEnabled) { model.TenancyName = Tenant.DefaultTenantName; } else if (model.TenancyName.IsNullOrEmpty()) { throw new UserFriendlyException(L("TenantNameCanNotBeEmpty")); } var tenant = await GetActiveTenantAsync(model.TenancyName); //Create user var user = new User { TenantId = tenant.Id, Name = model.FirstName, Surname = model.Surname, EmailAddress = model.EmailAddress.ToLower().Trim(), IsActive = true, IsEmailConfirmed = false }; //Get external login info if possible ExternalLoginInfo externalLoginInfo = null; if (model.IsExternalLogin) { externalLoginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); if (externalLoginInfo == null) { throw new ApplicationException("Can not external login!"); } user.Logins = new List<UserLogin> { new UserLogin { LoginProvider = externalLoginInfo.Login.LoginProvider, ProviderKey = externalLoginInfo.Login.ProviderKey } }; if (model.UserName.IsNullOrEmpty()) { model.UserName = model.EmailAddress; } model.Password = Users.User.CreateRandomPassword(); if (string.Equals(externalLoginInfo.Email, model.EmailAddress, StringComparison.InvariantCultureIgnoreCase)) { user.IsEmailConfirmed = true; } } else { //Username and Password are required if not external login if (model.UserName.IsNullOrEmpty() || model.Password.IsNullOrEmpty()) { throw new UserFriendlyException(L("FormIsNotValidMessage")); } } user.UserName = model.UserName; user.Password = new PasswordHasher().HashPassword(model.Password); //Switch to the tenant _unitOfWorkManager.Current.EnableFilter(AbpDataFilters.MayHaveTenant); _unitOfWorkManager.Current.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, tenant.Id); //Add default roles user.Roles = new List<UserRole>(); foreach (var defaultRole in await _roleManager.Roles.Where(r => r.IsDefault).ToListAsync()) { user.Roles.Add(new UserRole { RoleId = defaultRole.Id }); } //Save user CheckErrors(await _userManager.CreateAsync(user)); await _unitOfWorkManager.Current.SaveChangesAsync(); // Send confirmation email var code = await GenerateEmailConfirmationCodeLink(user); await _emailAppService.SendRegistrationConfirmationEmail(user, code); //await SendConfirmationEmail(user.EmailAddress, code, user.Name, user.Id); //Show a register result page return View("RegisterResult", new RegisterResultViewModel { TenancyName = tenant.TenancyName, FirstName = user.Name, LastName = user.Surname, UserName = user.UserName, EmailAddress = user.EmailAddress, IsActive = user.IsActive }); } catch (UserFriendlyException ex) { ViewBag.IsMultiTenancyEnabled = _multiTenancyConfig.IsEnabled; ViewBag.ErrorMessage = ex.Message; return View("Register", model); } }
private async Task<ActionResult> RegisterView(ExternalLoginInfo loginInfo, string tenancyName = null) { var name = loginInfo.DefaultUserName; var surname = loginInfo.DefaultUserName; var extractedNameAndSurname = TryExtractNameAndSurnameFromClaims(loginInfo.ExternalIdentity.Claims.ToList(), ref name, ref surname); var viewModel = new RegisterViewModel { TenancyName = tenancyName, EmailAddress = loginInfo.Email, FirstName = name, Surname = surname, IsExternalLogin = true }; if (!tenancyName.IsNullOrEmpty() && extractedNameAndSurname) { return await Register(viewModel); } return RegisterView(viewModel); }
private ActionResult RegisterView(RegisterViewModel model) { ViewBag.IsMultiTenancyEnabled = _multiTenancyConfig.IsEnabled; return View("Register", model); }