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(); } }
internal static void DeleteUser(UserInfo userAdapter) { UserInfoDao dao = new UserInfoDao(); UserInfo user = dao.FindByGuid(userAdapter.Guid); if (user != null) { using (Transaction tx = new Transaction()) { dao.Delete<UserInfo>(user); tx.Commit(); } System.Web.Security.Membership.DeleteUser(user.Username); } }
/// <summary> /// Gets all of the users for the specified site /// </summary> /// <param name="siteGuid"></param> /// <returns></returns> public static IList<UserInfo> GetUsersBySite(Int32 sitePrimaryKey) { UserInfoDao dao = new UserInfoDao(); return dao.FindBySiteGuid(sitePrimaryKey); }
/// <summary> /// Finds the membership information based upon the username /// </summary> /// <param name="p"></param> /// <returns></returns> public static MembershipUserWrapper FindByUsername(String username) { MembershipUser user = System.Web.Security.Membership.GetUser(username); UserInfo info = new UserInfoDao().FindByUsername(username); //Check if the asp.net membership account is orphaned, if so, delete it if ((user != null) && (info == null)) { System.Web.Security.Membership.DeleteUser(user.UserName); user = null; } //Check if the gooeycms account is orphaned, if so, delete it if ((user == null) && (info != null)) { UserInfoDao dao = new UserInfoDao(); using (Transaction tx = new Transaction()) { dao.Delete<UserInfo>(info); tx.Commit(); } info = null; } MembershipUserWrapper wrapper = new MembershipUserWrapper(); wrapper.MembershipUser = user; wrapper.UserInfo = info; return wrapper; }
public static MembershipUserWrapper FindByUserGuid(Data.Guid userGuid) { UserInfoDao dao = new UserInfoDao(); UserInfo user = dao.FindByGuid(userGuid); if (user == null) throw new MembershipException("The specified user guid is not valid"); MembershipUser user2 = System.Web.Security.Membership.GetUser(user.Username); return new MembershipUserWrapper(user, user2); }
public static MembershipUserWrapper CreateFromRegistration(Registration registration) { Boolean exists = (System.Web.Security.Membership.GetUser(registration.Email) != null); MembershipUserWrapper wrapper = new MembershipUserWrapper(); if (String.IsNullOrEmpty(registration.ExistingAccountGuid)) { UserInfo info = new UserInfo(); MembershipUser user = null; info.Username = registration.Email; info.Email = registration.Email; info.Firstname = registration.Firstname; info.Lastname = registration.Lastname; info.Company = registration.Company; info.Address1 = registration.Address1; info.Address2 = registration.Address2; info.City = registration.City; info.State = registration.State; info.Zipcode = registration.Zipcode; info.Guid = System.Guid.NewGuid().ToString(); info.Created = UtcDateTime.Now; UserInfoDao dao = new UserInfoDao(); if (!exists) { using (Transaction tx = new Transaction()) { dao.SaveObject(info); tx.Commit(); } } //Create the account in the asp.net membership system String password = Decrypt(registration.EncryptedPassword); try { if (!exists) user = System.Web.Security.Membership.CreateUser(registration.Email, password, registration.Email); if (!System.Web.Security.Roles.IsUserInRole(registration.Email, SecurityConstants.Roles.SITE_ADMINISTRATOR)) System.Web.Security.Roles.AddUserToRole(registration.Email, SecurityConstants.Roles.SITE_ADMINISTRATOR); } catch (MembershipCreateUserException e) { //Rollback the user info using (Transaction tx = new Transaction()) { dao.DeleteObject(info); tx.Commit(); } throw e; } wrapper.MembershipUser = user; wrapper.UserInfo = info; } else { UserInfo info = new UserInfoDao().FindByGuid(registration.ExistingAccountGuid); if (info != null) { //make sure the email addresses match if (info.Email.EqualsCaseInsensitive(registration.Email)) wrapper = FindByUsername(info.Email); } } return wrapper; }
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; }