示例#1
0
 public IActionResult Register(User user)
 {
     if (ModelState.IsValid)
     {
         if (dbContext.Users.Any(u => u.Email == user.Email))
         {
             ModelState.AddModelError("Email", "Email already in use!");
             return(View("Index"));
         }
         else
         {
             PasswordHasher <User> Hasher = new PasswordHasher <User>();
             user.Password = Hasher.HashPassword(user, user.Password);
             dbContext.Add(user);
             dbContext.SaveChanges();
             HttpContext.Session.SetInt32("UserId", user.UserId);
             return(RedirectToAction("Wall"));
         }
     }
     else
     {
         return(View("Index"));
     }
 }
示例#2
0
        public IActionResult Register(ViewModel submission)
        {
            Users newUser = submission.Register;

            if (ModelState.IsValid)
            {
                PasswordHasher <Users> HashedPW = new PasswordHasher <Users>();
                newUser.Password = HashedPW.HashPassword(newUser, newUser.Password);

                dbContext.Add(newUser);
                dbContext.SaveChanges();

                HttpContext.Session.SetInt32("UserId", newUser.UserId);
                return(RedirectToAction("Show", "Messages"));
            }
            return(View("Index"));
        }