public ActionResult Login(AccountModel.LoginModel model, string returnUrl) { if (ModelState.IsValid) { using (UsersRepository usersRepository = new UsersRepository()) { Users user = usersRepository.GetUserByLoginModel(model); if (user == null) { ModelState.AddModelError("LogOnError", "The user name or password provided is incorrect."); } else { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); Session["UserID"] = user.UserID; Session["MyMenu"] = null; if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(Redirect(returnUrl)); } else { //Redirect to default page return(RedirectToAction("RedirectToDefault")); } } } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult login(AccountModel.LoginModel login, string ReturnUrl) { ViewBag.returnUri = ReturnUrl == null ? "" : ReturnUrl; if (!ModelState.IsValid) { return(View(login)); } if (User.Identity.IsAuthenticated) { if (ReturnUrl != null) { return(Redirect(ReturnUrl)); } } UserApi userApi = new UserApi(); // var res = userApi.loginUser(login); if (true) { FormsAuthentication.SetAuthCookie(login.userName, false); RouteCollection collection = new RouteCollection(); var completeRoute = this.ControllerContext.RouteData.Route; test(); if (ReturnUrl != null) { var islocal = Url.IsLocalUrl(ReturnUrl); if (Url.IsLocalUrl(ReturnUrl)) { var ss = Server.UrlEncode(Request.UrlReferrer.PathAndQuery); return(Redirect(ReturnUrl)); } else { ModelState.AddModelError("username", "You are not allow to do that!"); return(RedirectToAction("Home", "Index")); } } ViewBag.loginMessage = "Login Success"; return(RedirectToAction("Home", "Index")); } else if ("Error".Contains("Error")) { ModelState.AddModelError("username", "Error : " + ""); } else { ModelState.AddModelError("username", "Username and Password didnt match."); } return(View()); }
public async Task <ActionResult> Index(AccountModel.LoginModel model, string returnUrl) { if (ModelState.IsValid) { Users user = await UserManager.FindAsync(model.username, model.password); if (user == null) { ModelState.AddModelError("", "Invalid username or password."); } else { ClaimsIdentity claimsidentity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); await SignInAsync(user, isPersistent : false); return(RedirectToLocal(returnUrl)); } } return(View(model)); }
public ActionResult Login(AccountModel.LoginModel model) { if (model.Account == "admin" && model.Password == "accuvally") { FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, model.Account, DateTime.UtcNow.AddHours(8), DateTime.UtcNow.AddHours(8).AddDays(3), true, model.Account, FormsAuthentication.FormsCookiePath); string encTicket = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); cookie.HttpOnly = true; Response.Cookies.Add(cookie); } return(RedirectToAction("Index", "FaceDetection")); }
public string loginUser(AccountModel.LoginModel loginModel) { try { Uri uri = new Uri(string.Format(apilist.appDict["login"] + loginModel.userName + "/" + loginModel.passWorld)); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.ProtocolVersion = HttpVersion.Version11; request.ContentType = "application/json"; request.ServerCertificateValidationCallback = delegate { return(true); }; using (var rsps = new StreamReader(request.GetResponse().GetResponseStream())) { return(rsps.ReadToEnd()); } } catch (Exception ee) { return("Error : " + ee.Message); } }