Example #1
0
 public IActionResult Login(LoginVM login)
 {
     try
     {
         if (TokenMiddleware.Login == login.Username && TokenMiddleware.Password == login.Password)
         {
             var options = new CookieOptions
             {
                 Expires = DateTimeOffset.MaxValue
             };
             Response.Cookies.Append(TokenMiddleware._key, TokenMiddleware.GetMD5Hash(login.Username, login.Password), options);
             return(Json(new { Success = true }));
         }
         return(new ObjectResult(new { Success = false, Message = "Incorrect credentials!" }));
     }
     catch (Exception ex)
     {
         return(new ObjectResult(new { Success = false, Message = "Error", Details = $"{ex.Message}\n{ex.StackTrace}" }));
     }
 }
        public static void Register(HttpConfiguration config)
        {
            // Конфигурация и службы веб-APIК

            // Маршруты веб-API
            config.MapHttpAttributeRoutes();

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.EntitySet <Comment>("Comments");
            builder.EntitySet <Token>("Tokens");
            var session    = (IToken)config.DependencyResolver.GetService(typeof(IToken));
            var middleware = new TokenMiddleware(session);

            config.MessageHandlers.Add(middleware);

            config.Routes.MapODataServiceRoute("odata", "odata", builder.GetEdmModel());

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }