/// <summary> /// 修改密码 /// </summary> /// <param name="model">修改密码实体</param> /// <returns>结果</returns> public async Task <BaseResult> ChangePasswordAsync(ChangePasswordModel model) { BaseResult result = new BaseResult(); string oldPwd = await _repository.GetPasswordByIdAsync(model.Id);//数据库中的密码 if (oldPwd == AESEncryptHelper.Encode(model.OldPassword, CzarCmsKeys.AesEncryptKeys)) { var count = await _repository.ChangePasswordByIdAsync(model.Id, AESEncryptHelper.Encode(model.NewPassword.Trim(), CzarCmsKeys.AesEncryptKeys)); if (count > 0) { result.ResultCode = ResultCodeAddMsgKeys.CommonObjectSuccessCode; result.ResultMsg = ResultCodeAddMsgKeys.CommonObjectSuccessMsg; } else { result.ResultCode = ResultCodeAddMsgKeys.CommonExceptionCode; result.ResultMsg = ResultCodeAddMsgKeys.CommonExceptionMsg; } } else { result.ResultCode = ResultCodeAddMsgKeys.PasswordOldErrorCode; result.ResultMsg = ResultCodeAddMsgKeys.PasswordOldErrorMsg; } return(result); }
/// <summary> /// 登录操作,成功则写日志 /// </summary> /// <param name="model">登陆实体</param> /// <returns>状态</returns> public async Task <Manager> SignInAsync(LoginModel model) { model.Password = AESEncryptHelper.Encode(model.Password.Trim(), CzarCmsKeys.AesEncryptKeys); model.UserName = model.UserName.Trim(); string conditions = $"select * from {nameof(Manager)} where IsDelete=0 ";//未删除的 conditions += $"and (UserName = @UserName or Mobile =@UserName or Email =@UserName) and Password=@Password"; var manager = await _repository.GetAsync(conditions, model); if (manager != null) { manager.LoginLastIp = model.Ip; manager.LoginCount += 1; manager.LoginLastTime = DateTime.Now; _repository.Update(manager); await _managerLogRepository.InsertAsync(new ManagerLog() { ActionType = CzarCmsEnums.ActionEnum.SignIn.ToString(), AddManageId = manager.Id, AddManagerNickName = manager.NickName, AddTime = DateTime.Now, AddIp = model.Ip, Remark = "用户登录" }); } return(manager); }
/// <summary> /// 登录操作,成功则写日志 /// </summary> /// <param name="model">登陆实体</param> /// <returns>状态</returns> public Manager SignIn(LoginModel model) { model.Password = AESEncryptHelper.Encode(model.Password.Trim(), CzarCmsKeys.AesEncryptKeys); model.UserName = model.UserName.Trim(); string conditions = "where IsDelete=0 ";//未删除的 conditions += $"and (UserName = @UserName or Mobile =@UserName or Email =@UserName) and Password=@Password"; var manager = _repository.GetList(conditions, model).FirstOrDefault(); if (manager != null) { manager.LoginLastIp = model.Ip; manager.LoginCount += 1; manager.LoginLastTime = DateTime.Now; _repository.Update(manager); _managerLogRepository.Insert(new ManagerLog() { ActionType = CzarCmsEnums.ActionEnum.SignIn.ToString(), AddManageId = manager.Id, AddManagerNickName = manager.NickName, AddTime = DateTime.Now, AddIp = model.Ip, Remark = "用户登录" }); } return(manager); }
public async Task <BaseResult> AddOrModifyAsync(ManagerAddOrModifyModel item) { var result = new BaseResult(); Manager manager; if (item.Id == 0) { //TODO ADD manager = _mapper.Map <Manager>(item); manager.Password = AESEncryptHelper.Encode(CzarCmsKeys.DefaultPassword, CzarCmsKeys.AesEncryptKeys); manager.LoginCount = 0; manager.AddManagerId = 1; manager.IsDelete = false; manager.AddTime = DateTime.Now; int?isresult = await _repository.InsertAsync(manager); if (isresult > 0) { result.ResultCode = ResultCodeAddMsgKeys.CommonObjectSuccessCode; result.ResultMsg = ResultCodeAddMsgKeys.CommonObjectSuccessMsg; } else { result.ResultCode = ResultCodeAddMsgKeys.CommonExceptionCode; result.ResultMsg = ResultCodeAddMsgKeys.CommonExceptionMsg; } } else { //TODO Modify manager = await _repository.GetAsync(item.Id); if (manager != null) { _mapper.Map(item, manager); manager.ModifyManagerId = 1; manager.ModifyTime = DateTime.Now; if (_repository.Update(manager) > 0) { result.ResultCode = ResultCodeAddMsgKeys.CommonObjectSuccessCode; result.ResultMsg = ResultCodeAddMsgKeys.CommonObjectSuccessMsg; } else { result.ResultCode = ResultCodeAddMsgKeys.CommonExceptionCode; result.ResultMsg = ResultCodeAddMsgKeys.CommonExceptionMsg; } } else { result.ResultCode = ResultCodeAddMsgKeys.CommonFailNoDataCode; result.ResultMsg = ResultCodeAddMsgKeys.CommonFailNoDataMsg; } } return(result); }
public async Task <Result <string> > ChangePwd(string oldPwd, string newPwd) { Result <string> result = new Result <string>(); var member = await _manageServices.QueryByID(1); if (member.Password != AESEncryptHelper.Encode(oldPwd)) { result.status = false; result.message = "旧密码错误"; return(result); } member.Password = AESEncryptHelper.Encode(newPwd); result.message = "修改密码成功!"; await _manageServices.Update(member); return(result); }
public async Task <IActionResult> Login(string userName, string passWord) { var(_bool, msg) = VerifyValiate(); if (!_bool) { return(Json(new { msg = msg, status = "error" })); } var manage = await _manageServices.QueryByID(1); if (manage.Name == userName && manage.Password == AESEncryptHelper.Encode(passWord)) { //登陆授权 var claims = new List <Claim>(); claims.Add(new Claim(ClaimTypes.Name, "name")); var indentity = new ClaimsIdentity(claims, "denglu"); var principal = new ClaimsPrincipal(indentity); await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, principal); //验证是否授权成功 if (principal.Identity.IsAuthenticated) { //return Redirect("/"); return(Json(new { msg = "登陆成功!", status = "ok" })); } else { return(Json(new { msg = "登陆失败!", status = "error" })); } } else { return(Json(new { msg = "账号密码错误!", status = "error" })); } }