Esempio n. 1
0
        public IActionResult Login(logRegCompositeModel incoming)
        {
            loginViewModel loginData = incoming.login;

            TryValidateModel(loginData);
            if (ModelState.IsValid)
            {
                Users user = _context.users.FirstOrDefault(entry => entry.alias == loginData.alias);
                if (user != null)
                {
                    PasswordHasher <Users> hasher = new PasswordHasher <Users>();
                    if (hasher.VerifyHashedPassword(user, user.password, loginData.password) != 0)
                    {
                        HttpContext.Session.SetInt32("currentUserId", user.usersId);
                        return(RedirectToAction("list", "Idea"));
                    }
                }
            }
            return(RedirectToAction("Main"));
        }
Esempio n. 2
0
        public IActionResult Register(logRegCompositeModel incoming)
        {
            RegistrationViewModel registrationData = incoming.registration;

            TryValidateModel(registrationData);
            if (ModelState.IsValid)
            {
                Users newUser = new Users();
                PasswordHasher <Users> hasher = new PasswordHasher <Users>();
                newUser.name     = registrationData.name;
                newUser.alias    = registrationData.alias;
                newUser.email    = registrationData.email;
                newUser.password = hasher.HashPassword(newUser, registrationData.password);
                _context.users.Add(newUser);
                _context.SaveChanges();
                System.Console.WriteLine("registration validates");
            }
            else
            {
                System.Console.WriteLine("no validation here");
            }
            return(RedirectToAction("Main"));
        }