private JsonResult CreateResultJson(UserViewModel viewModel) { if (_service.ExistedName(viewModel.Entity.UserName)) { return(Json(new { result = Constants.Duplicate })); } if (_service.ExistedEmail(viewModel.Entity.Email)) { return(Json(new { result = Constants.DuplicateEmail })); } try { viewModel.Entity.Enable = true; viewModel.Entity.Password = UserCommon.CreateHash(viewModel.Entity.Password); viewModel.Entity.CreatedBy = viewModel.LoginId; viewModel.Entity.Created = DateTime.Now; _service.Insert(viewModel.Entity); return(Json(new { result = Constants.Success })); } catch (Exception e) { Log.Error("Create New User!", e); return(Json(new { result = Constants.UnSuccess })); } }
public void UpdateHashPassword() { // get users var users = _userepository.GetAll(); foreach (var xUser in users) { xUser.Password = UserCommon.CreateHash(xUser.PasswordOrginal.Trim()); _userepository.Update(xUser); } _unitOfWork.CommitChanges(); }
public bool CheckUser(string user, string password) { var userS = _customUserRepository.CheckUser(user.ToLower()); if (userS == null) { return(false); } var hashedPassword = UserCommon.CreateHash(password); return(hashedPassword.Equals(userS.Password)); }
public ActionResult ChangePassword(int userCode, string newPassword, string currentPassword) { var user = _service.GetByKey(userCode); if (user.Password != UserCommon.CreateHash(currentPassword)) { return(Json(new { result = Constants.UnSuccess })); } user.Password = UserCommon.CreateHash(newPassword); user.ModifiedBy = user.Id; user.Modified = DateTime.Now; _service.Update(user); return(Json(new { result = Constants.Success })); }
public ActionResult ForgotPassword(string user, string email) { var userItem = _service.GetByName(user); if (userItem.Email != email.Trim()) { return(Json(new { result = Constants.UnSuccess })); } var newPassword = userItem.Password + DateTime.Now.ToString("ddMMyyyyHHmmss"); // 1. Add new password to this user userItem.Password = UserCommon.CreateHash(newPassword); userItem.ModifiedBy = userItem.Id; userItem.Modified = DateTime.Now; _service.Update(userItem); // 2. Send mail with new password. try { var mMess = new MailMessage { From = new MailAddress(WebConfigurationManager.AppSettings["Email"]) }; mMess.To.Add(new MailAddress(email)); mMess.Subject = "[IT] New Password On Vivablast WareHouse System."; mMess.IsBodyHtml = true; mMess.Body = GetHtmlContent(ControllerContext, new ViewDataDictionary { { "Name", userItem.UserName }, { "Password", newPassword } }, "EmailTemplate"); var smClt = new SmtpClient { EnableSsl = true }; smClt.Send(mMess); return(Json(new { result = Constants.Success })); } catch (Exception ex) { return(Json(new { result = ex })); } }
private JsonResult EditResultJson(UserViewModel viewModel) { if (viewModel.CheckName != viewModel.Entity.UserName) { if (_service.ExistedName(viewModel.Entity.UserName)) { return(Json(new { result = Constants.Duplicate })); } } if (viewModel.EmailCurrent != viewModel.Entity.Email) { if (_service.ExistedEmail(viewModel.Entity.Email)) { return(Json(new { result = Constants.DuplicateEmail })); } } var user = _service.GetByKey(viewModel.Entity.Id); if (!Convert.ToBase64String(viewModel.Entity.Timestamp).Equals(Convert.ToBase64String(user.Timestamp))) { return(Json(new { result = Constants.DataJustChanged })); } try { //user.Id = viewModel.Entity.Id; user.UserName = viewModel.Entity.UserName; user.FirstName = viewModel.Entity.FirstName; user.LastName = viewModel.Entity.LastName; user.DepartmentId = viewModel.Entity.DepartmentId; user.Department = viewModel.Entity.Department; user.Telephone = viewModel.Entity.Telephone; user.Mobile = viewModel.Entity.Mobile; user.Email = viewModel.Entity.Email; //user.Enable = viewModel.Entity.Enable; user.Password = !string.IsNullOrEmpty(viewModel.Entity.Password) ? UserCommon.CreateHash(viewModel.Entity.Password) : viewModel.PasswordCurrent; user.StoreId = viewModel.Entity.StoreId; user.Store = viewModel.Entity.Store; //user.CreatedBy = viewModel.Entity.CreatedBy; //user.Created = viewModel.Entity.Created; user.UserR = viewModel.Entity.UserR; user.ProjectR = viewModel.Entity.ProjectR; user.StoreR = viewModel.Entity.StoreR; user.StockR = viewModel.Entity.StockR; user.RequisitionR = viewModel.Entity.RequisitionR; user.StockOutR = viewModel.Entity.StockOutR; user.StockReturnR = viewModel.Entity.StockReturnR; user.StockInR = viewModel.Entity.StockInR; user.ReActiveStockR = viewModel.Entity.ReActiveStockR; user.StockTypeR = viewModel.Entity.StockTypeR; user.CategoryR = viewModel.Entity.CategoryR; user.PER = viewModel.Entity.PER; user.SupplierR = viewModel.Entity.SupplierR; user.PriceR = viewModel.Entity.PriceR; user.StockServiceR = viewModel.Entity.StockServiceR; user.AccountingR = viewModel.Entity.AccountingR; user.MaintenanceR = viewModel.Entity.MaintenanceR; user.WorkerR = viewModel.Entity.WorkerR; user.ShippmentR = viewModel.Entity.ShippmentR; user.ReturnSupplierR = viewModel.Entity.ReturnSupplierR; //user.Password = user.ModifiedBy = viewModel.LoginId; user.Modified = DateTime.Now; _service.Update(user); return(Json(new { result = Constants.Success })); } catch (Exception e) { Log.Error("Update User!", e); return(Json(new { result = Constants.UnSuccess })); } }