예제 #1
0
        public IActionResult PostCheckUser(User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data"));
            }

            var match = _context.Users.Where(u => u.Email == user.Email).ToList();

            if (match.Count == 1)
            {
                if (PasswordSecurity.CheckPassword(match[0].Password, user.Password))
                {
                    return(Ok(new UserDTO(match[0].UserId, match[0].Name, match[0].Score)));
                }
            }
            return(BadRequest("Wrong email or password"));
        }
예제 #2
0
        public ActionResult Register([Bind(Include = "UserID,FirstName,LastName,EmailAddress,Password,Remember,College")] User user)
        {
            var userr = db.Users.Where(x => x.EmailAddress == user.EmailAddress).FirstOrDefault();

            try
            {
                if (userr == null)
                {
                    if (PasswordSecurity.CheckPassword(user.Password))
                    {
                        if (ModelState.IsValid)
                        {
                            user.Password = PasswordSecurity.HashPassword(user.Password);
                            user.RolaID   = 2;
                            db.Users.Add(user);
                            db.SaveChanges();

                            return(RedirectToAction("Login", user));
                        }
                    }
                    else
                    {
                        TempData["Error"] = "<script>alert('The password must have minimum 7 letter, one special char, one number, one upper and lower case letter!');</script>";
                        //Content("<script language='javascript' type='text/javascript'>alert('Your Password had to: minimum 7 letter, one special char, one number, one upper and lower case letter!');</script>");
                    }
                }
                else
                {
                    ViewBag.Error = "Email exist in databse";
                }
            }
            catch (Exception e)
            {
                ViewBag.Error = e;
            }
            return(View("Register", new User()));
        }