Ejemplo n.º 1
0
        public ActionResult Login()
        {
            string username = Request.Form["userName"];
            string password = Request.Form["password"];

            if (username == "" || password == "")
            {
                ViewBag.ErrorMessage = "Please enter a username";
                return(View("LoginPage"));
            }
            else if (!ERUser.Exists(username))
            {
                ViewBag.ErrorMessage = "Please enter a valid username.";
                return(View("LoginPage"));
            }
            else
            {
                ERUser user = ERUser.Get(username);

                if (user.ValidatePassword(password))
                {
                    Response.Cookies.Append("username", username);
                    return(Redirect("/"));
                }
                else
                {
                    ViewBag.ErrorMessage = "Incorrect username or password.";
                    return(View("LoginPage"));
                }
            }
        }
Ejemplo n.º 2
0
        public static void SetLoginData(Microsoft.AspNetCore.Http.HttpRequest request, dynamic viewbag)
        {
            viewbag.showLoginInfo = true;
            string username = request.Cookies["username"];

            if (ERUser.Exists(username))
            {
                viewbag.user       = ERUser.Get(username);
                viewbag.isLoggedIn = true;
            }
            else
            {
                viewbag.user       = null;
                viewbag.isLoggedIn = false;
            }
        }