public static MembershipUserWrapper AddUser(String username, String password, String email, String firstname, String lastname) { MembershipUserWrapper existing = FindByUsername(username); if (existing.MembershipUser != null) throw new MembershipException("The username " + username + " already exists and may not be used again."); if (!IsValidUsername(username)) throw new MembershipException("The username " + username + " is not valid and may not be used."); if (!IsValidEmail(email)) throw new MembershipException("The email " + email + " is not valid and may not be used."); UserInfo info = new UserInfo(); info.Guid = Guid.NewGuid().ToString(); info.Firstname = firstname; info.Lastname = lastname; info.Username = username; info.Email = email; info.Created = UtcDateTime.Now; UserInfoDao dao = new UserInfoDao(); using (Transaction tx = new Transaction()) { dao.Save<UserInfo>(info); tx.Commit(); } MembershipUser user = System.Web.Security.Membership.CreateUser(info.Username, password, info.Email); return new MembershipUserWrapper(info, user); }
public static void UpdateUserInfo(UserInfo userinfo) { UserInfoDao dao = new UserInfoDao(); using (Transaction tx = new Transaction()) { dao.Save<UserInfo>(userinfo); tx.Commit(); } }
public static MembershipUserWrapper CreateDemoAccount() { UserInfo info = new UserInfo(); info.Username = DemoAccountUsername; info.Email = DemoAccountUsername; info.Firstname = "GooeyCMS Demo"; info.Lastname = "Account"; info.Company = "GooeyCMS"; info.Address1 = "135 Gooey Ave"; info.Address2 = null; info.City = "New York"; info.State = "NY"; info.Zipcode = "10114"; info.Guid = System.Guid.NewGuid().ToString(); info.Created = UtcDateTime.Now; UserInfoDao dao = new UserInfoDao(); using (Transaction tx = new Transaction()) { dao.Save<UserInfo>(info); tx.Commit(); } MembershipUser user = System.Web.Security.Membership.CreateUser(DemoAccountUsername, DemoAccountPassword, DemoAccountUsername); System.Web.Security.Roles.AddUserToRole(DemoAccountUsername, SecurityConstants.Roles.SITE_ADMINISTRATOR); MembershipUserWrapper wrapper = new MembershipUserWrapper(); wrapper.MembershipUser = user; wrapper.UserInfo = info; return wrapper; }