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)); }
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)); }
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)); }