예제 #1
0
        public async Task <ActionResult> Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var authProxy = new AuthenticationProxy(WebConfigurationManager.AppSettings["WebApiUrl"], "/api/oauth");

            var token = await authProxy.Login(model.UserName, model.Password);

            if (token == null)
            {
                ModelState.AddModelError("password", "Wachtwoord of gebruikersnaam is onjuist");
                return(View());
            }

            var tokenCookie = new HttpCookie("token", token.Value)
            {
                Expires  = DateTime.Now.AddMinutes(token.ExpiresIn),
                HttpOnly = true
            };

            Response.Cookies.Add(tokenCookie);

            return(RedirectToAction("Index", "Dashboard"));
        }
예제 #2
0
        public async Task <ActionResult> Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var authProxy = new AuthenticationProxy(MvcApplication.GetApiUrl(), "/api/oauth");

            var token = await authProxy.Login(model.UserName, model.Password);

            if (token == null)
            {
                ModelState.AddModelError("password", ErrorMessages.IncorrectLogin);
                return(View());
            }

            var tokenCookie = new HttpCookie("token", token.Value)
            {
                Expires  = DateTime.Now.AddSeconds(token.ExpiresIn),
                HttpOnly = false
            };

            var roleCookie = new HttpCookie("role", token.Role)
            {
                Expires  = DateTime.Now.AddSeconds(token.ExpiresIn),
                HttpOnly = true
            };

            Response.Cookies.Add(tokenCookie);
            Response.Cookies.Add(roleCookie);

            return(RedirectToAction("Index", "Dashboard"));
        }