public async Task <ActionResult> ResetPassword(int id) { BL.UserInfo empBL = new BL.UserInfo(); if (empBL.GetItemByIdForDelete(id) != null) { return(Redirect(Url.Action("HttpError", "Error", new { area = "" }))); } IPasswordPolicy Password = new RandomPassword(); string orginalPassword = Password.GeneratePassword(); orginalPassword = "******"; string md5Password = HashEncrypt.MD5(orginalPassword); VM.UserInfoItem model = new VM.UserInfoItem(); model = empBL.GetItemById(id); //IdentityModel user = await UserManager.FindByNameAsync(model.LogonName); //string password = UserManager.PasswordHasher.HashPassword(md5Password); //UserStore store = new UserStore(UserHelper.GetCurrentUser().LogonName); //var set = store.SetPasswordHashAsync(user, password); //var result = store.UpdateAsync(user); model.Password = md5Password; empBL.UpdatePasswordDb(model); if (model != null) { // empBL.SendEmail(model, orginalPassword, "User_ResetPassword"); return(Json(true, JsonRequestBehavior.AllowGet)); } return(Json(false, JsonRequestBehavior.AllowGet)); }
//[AllowAnonymous] public async Task <ActionResult> UpdatePassword(VM.UserInfoUpdatePassword modelNew) { if (modelNew.UserId != Convert.ToInt32(UserHelper.GetCurrentUser().Id)) { return(Redirect(Url.Action("Index", "NoPermissions", new { area = "" }))); } BL.UserInfo empBL = new BL.UserInfo(); VM.UserInfoItem model = new VM.UserInfoItem(); // model.UserId = CommonMethod.getIntValue(UserHelper.GetCurrentUser().Id); model = empBL.GetItemById(model.UserId); IdentityModel user = await UserManager.FindByNameAsync(model.LogonName); //modelNew.Password = HashEncrypt.MD5(modelNew.Password); var results = await UserManager.CheckPasswordAsync(user, modelNew.Password); if (results) { //modelNew.NewPassword = HashEncrypt.MD5(modelNew.NewPassword); string password = UserManager.PasswordHasher.HashPassword(modelNew.NewPassword); UserStore store = new UserStore(UserHelper.GetCurrentUser().LogonName); var set = store.SetPasswordHashAsync(user, password); var result = store.UpdateAsync(user); if (user != null) { return(Content("Success")); } } else { return(Content("Error")); } return(Content("False")); }
// // GET: /SystemMaint/UserInfo/Details/5 // // GET: /SystemMaint/UserInfo/Create public ActionResult Create() { ViewBag.ShowSubmit = true; VM.UserInfoItem model = new VM.UserInfoItem(); model.StrStatus = "1"; model.RoleSelectList = GetRoleSelectList(model.RoleSelectList); //model.CompanySelectList = GetCompanySelectList(model.CompanySelectList); BL.UserInfo empBL = new BL.UserInfo(); // model.GasStationSelectList = empBL.GetAllGasStationSelectList(); return(View(model)); }
public bool UpdatePasswordDb(VM.UserInfoItem model) { MD.tbl_Common_User date = Ctx.tbl_Common_User.Where(c => c.UserId == model.UserId).FirstOrDefault(); date.Password = model.Password; date.UpdatedBy = model.UpdatedBy; date.UpdatedDate = DateTime.Now; Ctx.SaveChanges(); return(true); }
public bool Update(VM.UserInfoItem model) { MD.tbl_Common_User date = Ctx.tbl_Common_User.First(u => u.UserId == model.UserId); date.UserName = model.UserName; date.LogonName = model.LogonName; if (model.StrStatus.ToString() == UserStatus.Normal.strValue) { date.Status = UserStatus.Normal.intValue; } else { date.Status = UserStatus.Disable.intValue; } date.DomainAccount = model.DomainAccount; date.EmailAddress = model.EmailAddress; date.UpdatedBy = model.UpdatedBy; date.UpdatedDate = DateTime.Now; //Ctx.SaveChanges(); //修改公司关系 updateUserOfCompany(date.UserId, model.UserCompanyValue, model.UpdatedBy); //UpdateUserCompany(model.UserCompanyValue, date.UserId, model.UpdatedBy); Ctx.SaveChanges(); //修改 角色 if (Ctx.tbl_Common_RoleUser.Where(m => m.UserId == model.UserId).Count() == 0) { MD.tbl_Common_RoleUser roleUser = new MD.tbl_Common_RoleUser(); roleUser.RoleId = model.RoleId.Value; roleUser.UserId = date.UserId; roleUser.CreatedDate = DateTime.Now; roleUser.CreatedBy = model.UpdatedBy; //roleUser.UpdatedDate = DateTime.Now; //roleUser.UpdatedBy = model.UpdatedBy; Ctx.tbl_Common_RoleUser.Add(roleUser); Ctx.SaveChanges(); } else { MD.tbl_Common_RoleUser roleUser = Ctx.tbl_Common_RoleUser.First(m => m.UserId == model.UserId); roleUser.RoleId = model.RoleId.Value; roleUser.IsDeleted = false; roleUser.UpdatedDate = DateTime.Now; roleUser.UpdatedBy = model.UpdatedBy; Ctx.SaveChanges(); } updateUserOfGasStation(date.UserId, model.UserGasStationValue, model.UpdatedBy); return(true); }
public bool UserUpdate(VM.UserInfoItem model) { MD.tbl_Common_User date = Ctx.tbl_Common_User.First(u => u.UserId == model.UserId); date.UserName = model.UserName; date.EmailAddress = model.EmailAddress; date.UpdatedBy = model.UpdatedBy; date.UpdatedDate = DateTime.Now; Ctx.SaveChanges(); return(true); }
//public List<SelectListItem> GetAllGasStationSelectList() //{ // var allGasStation = (from gasStation in Ctx.tbl_Gs_GasStationInfo // where gasStation.IsDelete != true // select new SelectListItem // { // Text = gasStation.Name, // Value = gasStation.GasStationId.ToString(), // Selected = true // }); // return allGasStation.ToList(); //} public bool Create(VM.UserInfoItem model) { MD.tbl_Common_User date = new MD.tbl_Common_User(); date.UserName = model.UserName; date.LogonName = model.LogonName; //model.StatusList.First(). if (model.StrStatus.ToString() == UserStatus.Normal.strValue) { date.Status = UserStatus.Normal.intValue; } else { date.Status = UserStatus.Disable.intValue; } date.DomainAccount = model.DomainAccount; date.EmailAddress = model.EmailAddress; date.CreatedDate = DateTime.Now; date.CreatedBy = model.CreatedBy; date.UpdatedDate = DateTime.Now; date.UpdatedBy = model.UpdatedBy; //生成密码 //IPasswordPolicy Password = new RandomPassword(); //string orginalPassword = Password.GeneratePassword(); //date.Password = HashEncrypt.SHA512Encrypt(orginalPassword); date.Password = model.Password; Ctx.tbl_Common_User.Add(date); //生成角色关系 MD.tbl_Common_RoleUser roleUser = new MD.tbl_Common_RoleUser(); roleUser.RoleId = model.RoleId.Value; roleUser.UserId = date.UserId; roleUser.CreatedDate = DateTime.Now; roleUser.CreatedBy = model.CreatedBy; //roleUser.UpdatedDate = DateTime.Now; //roleUser.UpdatedBy = model.UpdatedBy; Ctx.tbl_Common_RoleUser.Add(roleUser); Ctx.SaveChanges(); //生成公司关系 updateUserOfCompany(roleUser.UserId, model.UserCompanyValue, model.CreatedBy); //生成 气站关系 // updateUserOfGasStation(roleUser.UserId, model.UserGasStationValue, model.CreatedBy); //发送邮件 //if(date.Status==1) // SendEmail(date, orginalPassword, "User_New"); return(true); }
public ActionResult GetGasStationMaps(int id, string value) { BL.UserInfo empBL = new BL.UserInfo(); VM.UserInfoItem model = new VM.UserInfoItem(); if (id > 0) { model = empBL.GetItemById(id); } if (value != null) { // model = empBL.GetItemByCompany(model, value); } model.UserCompanyValue = value; return(PartialView("_GasStationMap", model)); }
public ActionResult Edit(VM.UserInfoItem model) { BL.UserInfo empBL = new BL.UserInfo(); if (empBL.ValidateName(model.UserId, model.LogonName)) { return(Content(ResourceHelper.GetValue("SMM_UserInfo_SameLogonName"))); } if (!new EmailExAttribute().IsValid(model.EmailAddress)) { return(Content("False")); } model.UpdatedBy = "sysAdmin";// UserHelper.GetCurrentUser().LogonName; empBL.Update(model); return(Content("Success")); }
public ActionResult UserEdit(VM.UserInfoItem model) { if (!new EmailExAttribute().IsValid(model.EmailAddress)) { return(Content("False")); } BL.UserInfo empBL = new BL.UserInfo(); var userEdit = empBL.GetItemById(model.UserId); userEdit.UserName = model.UserName; userEdit.EmailAddress = model.EmailAddress; userEdit.UpdatedBy = "sysAdmin";//UserHelper.GetCurrentUser().LogonName; empBL.UserUpdate(userEdit); return(Content("Success")); }
public void SendEmail(VM.UserInfoItem model, string password, string emailTemplateName) { bool isSendEmailtoIIS = false; var sendEmailInfo = new SendEmailInfo(); var email = Ctx.tbl_EmailTemplate.FirstOrDefault(t => t.Name == emailTemplateName); string[] emailSendTo = { model.EmailAddress }; string url = string.Format("{0}/", EmailTemplateParam.GetHostName()); sendEmailInfo.mailSubject = email.EmailSubject.Replace(EmailTemplateParam.SystemName, EmailTemplateParam.SystemNameBasic); sendEmailInfo.mailBody = email.EmailContent.Replace(EmailTemplateParam.UserDisplayName, model.LogonName) .Replace(EmailTemplateParam.URL, url) .Replace(EmailTemplateParam.UserName, model.LogonName) .Replace(EmailTemplateParam.Password, password) .Replace("[DateTime]", DateTime.Now.ToString("yyyy年MM月dd日")); //MailHelper.SendMail(emailSendTo, sendEmailInfo.mailSubject, sendEmailInfo.mailBody, 0, isSendEmailtoIIS, true); }
//[AllowAnonymous] public async Task <ActionResult> Create(VM.UserInfoItem model) { BL.UserInfo empBL = new BL.UserInfo(); if (empBL.ValidateName(-1, model.LogonName)) { return(Content(ResourceHelper.GetValue("SMM_UserInfo_SameLogonName"))); } if (!new EmailExAttribute().IsValid(model.EmailAddress)) { return(Content("False")); } var user = new IdentityModel(); user.UserName = model.LogonName; user.LogonName = model.UserName; user.StrStatus = model.StrStatus; user.RoleId = model.RoleId; user.UserCompangValue = model.UserCompanyValue; user.UserGasStationValue = model.UserGasStationValue; user.DomainAccount = model.DomainAccount; user.EmailAddress = model.EmailAddress; user.CreateBy = "sysAdmin";//UserHelper.GetCurrentUser().LogonName; IPasswordPolicy Password = new RandomPassword(); string orginalPassword = Password.GeneratePassword(); string md5Password = HashEncrypt.MD5(orginalPassword); var result = await UserManager.CreateAsync(user, md5Password); if (result.Succeeded) { if (user.StrStatus == "1") { //empBL.SendEmail(model, orginalPassword, "User_New"); } return(Content("Success")); } return(Content("False")); }