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

            var loginResult = AuthProviderHost.PrimaryAuthProvider.Authenticate(model.Username, model.Password);

            if (loginResult.StatusCode == HttpStatusCode.Unauthorized)
            {
                model.ErrorMessages.Add("Incorrect Username or Password");
                return(View(model));
            }

            if (loginResult.StatusCode != HttpStatusCode.OK)
            {
                model.ErrorMessages.Add("Error connecting to API");
                return(View(model));
            }

            if (!string.IsNullOrWhiteSpace(loginResult.Token))
            {
                JwtCookieManager.SetCookie(loginResult.Token);
                return(RedirectToAction("Index", "Home", null));
            }

            return(View(model));
        }
예제 #2
0
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var    newUser = new object(); // attempt the login here
                string token   = "jwt here";

                if (newUser != null)
                {
                    JwtCookieManager.SetCookie(token);
                    return(RedirectToAction("Index", "Home", null));
                }
            }

            return(View(model));
        }
예제 #3
0
        public ActionResult Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            RestClient authClient  = new RestClient(ConfigurationManager.AppSettings["Ace.Api"]);
            var        authRequest = new RestRequest("/Account/Authenticate", Method.POST);

            authRequest.AddJsonBody(new { model.Username, model.Password });
            var authResponse = authClient.Execute(authRequest);

            if (authResponse.StatusCode == HttpStatusCode.Unauthorized)
            {
                model.ErrorMessage = "Incorrect Username or Password";
                return(View(model));
            }
            else if (authResponse.StatusCode != HttpStatusCode.OK)
            {
                model.ErrorMessage = "Error connecting to API";
                return(View(model));
            }

            // else we got an OK response
            JObject response  = JObject.Parse(authResponse.Content);
            var     authToken = (string)response.SelectToken("authToken");

            if (!string.IsNullOrWhiteSpace(authToken))
            {
                JwtCookieManager.SetCookie(authToken);
                return(RedirectToAction("Index", "Home", null));
            }

            return(View(model));
        }
예제 #4
0
 public ActionResult LogOff()
 {
     JwtCookieManager.SignOut();
     return(RedirectToAction("Index", "Home", null));
 }
예제 #5
0
 public ActionResult LogOff()
 {
     JwtCookieManager.SignOut();
     BaseController.CurrentUser = null;
     return(RedirectToAction("Index", "Home", null));
 }
예제 #6
0
        public ActionResult Index()
        {
            var account = AuthProviderHost.PrimaryAuthProvider.GetAccount(GetUserToken(), JwtCookieManager.GetUserGuid(GetUserToken()));

            return(View(account));
        }
예제 #7
0
 public string GetUserGuid()
 {
     return(JwtCookieManager.GetUserGuid(GetUserToken()));
 }