public ActionResult LogIn(LogInModel model, string returnUrl) { if (ModelState.IsValid) { //call the service to check the username and password bool validateUser = new UserServ.WCFUserClient().LogIn(model.Username,model.PasswordToken); if (validateUser) { //works but dont understand yet FormsAuthentication.SetAuthCookie(model.Username,true); // if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Home", "Product"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return View(model); }
public PartialViewResult FaultLogIn(LogInModel model, string returnUrl) { if (ModelState.IsValid) { //call the service to check the username and password bool validateUser = new UserServ.WCFUserClient().LogIn(model.Username, model.PasswordToken); if (validateUser) { FormsAuthentication.SetAuthCookie(model.Username, true); return PartialView("_FaultDetails"); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } return PartialView("_FaultLogIn",model); }
public ActionResult LogIn(LogInModel model, string returnUrl) { if (ModelState.IsValid) { //call the service to check the username and password bool validateUser = new UserServ.WCFUserClient().LogIn(model.Username,model.PasswordToken); if (validateUser) { //works but dont understand yet //FormsAuthentication.SetAuthCookie(model.Username,true); List<UserType> userTypes = new WCFUserClient().GetUserUserType(model.Username).ToList(); string roles = ""; foreach (UserType u in userTypes) { if (roles != "") { roles = roles + "," + u.Name; } else { roles = u.Name; } } FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, model.Username, //user id DateTime.Now, DateTime.Now.AddMinutes(20), // expiry true, //do not remember roles, "/"); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket)); Response.Cookies.Add(cookie); // if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Home", "Product"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult FaultLogIn(LogInModel model, string returnUrl) { //Get 6 Digit Ticket string code = new WCFBAFuncClient().GenerateRandomTicket(6); //Check if ticket is filled if (code != null) { if (ModelState.IsValid) { //Authorise the user //call the service to check the username and password bool validateUser = new UserServ.WCFUserClient().LogIn(model.Username, model.PasswordToken); if (validateUser) { FormsAuthentication.SetAuthCookie(model.Username, true); BarCode b = new BarCode(); MemoryStream ms = new MemoryStream(b.Code39(code, 100, false, code)); var img = System.Drawing.Image.FromStream(ms); string imgPath = Server.MapPath("\\Content\\Images\\" + code + ".jpg"); img.Save(imgPath); FaultModel fm = new FaultModel(); fm.BarCodeImg = "..\\Content\\Images\\" + code + ".jpg"; fm.Code = Convert.ToInt32(code); return RedirectToAction("FaultDetails", new { barcodeImg = fm.BarCodeImg, code=fm.Code }); //return PartialView("_FaultDetails", fm); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); return PartialView("_FaultLogIn", model); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); return PartialView("_FaultLogIn", model); } } else { return PartialView("_FaultLogIn",model); } }