Пример #1
0
        public static int CreateAccount(string email, string password, bool isSuperUser = false)
        {
            bool IsValid = IsEmailSyntaxValid(email);
            string PasswordSalt = Crypto.GeneratePasswordSalt();
            string EncryptPassword = Crypto.Encrypt(password, PasswordSalt);

            if (!UserExists(email) & IsValid)
            {
                User U = new User
                    {
                        CreateDate = DateTime.Now,
                        Email = email,
                        Password = EncryptPassword,
                        PasswordSalt = PasswordSalt,
                        LastLoginDate = DateTime.Now,
                        FailedPasswordAttemptCount = 0,
                        IsLockedOut = false,
                        IsSuperUser = isSuperUser,
                        PortalID = Users.PortalID,
                    };
                Utils.DbContext.Users.AddObject(U);
                Utils.DbContext.SaveChanges();

                BLL.Roles roles = new Roles(Utils.DbContext);
                roles.AddUsersToRoles(1, U.UserID, 1);

                return U.UserID;
            }
            else
            {
                return 0;
            }
        }
Пример #2
0
        public static void ImportUsers()
        {
            string[] csvlines = File.ReadAllLines(@"C:\codeplex\jQueryMobile\jQueryMobile\Job\SampleData\Users.csv");

            var query = from csvline in csvlines
                        let data = csvline.Split(',')
                        select new
                        {
                            PortalID = data[0],
                            Email = data[1],
                            Password = data[2],
                            FacebookID = data[3],
                            FullName = data[4],
                            FirstName = data[5],
                            MiddleName = data[6],
                            LastName = data[7],
                            Gender = data[8],
                            Local = data[9],
                            Link = data[10],
                            _TimeZone = data[11],
                            Birthdate = data[12],
                            Picture = data[13],
                            Telephone = data[14],
                            LocationID = data[15],
                            Address = data[16],
                            City = data[17],
                            Region = data[18],
                            PostalCode = data[19]
                        };

            int row = 0;

            foreach (var i in query)
            {
                if (row != 0) // skip first row header name
                {
                    string passwordsalt = Crypto.GeneratePasswordSalt();

                    User U = new User
                    {
                        PortalID = int.Parse(i.PortalID),
                        Email = i.Email,
                        Password = Crypto.Encrypt("Password", passwordsalt),
                        PasswordSalt = passwordsalt,
                        FacebookID = i.FacebookID,
                        FullName = i.FullName,
                        FirstName = i.FirstName,
                        MiddleName = i.MiddleName,
                        LastName = i.LastName,
                        Gender = i.Gender,
                        Local = i.Local,
                        Link = i.Link,
                        TimeZone = int.Parse(i._TimeZone),
                        Birthday = DateTime.Parse(i.Birthdate),
                        Picture = i.Picture,
                        Telephone = i.Telephone,
                        LocationID = i.LocationID,
                        Address = i.Address,
                        City = i.City,
                        Region = i.Region,
                        PostalCode = i.PostalCode,
                        CreateDate = DateTime.Now,
                        LastLoginDate = DateTime.Now,
                        FailedPasswordAttemptCount = 0,
                        IsLockedOut = false,
                        IsSuperUser = false
                    };

                    Utils.DbContext.Users.AddObject(U);
                    Utils.DbContext.SaveChanges();

                    BLL.Roles roles = new Roles(Utils.DbContext);
                    roles.AddUsersToRoles(1, U.UserID, 1);
                }
            }
                row++;
        }