Beispiel #1
0
 public IActionResult Login(Models.Requests.NewToken newTokenRequest)
 {
     if (Request.Method == "GET")
     {
         ViewData["service"] = newTokenRequest.Service;
         ViewData["error"]   = newTokenRequest.err;
         return(View());
     }
     else if (Request.Method == "POST")
     {
         try
         {
             NewTokenRequestHandler handler = new NewTokenRequestHandler(newTokenRequest);
             if (handler.VerifyUser())
             {
                 return(Redirect(newTokenRequest.Service + "?jwt=" + HttpUtility.UrlEncode(handler.GenerateJWT())));
             }
             else
             {
                 return(Redirect("/Login?service=" + newTokenRequest.Service + "&err=LoginFailed"));
             }
         }catch (Exception E)
         {
             Logger.LogError("Got exception while handling new token request: " + E.ToString());
             return(StatusCode(500));
         }
     }
     else
     {
         return(StatusCode(422));
     }
 }
        public string Get()
        {
            NewTokenRequestHandler handler = new NewTokenRequestHandler(new Models.Requests.NewToken {
                Username = "******",
                Password = "******",
            });

            if (handler.VerifyUser())
            {
                return(handler.GenerateJWT());
            }
            else
            {
                return("Invalid Credentials");
            }
        }