public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext) { //base.OnAuthorization(actionContext); var headers = actionContext.Request.Headers; if (actionContext.Request.Headers.Authorization == null) { PutUnauthorizedResult(actionContext, "No hay autorización"); } else { try { var userPwd = Encoding.UTF8.GetString(Convert.FromBase64String(headers.Authorization.Parameter)); var credArray = userPwd.Split(":".ToCharArray()); var userName = credArray[0]; var password = credArray[1]; if (Ion_Auth.Login(userName, password) == false) { PutUnauthorizedResult(actionContext, "No existe usuario"); } } catch (Exception ex) { PutUnauthorizedResult(actionContext, ex.Message); } } }
public ActionResult Login(string user = "", string pass = "", string ReturnUrl = "") { if (Ion_Auth.Login(user, pass) == true) { FormsAuthentication.SetAuthCookie(user, false); return(Redirect(ReturnUrl == null?ReturnUrl:"/")); } ViewBag.ReturnUrl = ReturnUrl; return(View()); }
public ActionResult Index(string user = "", string pass = "", string ReturnUrl = "/", string App = "") { if (Ion_Auth.Login(user, pass) == true) { if (App == "") { App = "RK"; } string url = ""; FormsAuthenticationTicket authticket = new FormsAuthenticationTicket(1, user, DateTime.Now, DateTime.Now.AddMinutes(40), true, user, FormsAuthentication.FormsCookiePath); // Encrypt the ticket. string encTicket = FormsAuthentication.Encrypt(authticket); // Create the cookie. Response.Cookies.Add(new HttpCookie(".APP" + App, encTicket)); switch (App) { case "COBAVIAT": case "COVECO": url = Settings.Get("app_" + App.ToLower()) + ReturnUrl; break; default: url = ReturnUrl; break; } return(Redirect(url)); } ViewBag.App = App; ViewBag.ReturnUrl = ReturnUrl; return(View()); }