Ejemplo n.º 1
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var dbContext = new SWE4713Entities())
                {
                    User db = new User();

                    db.FirstName  = model.FirstName;
                    db.LastName   = model.LastName;
                    db.DOB        = model.DOB;
                    db.Street     = model.Street;
                    db.City       = model.City;
                    db.State      = model.State;
                    db.Zip        = model.Zip;
                    db.UserTypeId = 3;                                                                                                                                                       //default set to Accountant
                    db.UserName   = model.FirstName.Substring(0, 1).ToLower() + model.LastName.ToLower() + DateTime.Now.Month.ToString("00") + DateTime.Now.Year.ToString().Substring(2, 2); //needs to save it as [firstinitial][lastname][month][year]
                    //db.Picture = Convert.ToByte(model.Picture);
                    db.Email       = model.Email;
                    db.DateCreated = DateTime.Now;
                    db.Active      = true;
                    db.Password    = Hasher.HashString(model.Password);

                    dbContext.Users.Add(db);
                    dbContext.SaveChanges();
                }
                ViewBag.Message = "User Details Saved";
                return(View("Register"));
            }
            else
            {
                return(View("Register", model));
            }
        }
Ejemplo n.º 2
0
        public ActionResult ResetPassword(ResetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                using (var dbContext = new SWE4713Entities())
                {
                    Models.User userdb = (from s in dbContext.Users
                                          where s.Email == model.Email
                                          select s).FirstOrDefault <User>();
                    var oldPassword = userdb.Password;

                    PasswordHistory phistory = new PasswordHistory();

                    phistory.OldPassword = oldPassword;
                    phistory.DateCreated = DateTime.Now;
                    phistory.Active      = true;
                    phistory.UserId      = userdb.UserId;
                    dbContext.PasswordHistories.Add(phistory);
                    dbContext.SaveChanges();

                    var usr = dbContext.Users.SingleOrDefault(b => b.Email == model.Email);
                    if (usr != null)
                    {
                        usr.Attempts    = 0;
                        usr.DateUpdated = DateTime.Now;
                        dbContext.SaveChanges();
                    }

                    ResetLoginFailure(model.Email);
                }
                return(View("ResetPasswordConfirmation", "Account"));
            }
            else
            {
                return(View("ResetPasswordConfirmation", model));
            }
        }
Ejemplo n.º 3
0
        private bool ResetLoginFailure(string email)
        {
            bool result = false;

            using (var dbContext = new SWE4713Entities())
            {
                var usr = dbContext.Users.SingleOrDefault(b => b.Email == email);
                if (usr != null)
                {
                    usr.Attempts = 0;
                    dbContext.SaveChanges();
                    result = true;
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        private bool IncrementLoginFailure(string username)
        {
            bool result = false;

            using (var dbContext = new SWE4713Entities())
            {
                var usr = dbContext.Users.SingleOrDefault(b => b.UserName == username);
                if (usr != null)
                {
                    var loginAttempts = usr.Attempts;
                    if (loginAttempts < 3)
                    {
                        usr.Attempts += 1;
                        dbContext.SaveChanges();
                        result = true;
                    }
                }
            }
            return(result);
        }