public ActionResult Register(RegisterViewModel model) { if (model == null) { return null; } if (!StrixMembership.Configuration.Registration.AllowUserRegistration) { return null; } if (ModelState.IsValid) { var result = this._accountService.RegisterAccount(model); if (result.Success && result.Message == null) { return this.RedirectToAction("RegisterSuccess"); } else { ModelState.AddModelError(string.Empty, result.Message); } } return this.View(model); }
public SaveResult<UserViewModel> RegisterAccount(RegisterViewModel model) { if (model == null) { throw new ArgumentNullException("model"); } var password = this._securityManager.GeneratePassword(); User user = this._userManager.Create(model.Name, model.Email, StrixPlatform.CurrentCultureCode, password, false, model.AcceptedTerms, model.RegistrationComment); var result = new SaveResult<UserViewModel>(user != null, user.Map<UserViewModel>()); if (user != null) { var verificationId = Guid.NewGuid(); this._securityManager.SetVerificationId(user.Id, verificationId); this.SaveChanges(); // Add the user role to allow logging in. this._roleManager.AddUserToRole(StrixPlatform.User.GroupId, user.Id, PlatformConstants.USERROLE); this.SaveChanges(); if (StrixMembership.Configuration.Registration.AutoApproveUsers) { if (!this._mailer.SendApprovedAccountMail(user.PreferredCulture, user.Name, user.Email, verificationId)) { result.Message = Resources.Interface.ErrorSendingApprovedAccountMail; Logger.Log(string.Format("An error occurred while sending the approved account mail to user {0}", user.Name), LogLevel.Error); } } else { if (!this._mailer.SendUnapprovedAccountMail(user.PreferredCulture, user.Name, user.Email, verificationId)) { result.Message = Resources.Interface.ErrorSendingUnapprovedAccountMail; Logger.Log(string.Format("An error occurred while sending the unapproved account mail to user {0}", user.Name), LogLevel.Error); } } } return result; }