Esempio n. 1
0
        public IActionResult AddUser(UsersValidate uservalidator)
        {
            if (ModelState.IsValid)
            {
                var emailvalidation = _context.users.SingleOrDefault(p => p.email == uservalidator.email);
                if (emailvalidation == null)
                {
                    PasswordHasher <UsersValidate> Hasher = new PasswordHasher <UsersValidate>();
                    uservalidator.password = Hasher.HashPassword(uservalidator, uservalidator.password);
                    Users myUser = new Users();
                    myUser.first_name = uservalidator.first_name;
                    myUser.last_name  = uservalidator.last_name;
                    myUser.email      = uservalidator.email;
                    myUser.password   = uservalidator.password;
                    myUser.created_at = DateTime.Now;
                    myUser.updated_at = DateTime.Now;
                    _context.Add(myUser);
                    _context.SaveChanges();

                    HttpContext.Session.SetInt32("UserID", myUser.id);
                    int?UserID = HttpContext.Session.GetInt32("UserID");
                    ViewBag.UserID = UserID;
                    return(RedirectToAction("Dashboard"));
                }
                else
                {
                    TempData["uniqueemail"] = "This email belongs to a registered user. Please use another email address";
                    return(View("Index"));
                }
            }
            else
            {
                return(View("Index"));
            }
        }
Esempio n. 2
0
 public IActionResult Register(UserViewModel FormUser)
 {
     if (ModelState.IsValid)
     {
         User NewUser = new User {
             FirstName = FormUser.FirstName,
             LastName  = FormUser.LastName,
             Email     = FormUser.Email,
             Password  = FormUser.Password
         };
         _context.Add(NewUser);
         _context.SaveChanges();
         User results = _context.Users.SingleOrDefault(user => (user.Email == FormUser.Email && user.Password == FormUser.Password));
         int  id      = results.UserID;
         HttpContext.Session.SetInt32("logged_id", id);
         return(RedirectToAction("ShowDashboard", "Activity"));
     }
     return(View("LoginReg"));
 }