public ActionResult Login(LoginModel model) { var url = Request.Url; if (ModelState.IsValid) { if (model.Username != null && model.Password != null) { //string verifier = Crypto.Hash(model.Password,"sha256").Remove(32); string verifier = UtilitiesHelper.Encrypt(model.Password); rs_user loginUser = db.rs_user.FirstOrDefault(m => m.Username == model.Username && m.Password == verifier && m.FlagActive == true && m.IsBackEnd == true); if (loginUser != null) { //FormsAuthentication.SetAuthCookie(loginUser.Username, false); string userData = (loginUser.GroupId == null) ? "0" : loginUser.GroupId.ToString(); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, loginUser.Username, DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes), false, userData); // Encrypt the ticket. string encTicket = FormsAuthentication.Encrypt(ticket); // Create the cookie. Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); //FormsAuthentication.SetAuthCookie(model.Username, true); Logger.Username = model.Username; Logger.Log("Login", "Logged in with user [" + model.Username + "]"); return(RedirectToAction("Index")); } else { Logger.Username = model.Username; Logger.Log("Login", "Failed to login, user [" + model.Username + "]"); TempData["Notification"] = NotificationHelper.Error("Username and Password is incorrect"); } } else { TempData["Notification"] = NotificationHelper.Warning("Please provide correct Username and Password"); } } return(View(model)); }
public ActionResult Create(rs_user rs_user) { if (AclHelper.hasAccess(User, currentAction, currentController)) { if (ModelState.IsValid) { rs_user current = db.rs_user.SingleOrDefault(m => m.Username == rs_user.Username); if (current != null) { TempData["Notification"] = NotificationHelper.Error("Username '" + rs_user.Username + "' already exist."); } else { try { rs_user.Password = UtilitiesHelper.Encrypt(rs_user.Password); rs_user.IsBackEnd = true; rs_user.UserEntry = User.Identity.Name; rs_user.DateEntry = DateTime.Now; db.rs_user.Add(rs_user); db.SaveChanges(); Logger.Log("Add", "New User [Username: "******"]"); TempData["Notification"] = NotificationHelper.Inform("New User [Username: "******"]"); return(RedirectToAction("Index")); } catch (Exception ex) { TempData["Notification"] = NotificationHelper.Error(ex.Message); } } } //ViewBag.CompanyId = new SelectList(db.rs_company.Where(c => c.FlagActive == true).OrderBy(c => c.Name), "CompanyId", "Name", rs_user.CompanyId); ViewBag.GroupId = new SelectList(db.rs_user_group.Where(g => g.FlagActive == true).OrderBy(g => g.Name), "GroupId", "Name", rs_user.GroupId); return(View(rs_user)); } else { return(RedirectToAction("NotAuthenticated", "Home")); } }
public ActionResult Index(ChangePasswordModel cp) { rs_user rs_user = new rs_user(); try { string CurrentPassword = db.rs_user.Where(m => m.Username == User.Identity.Name).Single().Password; if (ModelState.IsValid) { //if (Crypto.Hash(cp.OldPassword).Remove(32) == CurrentPassword) if (UtilitiesHelper.Encrypt(cp.OldPassword) == CurrentPassword) { rs_user baru = new rs_user(); baru = db.rs_user.Where(m => m.Username == User.Identity.Name).Single(); //baru.Password = Crypto.Hash(cp.NewPassword).Remove(32); baru.Password = UtilitiesHelper.Encrypt(cp.NewPassword); db.Entry(baru).State = EntityState.Modified; db.SaveChanges(); Logger.Log("Change Password", "User Change Password [" + baru.Username + "]"); TempData["Notification"] = NotificationHelper.Inform("You have successfully changed your password."); } else { TempData["Notification"] = NotificationHelper.Error("Incorrect old password!"); } } } catch (Exception) { TempData["Notification"] = NotificationHelper.Error("Change password failed!"); } return(View(cp)); }
public ActionResult Reset(rs_user rs_user) { if (AclHelper.hasAccess(User, currentAction, currentController)) { try { rs_user baru = new rs_user(); baru = db.rs_user.Where(m => m.UserId == rs_user.UserId).Single(); //baru.Password = Crypto.Hash("123456", "sha256").Remove(32); baru.Password = UtilitiesHelper.Encrypt("123456"); baru.UserUpdate = User.Identity.Name; baru.DateUpdate = DateTime.Now; db.Entry(baru).State = EntityState.Modified; db.SaveChanges(); //db.rs_user.ApplyCurrentValues(baru); //db.SaveChanges(); //db.rs_user.Attach(baru); //db.ObjectStateManager.ChangeObjectState(baru, EntityState.Modified); //db.SaveChanges(); Logger.Log("Reset", "Reset User Password [Username:"******"]"); TempData["Notification"] = NotificationHelper.Inform("Reset User Password [Username:"******"]"); } catch (Exception ex) { TempData["Notification"] = NotificationHelper.Error(ex.Message); } return(RedirectToAction("Index")); } else { return(RedirectToAction("NotAuthenticated", "Home")); } }
public ActionResult Upload(HttpPostedFileBase file) { if (AclHelper.hasAccess(User, currentAction, currentController)) { if (file != null && file.ContentLength > 0) { if (Path.GetExtension(file.FileName).ToLower() != ".xls") { TempData["Notification"] = NotificationHelper.Error("Only XLS files are supported."); } else { try { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/Uploads"), fileName); file.SaveAs(path); DateTime start_time = DateTime.Now; ParserInfoHelper PI_Helper = new ParserInfoHelper(); int recordProcessed = 0; int recordWarning = 0; int recordInserted = 0; int recordError = 0; string Summary = string.Empty; Summary += "Filename : " + fileName + "<br><br>"; ExcelHelper helper = new ExcelHelper(); ArrayList data = helper.Parser(path, new String[] { "User", "1", "1", User.Identity.Name, DateTime.Now.ToString("dd-mm-yyyy HH:mm:ss") }, "Sheet1"); foreach (ArrayList row in data) { row[1] = UtilitiesHelper.Encrypt(row[1].ToString()); } int totalRows = data.Count; if (totalRows > 0) { helper.RowProcessed += (s, t) => recordProcessed += 1; helper.RowInserted += (s, t) => { recordInserted += 1; PI_Helper.AddInfo(t.Message); }; helper.RowWarning += (s, t) => { recordWarning += 1; PI_Helper.AddWarning(t.Message); }; helper.RowError += (s, t) => { recordError += 1; PI_Helper.AddError(t.Message); }; helper.Import(data, "rs_user", new string[] { "Username", "Password", "FullName", "UserType", "IsBackEnd", "FlagActive", "UserEntry", "DateEntry" }, null, new List <string>(new string[] { "1" })); } Summary += "Record Processed : " + recordProcessed + "<br>"; Summary += "Record Inserted : " + recordInserted + "<br>"; Summary += "Record Error : " + recordError + "<br>"; Summary += "Record Warning : " + recordWarning + "<br><br>"; Summary += "Elapsed Time: " + DateTime.Now.Subtract(start_time).Minutes + " minutes"; PI_Helper.Summary = Summary; Logger.Log("Upload", "User upload successful."); TempData["Notification"] = PI_Helper.Display(); return(RedirectToAction("Index")); } catch (Exception ex) { TempData["Notification"] = NotificationHelper.Error(ex.Message); } } } else { TempData["Notification"] = NotificationHelper.Error("No file is selected."); } return(View()); } else { return(RedirectToAction("NotAuthenticated", "Home")); } }