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);
        }
 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);
     }
 }
 public static void UpdateUserInfo(UserInfo userinfo)
 {
     UserInfoDao dao = new UserInfoDao();
     using (Transaction tx = new Transaction())
     {
         dao.Save<UserInfo>(userinfo);
         tx.Commit();
     }
 }
        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;
        }
 public IList<Package> GetSitePackagesForUser(UserInfo user)
 {
     PackageDao dao = new PackageDao();
     return dao.FindByUserId(user.Id);
 }
        public IList<Package> GetPurchasedPackages(UserInfo user)
        {
            IList<Package> packages = new List<Package>();

            UserPackageDao dao = new UserPackageDao();
            PackageDao packageDao = new PackageDao();

            IList<UserPackage> ups = dao.FindByUserAndPackage(user.Guid);
            foreach (UserPackage up in ups)
            {
                Package package = packageDao.FindByPackageGuid(up.PackageGuid);
                if (package != null)
                    packages.Add(package);
            }

            return packages;
        }