public IActionResult UserReg(User NewUser, string ConfirmPassword)
        {
            if (NewUser.Password != ConfirmPassword)
            {
                return(View("Index"));
            }
            if (ModelState.IsValid)
            {
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                NewUser.Password = Hasher.HashPassword(NewUser, NewUser.Password);
                _context.Add(NewUser);
                _context.SaveChanges();

                User LoggedIn = _context.users.Last();
                HttpContext.Session.SetString("UserName", LoggedIn.Name);
                HttpContext.Session.SetInt32("UserId", LoggedIn.UserId);
                HttpContext.Session.SetString("Alias", LoggedIn.Alias);

                return(RedirectToAction("Success"));
            }
            else
            {
                return(View("Index"));
            }
        }
示例#2
0
 public IActionResult addUser(UserViewModel user)
 {
     if (ModelState.IsValid)
     {
         User newUser = new User
         {
             name     = user.name,
             alias    = user.alias,
             email    = user.email,
             password = user.password
         };
         _context.Add(newUser);
         _context.SaveChanges();
         User checkUser = _context.users.SingleOrDefault(users => user.email == users.email);
         HttpContext.Session.SetInt32("userid", checkUser.userid);
         int?userid = HttpContext.Session.GetInt32("userid");
         return(RedirectToAction("bright"));
     }
     else
     {
         return(View("Index"));
     }
 }
示例#3
0
 public IActionResult Register(UserViewModel user)
 {
     if (ModelState.IsValid)
     {
         string UserEmail  = user.email;
         User   LookupUser = _context.Users.SingleOrDefault(login => login.email == UserEmail);
         if (LookupUser == null)
         {
             PasswordHasher <UserViewModel> Hasher = new PasswordHasher <UserViewModel>();
             user.password = Hasher.HashPassword(user, user.password);
             User NewUser = new User
             {
                 name       = user.name,
                 alias      = user.alias,
                 email      = user.email,
                 password   = user.password,
                 created_at = DateTime.Now,
                 updated_at = DateTime.Now
             };
             _context.Add(NewUser);
             _context.SaveChanges();
             NewUser = _context.Users.SingleOrDefault(login => login.email == UserEmail);
             HttpContext.Session.SetInt32("userid", NewUser.userid);
             HttpContext.Session.SetString("alias", NewUser.alias);
             return(RedirectToAction("Success"));
         }
         else
         {
             ModelState.AddModelError("email", "This Email is already registered.");
             ViewBag.errors = ModelState.Values;
             return(View("~/Views/User/Main.cshtml", user));
         }
     }
     else
     {
         return(View("~/Views/User/Main.cshtml", user));
     }
 }