public ActionResult ChangePassword(ChangePasswordModel model) { string currentPerson = GetCurrentPerson(); ViewBag.PersonNamea = currentPerson; if (string.IsNullOrWhiteSpace(currentPerson)) { ModelState.AddModelError("", "对不起,请重新登陆"); return(View()); } if (ModelState.IsValid) { IAccountBLL accountBLL = new AccountBLL(); if (null != (accountBLL.ValidateUser(currentPerson, EncryptAndDecrypte.EncryptString(model.OldPassword)))) { if (accountBLL.ChangePassword(currentPerson, model.OldPassword, model.NewPassword)) { ModelState.AddModelError("", "修改密码成功"); return(View()); } } } ModelState.AddModelError("", "修改密码不成功,请核实数据"); return(View()); }
/// <summary> /// 登录页面 /// </summary> /// <returns></returns> public ActionResult Index() { return(View()); //开发的时候,只需要注释此行代码 #if DEBUG //Debug 测试时使用 AccountBLL accountBLL = new BLL.AccountBLL(); SysPerson person = accountBLL.ValidateUser("Admin", EncryptAndDecrypte.EncryptString("123456")); if (person != null) {//登录成功 Account account = new Account(); account.Name = person.MyName; account.PersonName = person.Name; account.Id = person.Id.ToString(); account.LastLogonIP = person.LastLogonIP; account.LastLogonTime = person.LastLogonTime; account.LogonNum = person.LogonNum; account.Theme = person.PageStyle; //Session["account"] = account; Utils.WriteCookie("account", account, 7); return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index", "Home")); #else //Release 正式平台使用 return(View()); #endif }
/// <summary> /// 修改密码 /// </summary> /// <param name="personName">用户名</param> /// <param name="oldPassword">旧密码</param> /// <param name="newPassword">新密码</param> /// <returns>修改密码是否成功</returns> public bool ChangePassword(string personName, string oldPassword, string newPassword) { if (!string.IsNullOrWhiteSpace(personName) && !string.IsNullOrWhiteSpace(oldPassword) && !string.IsNullOrWhiteSpace(newPassword)) { try { string oldPasswordEncryptString = EncryptAndDecrypte.EncryptString(oldPassword); string newPasswordEncryptString = EncryptAndDecrypte.EncryptString(newPassword); using (SysEntities db = new SysEntities()) { var person = db.SysPerson.FirstOrDefault(p => (p.Name == personName) && (p.Password == oldPasswordEncryptString)); person.Password = newPasswordEncryptString; person.SurePassword = newPasswordEncryptString; if (!string.IsNullOrWhiteSpace(person.EmailAddress)) { NetSendMail.MailSendChangePassword(db, person.EmailAddress, personName, newPassword); //发送通知的邮件 } db.SaveChanges(); return(true); } } catch (Exception ex) { ExceptionsHander.WriteExceptions(ex); } } return(false); }
public ActionResult Index(LogOnModel model) { #region 验证码验证 if (Session["__VCode"] == null || (Session["__VCode"] != null && model.ValidateCode != Session["__VCode"].ToString())) { ModelState.AddModelError("PersonName", "验证码错误!"); //return ""; return(View()); } #endregion if (ModelState.IsValid) { IAccountBLL accountBLL = new BLL.AccountBLL(); SysPerson person = accountBLL.ValidateUser(model.PersonName, EncryptAndDecrypte.EncryptString(model.Password)); if (person != null) {//登录成功 Account account = new Account(); account.Name = person.Name; account.PersonName = person.MyName; account.Id = person.Id.ToString(); account.LastLogonIP = person.LastLogonIP; account.LastLogonTime = person.LastLogonTime; account.LogonNum = person.LogonNum; Utils.WriteCookie("account", account, 7); //Session["account"] = account; return(RedirectToAction("Index", "Home")); } } ModelState.AddModelError("PersonName", "用户名或者密码出错。"); return(View()); }
public ActionResult Edit(string id, SysPerson entity) { if (entity != null && ModelState.IsValid) { //数据校验 string currentPerson = GetCurrentPerson(); entity.UpdateTime = DateTime.Now; entity.UpdatePerson = currentPerson; //加密 entity.Password = EncryptAndDecrypte.EncryptString(entity.Password); entity.SurePassword = entity.Password; string returnValue = string.Empty; if (m_BLL.Edit(ref validationErrors, entity)) { LogClassModels.WriteServiceLog(Suggestion.UpdateSucceed + ",人员信息的Id为" + id, "人员" ); //写入日志 return(Json(Suggestion.UpdateSucceed)); //提示更新成功 } else { if (validationErrors != null && validationErrors.Count > 0) { validationErrors.All(a => { returnValue += a.ErrorMessage; return(true); }); } LogClassModels.WriteServiceLog(Suggestion.UpdateFail + ",人员信息的Id为" + id + "," + returnValue, "人员" ); //写入日志 return(Json(Suggestion.UpdateFail + returnValue)); //提示更新失败 } } return(Json(Suggestion.UpdateFail + "请核对输入的数据的格式")); //提示输入的数据的格式不对 }
public ActionResult Edit(string id) { SysPerson entity = m_BLL.GetById(id); entity.Password = EncryptAndDecrypte.DecrypteString(entity.Password);//解密 entity.SurePassword = entity.Password; return(View(entity)); }
public ActionResult Create(SysPerson entity) { if (entity != null && ModelState.IsValid) { //用户名重名判断 List <SysPerson> sp = m_BLL.GetAll(); foreach (var item in sp) { if (item.Name == entity.Name) { return(Json(Suggestion.InsertFail + ",用户名已被使用")); } } string currentPerson = GetCurrentPerson(); entity.CreateTime = DateTime.Now; entity.CreatePerson = currentPerson; entity.Id = Result.GetNewId(); string returnValue = string.Empty; //谢承忠添加 //登入时做了加密检验 entity.Password = EncryptAndDecrypte.EncryptString(entity.Password); entity.SurePassword = EncryptAndDecrypte.EncryptString(entity.SurePassword); if (m_BLL.Create(ref validationErrors, entity)) { LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",人员的信息的Id为" + entity.Id, "人员" );//写入日志 return(Json(Suggestion.InsertSucceed)); } else { if (validationErrors != null && validationErrors.Count > 0) { validationErrors.All(a => { returnValue += a.ErrorMessage; return(true); }); } LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",人员的信息," + returnValue, "人员" ); //写入日志 return(Json(Suggestion.InsertFail + returnValue)); //提示插入失败 } } return(Json(Suggestion.InsertFail + ",请核对输入的数据的格式")); //提示输入的数据的格式不对 }
/// <summary> /// 验证用户名和密码是否正确 /// </summary> /// <param name="phoneNumber">用户名</param> /// <param name="password">密码</param> /// <returns>登录成功后的用户信息</returns> public DAL.Account ValidateUser(string phoneNumber, string password) { if (String.IsNullOrWhiteSpace(phoneNumber) || String.IsNullOrWhiteSpace(password)) { return(null); } password = EncryptAndDecrypte.EncryptString(password); //获取用户信息,请确定web.config中的连接字符串正确 using (SysEntities db = new SysEntities()) { return((from p in db.Account where p.PhoneNumber == phoneNumber && p.Password == password && p.State == "启用" select p).FirstOrDefault()); } }
public ActionResult Edit(string id, SysPerson entity) { if (entity != null && ModelState.IsValid) { //数据校验 string oldPic = Request.Form["OldPic"]; if (entity.HDpic != oldPic) //修改头像删除老的头像文件 { DirFile.DeleteFile(oldPic); } string currentPerson = GetCurrentPerson(); entity.UpdateTime = DateTime.Now; entity.UpdatePerson = currentPerson; //如果修改了密码,就将密码加密 2016830 IBLL.IAccountBLL accountBLL = new AccountBLL(); if (null == (accountBLL.ValidateUser(entity.Name, entity.Password))) { entity.Password = EncryptAndDecrypte.EncryptString(entity.Password); entity.SurePassword = EncryptAndDecrypte.EncryptString(entity.SurePassword); } string returnValue = string.Empty; if (m_BLL.Edit(ref validationErrors, entity)) { LogClassModels.WriteServiceLog(Suggestion.UpdateSucceed + ",人员信息的Id为" + id, "人员" ); //写入日志 App.Codes.MenuCaching.ClearCache(id); //清除缓存 return(Json(Suggestion.UpdateSucceed)); //提示更新成功 } else { if (validationErrors != null && validationErrors.Count > 0) { validationErrors.All(a => { returnValue += a.ErrorMessage; return(true); }); } LogClassModels.WriteServiceLog(Suggestion.UpdateFail + ",人员信息的Id为" + id + "," + returnValue, "人员" ); //写入日志 return(Json(Suggestion.UpdateFail + returnValue)); //提示更新失败 } } return(Json(Suggestion.UpdateFail + "请核对输入的数据的格式")); //提示输入的数据的格式不对 }
/// <summary> /// 修改密码 /// </summary> /// <param name="personName">用户名</param> /// <param name="oldPassword">旧密码</param> /// <param name="newPassword">新密码</param> /// <returns>修改密码是否成功</returns> public bool ChangePassword(string personName, string oldPassword, string newPassword) { if (!string.IsNullOrWhiteSpace(personName) && !string.IsNullOrWhiteSpace(oldPassword) && !string.IsNullOrWhiteSpace(newPassword)) { try { string oldPasswordEncryptString = EncryptAndDecrypte.EncryptString(oldPassword); string newPasswordEncryptString = EncryptAndDecrypte.EncryptString(newPassword); using (SysEntities db = new SysEntities()) { return(true); } } catch (Exception ex) { ExceptionsHander.WriteExceptions(ex); } } return(false); }
public ActionResult Create(SysPerson entity) { if (entity != null && ModelState.IsValid) { string currentPerson = GetCurrentPerson(); entity.CreateTime = DateTime.Now; entity.CreatePerson = currentPerson; entity.Id = Result.GetNewId(); //将密码加密 2016830 entity.Password = EncryptAndDecrypte.EncryptString(entity.Password); entity.SurePassword = EncryptAndDecrypte.EncryptString(entity.SurePassword); string returnValue = string.Empty; if (m_BLL.Create(ref validationErrors, entity)) { LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",人员的信息的Id为" + entity.Id, "人员" );//写入日志 return(Json(Suggestion.InsertSucceed)); } else { if (validationErrors != null && validationErrors.Count > 0) { validationErrors.All(a => { returnValue += a.ErrorMessage; return(true); }); } LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",人员的信息," + returnValue, "人员" ); //写入日志 return(Json(Suggestion.InsertFail + returnValue)); //提示插入失败 } } return(Json(Suggestion.InsertFail + ",请核对输入的数据的格式")); //提示输入的数据的格式不对 }
/// <summary> /// 注册 /// </summary> public Common.Account Register(string name, string phoneNumber, string password, string inviteCode, ref string message) { //获取用户信息,请确定web.config中的连接字符串正确 using (SysEntities db = new SysEntities()) { bool invites = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["InviteCodeEnabled"]); if (!invites) { password = EncryptAndDecrypte.EncryptString(password); var dataAccount = (from p in db.Account where p.PhoneNumber == phoneNumber || p.Name == name select p).FirstOrDefault(); if (dataAccount == null) { Invite invite = new Invite() { Id = Common.Result.GetNewId(), Code = GetByRndNum(5), State = StateEnums.QY , CreateTime = DateTime.Now, CreatePerson = name }; db.Invite.Add(invite); Invite invite2 = new Invite() { Id = Common.Result.GetNewId(), Code = GetByRndNum(5), State = StateEnums.QY , CreateTime = DateTime.Now, CreatePerson = name }; db.Invite.Add(invite2); var account = new DAL.Account() { Id = Common.Result.GetNewId(), State = StateEnums.QY, PhoneNumber = phoneNumber, Name = name, Password = password , CreateTime = DateTime.Now, CreatePerson = phoneNumber }; db.Account.Add(account); Resume resume = new Resume() { Id = Common.Result.GetNewId(), AccountId = account.Id, CreateTime = DateTime.Now, CreatePerson = name, Name = "默认", Remark = "注册账号自动创建", Sort = 0, State = StateEnums.QY, CompletionPercentage = 0 }; db.Resume.Add(resume); SysNotice notice = new SysNotice(); notice.Id = Result.GetNewId(); notice.CreatePerson = name; notice.CreateTime = DateTime.Now; notice.AccountId = account.Id; notice.Message = "您的邀请码为:" + invite.Code + ",另一个为:" + invite2.Code; db.SysNotice.Add(notice); db.SaveChanges(); Common.Account accountCommon = new Common.Account(); accountCommon.ResumeId = resume.Id; accountCommon.Name = name; accountCommon.Id = account.Id; return(accountCommon); } else { if (phoneNumber == dataAccount.PhoneNumber) { message = "手机号码已经存在"; } else if (name == dataAccount.Name) { message = "绰号已经存在"; } } } else { var data = (from p in db.Invite where p.Code == inviteCode && p.State == StateEnums.QY select p).FirstOrDefault(); if (data != null) { password = EncryptAndDecrypte.EncryptString(password); var dataAccount = (from p in db.Account where p.PhoneNumber == phoneNumber || p.Name == name select p).FirstOrDefault(); if (dataAccount == null) { data.State = StateEnums.JY; data.UpdatePerson = name; data.UpdateTime = DateTime.Now; Invite invite = new Invite() { Id = Common.Result.GetNewId(), Code = GetByRndNum(5), State = StateEnums.QY , CreateTime = DateTime.Now, CreatePerson = name }; db.Invite.Add(invite); Invite invite2 = new Invite() { Id = Common.Result.GetNewId(), Code = GetByRndNum(5), State = StateEnums.QY , CreateTime = DateTime.Now, CreatePerson = name }; db.Invite.Add(invite2); var account = new DAL.Account() { Id = Common.Result.GetNewId(), State = StateEnums.QY, PhoneNumber = phoneNumber, Name = name, Password = password , CreateTime = DateTime.Now, CreatePerson = phoneNumber }; db.Account.Add(account); Resume resume = new Resume() { Id = Common.Result.GetNewId(), AccountId = account.Id, CreateTime = DateTime.Now, CreatePerson = name, Name = "默认", Remark = "注册账号自动创建", Sort = 0, State = StateEnums.QY, CompletionPercentage = 0 }; db.Resume.Add(resume); SysNotice notice = new SysNotice(); notice.Id = Result.GetNewId(); notice.CreatePerson = name; notice.CreateTime = DateTime.Now; notice.AccountId = account.Id; notice.Message = "您的邀请码为:" + invite.Code + ",另一个为:" + invite2.Code; db.SysNotice.Add(notice); db.SaveChanges(); Common.Account accountCommon = new Common.Account(); accountCommon.ResumeId = resume.Id; accountCommon.Name = name; accountCommon.Id = account.Id; return(accountCommon); } else { if (phoneNumber == dataAccount.PhoneNumber) { message = "手机号码已经存在"; } else if (name == dataAccount.Name) { message = "绰号已经存在"; } } } else { message = "邀请码不正确"; } } } return(null); }