/// <summary> /// Registers the specified user. /// </summary> /// <param name="model">The registration model.</param> /// <param name="errorMessage">The error message that occured during regustration.</param> /// <param name="requireConfirmation">if set to <c>true</c> [require confirmation].</param> /// <param name="token">Confirmation token</param> /// <returns> /// true when user is registered and logged in /// </returns> public static bool Register(RegisterModel model, bool requireConfirmation, out string errorMessage, out string token) { errorMessage = string.Empty; token = string.Empty; try { var id = Guid.NewGuid().ToString(); token = UserSecurity.CreateUserAndAccount(model.Email, model.Password, new { MemberId = id, CustomerSession.StoreId, RegisterType = RegisterType.GuestUser.GetHashCode(), AccountState = requireConfirmation ? AccountState.PendingApproval.GetHashCode() : AccountState.Approved.GetHashCode(), Discriminator = "Account" }, requireConfirmation); var contact = new Contact { MemberId = id, FullName = String.Format("{0} {1}", model.FirstName, model.LastName) }; contact.Emails.Add(new Email { Address = model.Email, MemberId = id, Type = EmailType.Primary.ToString() }); foreach (var addr in model.Addresses) { contact.Addresses.Add(addr); } UserClient.CreateContact(contact); return(requireConfirmation || UserSecurity.Login(model.Email, model.Password)); } catch (MembershipCreateUserException e) { errorMessage = ErrorCodeToString(e.StatusCode); } catch (Exception ex) { errorMessage = ex.Message; } return(false); }