Пример #1
0
        public async Task<ActionResult> Login(LoginViewModel model)
        {
            var username = model.username;
            var password = model.password;
            try
            {
                var user = await ParseUser.LogInAsync(username, password);
                if (user != null)
                {
                    GetUser getUser = new GetUser();
                    var role = user.Get<string>("role");
                    roles.AddRange(await getUser.GetRoleOfUser(username));
                    Session["login"] = username;
                    FormsAuthentication.SetAuthCookie(username, false);
                    return RedirectToAction(role.ToString(), "DashBoard");
                }

                ViewBag.Message = "Login Failed";
                return View();
            }
            catch (ParseException nre)
            {
                ViewBag.Message = "Login Failed, cause: " + nre.Message;
                return View();
            }

        }
Пример #2
0
        public async Task<ActionResult> Login(LoginViewModel model)
        {
            var username = model.username;
            var password = model.password;
            try
            {
                var user = await ParseUser.LogInAsync(username, password);

                if (model.rememberMe)
                {
                    var authTicket = new FormsAuthenticationTicket(
                        1,
                        username,
                        DateTime.Now,
                        DateTime.Now.AddMinutes(20), // expiry
                        model.rememberMe,
                        "/"
                    );
                    HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket));
                    Response.Cookies.Add(cookie);
                }

                if (user != null)
                {
                    GetUser getUser = new GetUser();
                    var role = user.Get<string>("role");
                    roles.AddRange(await getUser.GetRoleOfUser(username));
                    Session["login"] = username;
                    FormsAuthentication.SetAuthCookie(username, false);
                    return RedirectToAction(role.ToString(), "DashBoard");
                }

                ViewBag.Message = "Login Failed";
                return View();
            }
            catch (ParseException nre)
            {
                ViewBag.Message = "Login Failed, cause: " + nre.Message;
                return View();
            }

        }