Beispiel #1
0
 public ActionResult Register(RegisterModel model)
 {
     if (ModelState.IsValid)
     {
         UserProcessor userProcessor = new UserProcessor();
         if (userProcessor.CreateUser(model))
         {
             return RedirectToAction("Index", "Home");
         }
         else
         {
             return View(model);
         }
     }
     else
         return View(model);
 }
Beispiel #2
0
        public bool CreateUser(RegisterModel model)
        {
            using (DataBaseContext dataBaseContext = new DataBaseContext())
            {
                if (dataBaseContext.Users.ToList().Any(it => (it.UserName.ToLower().Equals(model.UserName.ToLower()) &&
                                                             it.UserSurname.ToLower().Equals(model.UserSurname.ToLower())) ||
                                                             it.Email.ToLower().Equals(model.ToString().ToLower())))
                {
                    return false;
                }
                try
                {
                    Hasher hasher = new Hasher();
                    string salt = hasher.GetSalt();
                    dataBaseContext.Users.Add(new User()
                    {
                        UserName = model.UserName,
                        UserSurname = model.UserSurname,
                        Email = model.Email,
                        Salt = salt,
                        Password = hasher.GetHashString(hasher.GetHashString(model.Password)/* + salt*/),
                        Gender = model.Gender,
                        Birthday = model.Birthday,
                        MaritalStatus = model.MaritalStatus,
                        ListOfInterests = model.ListOfInterests
                    });
                    dataBaseContext.SaveChanges();
                }
                catch (Exception)
                {

                    return false;
                }

                return true;
            }
        }