public IHttpActionResult Register(RegistrationRequest request) { var response = new RegistrationResponse(); try { var member = MembershipAdapter.GetMember(request.Email); if (member.Exists() && member.ConfirmedRegistration()) { request.AddError("Email", "Email already exists"); } if (request.IsValidModel()) { if (!request.PasswordsMatch()) { request.AddError("Password", "Passwords do not match"); } } if (!request.HasErrors()) { if (member.IsNewRegistration()) { member.Email = request.Email; member.RegistrationDate = DateTime.Now.ToUniversalTime(); member.IsActive = true; member.IsAdmin = false; member.Security = new MemberPassword(); member.Security.InitializePassword(request.Password); member.Profile = new MemberProfile(); member.Profile.Alias = request.Alias; member.Profile.TimeZoneId = ConfigHelper.DefaultTimeZoneId; var registrationToken = new MemberToken(); registrationToken.Token = Guid.NewGuid(); registrationToken.TokenType = TokenTypes.Registration; registrationToken.RequestDate = member.RegistrationDate; member.Tokens.Add(registrationToken); member = MembershipAdapter.AddMember(member); } else if (member.IsPendingRegistrationConfirmation()) { member.Security.InitializePassword(request.Password); member.Profile.Alias = request.Alias; var registrationToken = MembershipAdapter.GetMemberTokens(member.Id, TokenTypes.Registration, true); member.Tokens.Add(registrationToken.ElementAt(0)); member = MembershipAdapter.ReRegisterMember(member); } var email = new RegistrationEmail { DomainName = ConfigHelper.DomainName, DomainBaseUrl = ConfigHelper.DomainBaseUrl, Alias = request.Alias, ConfirmationToken = member.Tokens.ElementAt(0).Token }; var emailBuilder = new EmailBuilder(EmailReference.HTML.Templates.Main, EmailReference.HTML.Contents.Registration); var emailBody = emailBuilder.BuildBody<RegistrationEmail>(email); var emailResult = EmailHelper.SendEmail(ConfigHelper.NoReplayEmailAddress, ConfigHelper.DomainName, request.Email, request.Alias, email.Subject, emailBody, true); if (emailResult) { response.IsSuccessful = true; response.StatusMessage = "Registration succeeded"; } } else { response.Errors.AddRange(request.GetErrors()); response.IsSuccessful = false; response.StatusMessage = "Registration was unsuccessful"; } } catch (Exception ex) { request.Password = string.Empty; request.PasswordConfirm = string.Empty; this.Log<RegistrationRequest>(LogCategories.Error, request, ex.Message); response.IsSuccessful = false; response.StatusMessage = this.StatusMessageForExpection; response.Errors.Add(ex.Message); } return Ok(response); }
public void Register() { var email = this.RequestUserInput<string>("Enter email: ", string.Empty); var alias = this.RequestUserInput<string>("Enter alias: ", string.Empty); var password = this.RequestUserInput<string>("Enter password: "******"Re-enter password: ", string.Empty); var request = new RegistrationRequest { Email = email, Alias = alias, Password = password, PasswordConfirm = passwordConfirm }; var response = proxy.Register(request); this.OutputResponse(response); }