public ProviderMember CreateMember(ProviderRegistrationForm form) { var userName = form.Member.Email.Scrub(); var password = form.Password.Scrub(); var model = ProviderMember.Empty; if (this.IsMongoMembershipEnabled) { try { var status = MembershipCreateStatus.UserRejected; var membershipUser = this.MembershipProvider.CreateUser(userName, password, userName, "", "", true, null, out status); if (status == MembershipCreateStatus.Success) { // create a user account model = this.Uow.ProviderMembers.CreateMember(form, membershipUser.ProviderUserKey.ToString()); if (model == null) { throw new Exception("failed to create provider account"); } } else { Logger.Warn(string.Format("Failed to create Member: {0}. Reason: {1}", userName, status)); } } catch (Exception e) { Logger.Error(string.Format("Error creating Member: {0}", userName), e); throw e; } } else { // create a user account model = this.Uow.ProviderMembers.CreateMember(form, string.Empty); if (model == null) { throw new Exception("failed to create provider account"); } } try { WebSecurity.CreateUserAndAccount(userName, password, new { MongoUserId = model.Id }); } catch (Exception e) { Logger.Error(string.Format("Error creating WebSecurity user: {0}", userName), e); throw e; } return(model); }
public HttpResponseMessage RegisterProvider(ProviderRegistrationForm registrationForm) { var formValidation = registrationForm.Validate(this.AccountSession, ValidationMode.Create); if (formValidation.IsValid) { var authenticationSecurity = new AuthenticationSecurity() { Uow = this.Uow }; try { // create the member account var member = authenticationSecurity.CreateMember(registrationForm); // set the accout session this.Uow.AccountSession = new Model.AccountSession() { MemberId = member.Id }; // use the switchboard to handle any communications related to this new member this.Switchboard.ProviderMemberCreated(member); // login to the account AuthenticationSecurity.Login(registrationForm.Member.Email, registrationForm.Password); // add appropriate roles to the account var roles = new string[2] { Definitions.Account.Roles.Elevated, Definitions.Account.Roles.Provider }; authenticationSecurity.AddRolesToUser(registrationForm.Member.Email, roles); // set redirect location based on user type var redirect = AuthenticationSecurity.RegistrationAccountTypeRedirect(AccountType.Provider); return(CreateSuccessResponse(new { success = true, redirect = redirect }, HttpStatusCode.Created)); } catch (Exception ex) { // log exception Logger.Error(string.Format("Exception detected attempting to create provider account and login for email {0}", registrationForm.Member.Email), ex); // log the user out AuthenticationSecurity.Logout(); return(CreateErrorResponse(ex)); } } // invalid parameters, generate response return(CreateInvalidResponse(formValidation)); }
public ProviderMember CreateMember(ProviderRegistrationForm registrationForm, string membershipId) { // create the model var model = new ProviderMember() { AccountType = AccountType.Provider, AccountStatus = AccountStatus.Pending, AccountPrestige = AccountPrestige.Creator, MembershipId = membershipId, Email = registrationForm.Member.Email.Scrub(), FirstName = registrationForm.Member.FirstName.Scrub(), LastName = registrationForm.Member.LastName.Scrub(), PortfolioIds = new List <string>(), PortfolioId = string.Empty, }; // insert the collection var result = this.Collection.Insert(model); if (result.Ok) { // add the receipts model.Created = new ChangeReceipt() { By = model.Id, On = this.TimeStamp }; model.Modified = new ChangeReceipt() { By = model.Id, On = this.TimeStamp }; // update the entity model = Update(model); // log the creation this.Logger.Info(string.Format("created provider member for email {0} with ID {1}", model.Email, model.Id)); // return the created model return(model); } else { // log the failure this.Logger.Error(string.Format("failed to create provider member for email {0}. Code: {1}, Reason: {2}", model.Email, result.Code, result.ErrorMessage)); } return(null); }