public ErrorInfo ResetPassword(ref ErrorInfo err, ApiRequesEntityBean <ErrorInfo> inEnt) { ErrorInfo reEnt = new ErrorInfo(); string VerifyCode = ""; string LoginName = ""; string NewPwd = ""; var tmp = inEnt.para.SingleOrDefault(x => x.K == "VerifyCode"); if (tmp != null) { VerifyCode = tmp.V; } tmp = inEnt.para.SingleOrDefault(x => x.K == "LoginName"); if (tmp != null) { LoginName = tmp.V; } tmp = inEnt.para.SingleOrDefault(x => x.K == "NewPwd"); if (tmp != null) { NewPwd = tmp.V; } if (string.IsNullOrEmpty(VerifyCode) || string.IsNullOrEmpty(LoginName) || string.IsNullOrEmpty(NewPwd)) { err.IsError = true; err.Message = "参数不正确"; return(err); } using (DBEntities db = new DBEntities()) { var login = db.fa_login.SingleOrDefault(x => x.LOGIN_NAME == LoginName); if (login == null) { err.IsError = true; err.Message = "登录名不存在"; return(err); } if (login.VERIFY_CODE != VerifyCode) { err.IsError = true; err.Message = "验证码不正确"; return(err); } //检测密码复杂度 if (!Fun.CheckPassword(ref err, NewPwd)) { err.IsError = true; err.Message = string.Format("密码复杂度不够:{0}", err.Message); return(err); } login.PASSWORD = NewPwd.Md5(); Fun.DBEntitiesCommit(db, ref err); return(reEnt); } }
/// <summary> /// 修改用户密码 /// <para>entity:旧密码</para> /// <para>NewPwd:新密码</para> /// </summary> /// <param name="inEnt"></param> /// <returns></returns> async public Task <ResultObj <bool> > UserEditPwd(EditPwdDto inEnt) { var reObj = new ResultObj <bool>(); reObj.data = false; if (!inEnt.NewPwd.Equals(inEnt.ReNewPwd)) { reObj.success = false; reObj.msg = "两次密码不一致"; return(reObj); } if (!Fun.CheckPassword(inEnt.NewPwd, appConfig.BaseConfig.PwdComplexity)) { reObj.success = false; reObj.code = "-2"; reObj.msg = string.Format("密码复杂度不够:{0}", appConfig.BaseConfig.PwdComplexity); return(reObj); } DapperHelper <SysLoginEntity> dapper = new DapperHelper <SysLoginEntity>(); var single = await dapper.Single(i => i.loginName == inEnt.LoginName); if (single == null) { reObj.success = false; reObj.msg = "账号不存在"; return(reObj); } if (single.password != inEnt.OldPwd.Md5()) { reObj.success = false; reObj.msg = "原密码有误"; return(reObj); } single.password = inEnt.NewPwd.Md5(); var upRows = await dapper.Update(new DtoSave <SysLoginEntity> { data = single, saveFieldListExp = x => new object[] { x.password }, whereList = null }); if (upRows < 1) { reObj.success = false; reObj.msg = "修改密码失败"; return(reObj); } reObj.success = true; reObj.data = true; return(reObj); }
/// <summary> /// 重置用户密码 /// <para>VerifyCode:短信验证码</para> /// <para>LoginName:登录名</para> /// <para>NewPwd:新密码</para> /// </summary> /// <param name="inEnt"></param> /// <returns></returns> public async Task <Result> ResetPassword(ResetPasswordDto inEnt) { Result reObj = new Result(); if (string.IsNullOrEmpty(inEnt.VerifyCode) || string.IsNullOrEmpty(inEnt.LoginName) || string.IsNullOrEmpty(inEnt.NewPwd)) { reObj.success = false; reObj.msg = "参数不正确"; return(reObj); } var dapper = new DapperHelper <SysLoginEntity>(); var login = await dapper.Single(x => x.loginName == inEnt.LoginName); if (login == null) { reObj.success = false; reObj.msg = "登录名不存在"; return(reObj); } //if (login.verifyCode != inEnt.VerifyCode) //{ // reObj.success = false; // reObj.msg = "验证码不正确"; // return reObj; //} //检测密码复杂度 if (!Fun.CheckPassword(inEnt.NewPwd, appConfig.BaseConfig.PwdComplexity)) { reObj.success = false; reObj.msg = "密码复杂度不够:"; return(reObj); } login.password = inEnt.NewPwd.Md5(); await dapper.Update(new DtoSave <SysLoginEntity>() { data = login, saveFieldListExp = x => new object[] { x.password } }); return(reObj); }
public ErrorInfo LoginReg(ref ErrorInfo err, ApiLogingBean inEnt) { #region 检测输入 if (string.IsNullOrEmpty(inEnt.loginName)) { err.IsError = true; err.Message = "电话号码不能为空"; return(err); } if (!inEnt.loginName.IsOnlyNumber() || inEnt.loginName.Length != 11) { err.IsError = true; err.Message = "电话号码格式不正确"; return(err); } if (!Fun.CheckPassword(ref err, inEnt.passWord)) { err.Message = string.Format("密码复杂度不够:{0}", err.Message); err.IsError = true; return(err); } #endregion using (DBEntities db = new DBEntities()) { #region 检测验证码 if (AppSet.VerifyCode) { var nowDate = DateTime.Now.AddMinutes(-30); var codeNum = db.fa_sms_send.Where(x => x.ADD_TIME > nowDate && x.PHONE_NO == inEnt.loginName && x.CONTENT == inEnt.code ).Count(); if (codeNum == 0) { err.IsError = true; err.Message = "验证码无效"; return(err); } } #endregion var userList = db.fa_user.Where(x => x.LOGIN_NAME == inEnt.loginName).ToList(); #region 检测电话号码是否存在 if (userList.Count() > 0) { err.IsError = true; err.Message = "电话号码已经存在,请更换电话号码"; return(err); } #endregion var loginList = db.fa_login.Where(x => x.LOGIN_NAME == inEnt.loginName).ToList(); #region 添加登录账号 if (loginList.Count() == 0) { LOGIN inLogin = new LOGIN(); inLogin.LOGIN_NAME = inEnt.loginName; inLogin.PASSWORD = inEnt.passWord; Z_Login zLogin = new Z_Login(); var isAddSucc = zLogin.Login_Save(db, null, ref err, inLogin, null); if (isAddSucc == null) { return(err); } } #endregion #region 添加user TUser inUser = new TUser(); inUser.LOGIN_NAME = inEnt.loginName; inUser.NAME = inEnt.userName; var user = Mapper.Map <fa_user>(inUser); user.ID = Fun.GetCurrvalSeqID <fa_user>(); db.fa_user.Add(user); #endregion //var userInfo = db.fa_user_info.SingleOrDefault(x => x.ID == user.ID); //if (userInfo == null) //{ // userInfo = new fa_user_info { ID = user.ID }; // db.fa_user_info.Add(userInfo); //} err.Message = user.ID.ToString(); // 提交事务数据 Fun.DBEntitiesCommit(db, ref err); return(err); } }
public async Task <ResultObj <int> > LoginReg(LogingDto inEnt, DapperHelper <SysUserEntity> dbHelperUser, DapperHelper <SysLoginEntity> dbHelper) { ResultObj <int> reObj = new ResultObj <int>(); #region 验证值 ModelHelper <LogingDto> modelHelper = new ModelHelper <LogingDto>(inEnt); var errList = modelHelper.Validate(); if (errList.Count() > 0) { reObj.success = false; reObj.code = "-1"; reObj.msg = string.Format(",", errList.Select(x => x.ErrorMessage)); return(reObj); } #endregion #region 检测输入 if (!inEnt.loginName.IsOnlyNumber() || inEnt.loginName.Length != 11) { reObj.success = false; reObj.code = "-1"; reObj.msg = "电话号码格式不正确"; return(reObj); } if (!Fun.CheckPassword(inEnt.password, appConfig.BaseConfig.PwdComplexity)) { reObj.success = false; reObj.code = "-2"; reObj.msg = string.Format("密码复杂度不够:{0}", appConfig.BaseConfig.PwdComplexity); return(reObj); } #endregion #region 检测验证码 //if (AppSettingsManager.self.BaseConfig.VerifyCode) //{ // var nowDate = DateTime.Now.AddMinutes(-30); // var codeNum = await new SmsSendRepository().Count(inEnt.loginName, inEnt.code); // if (codeNum == 0) // { // reObj.success = false; // reObj.code = "-3"; // reObj.msg = string.Format("验证码无效"); // return reObj; // } //} #endregion var userList = await dbHelperUser.FindAll(x => x.loginName == inEnt.loginName); #region 检测电话号码是否存在 if (userList.Count() > 0) { reObj.success = false; reObj.code = "-4"; reObj.msg = string.Format("电话号码已经存在,请更换电话号码"); return(reObj); } #endregion //开始事务 try { var loginList = await FindAll(x => x.loginName == inEnt.loginName); #region 添加登录账号 if (loginList.Count() == 0) { SysLoginEntity inLogin = new SysLoginEntity(); inLogin.id = await SequenceRepository.GetNextID <SysLoginEntity>(); inLogin.loginName = inEnt.loginName; inLogin.password = inEnt.password.Md5(); inLogin.isLocked = 0; inLogin.failCount = 0; reObj.success = await dbHelper.Save(new DtoSave <SysLoginEntity>() { data = inLogin }) > 0 ? true : false; if (!reObj.success) { reObj.success = false; reObj.code = "-5"; reObj.msg = string.Format("添加账号失败"); return(reObj); } } #endregion #region 添加user SysUserEntity inUser = new SysUserEntity(); inUser.loginName = inEnt.loginName; inUser.name = inEnt.userName; inUser.id = await SequenceRepository.GetNextID <SysUserEntity>(); inUser.districtId = 1; inUser.createTime = Helper.DataTimeHelper.getDateLong(DateTime.Now); inUser.status = 1; reObj.success = await dbHelperUser.Save(new DtoSave <SysUserEntity> { data = inUser, ignoreFieldList = new List <string>() }) > 0 ? true : false; if (!reObj.success) { reObj.success = false; reObj.code = "-6"; reObj.msg = string.Format("添加user失败"); return(reObj); } #endregion reObj.data = inUser.id; } catch (Exception e) { reObj.success = false; reObj.msg = e.Message; } return(reObj); }