public async Task <LoginOutput> LoginByAccountPwd(LoginByAccountPwdInput input, string fromIP) { //rsa解密 var password = H_EncryptProvider.RsaDecrypt(_appSettings.Key.RsaPrivateKey, input.Password); //sha256加密 password = H_EncryptProvider.HMACSHA256(password, _appSettings.Key.Sha256Key); //根据账号密码登录 var user = await _userDomainService.LoginByAccountPwd(input.Account, password); return(await Login(user, fromIP, input.IsRememberLogin)); }
/// <summary> /// 更新用户密码 /// </summary> /// <param name="userId"></param> /// <param name="oldPwd"></param> /// <param name="newPwd"></param> /// <returns></returns> public async Task UpdatePwd(long userId, string oldPwd, string newPwd) { var user = await Get(userId); oldPwd = H_EncryptProvider.HMACSHA256(oldPwd, _appSettings.Key.Sha256Key); H_AssertEx.That(user.Password != oldPwd, "原密码错误"); user.PasswordLevel = (PasswordLevel)H_Util.CheckPasswordLevel(newPwd); user.Password = H_EncryptProvider.HMACSHA256(newPwd, _appSettings.Key.Sha256Key); await _userRep.UpdateAsync(user, user => new { user.Password, user.PasswordLevel }); }
public async Task Add(UserAddInput input) { var user = input.Adapt <SysUser>(); user.FirstNameInitial = WordsHelper.GetFirstPinyin(user.Name.Substring(0, 1)); user.PasswordLevel = (PasswordLevel)H_Util.CheckPasswordLevel(user.Password); user.Password = H_EncryptProvider.HMACSHA256(user.Password, _appSettings.Key.Sha256Key); user.Enabled = true; var role = await _roleDomainService.Get(input.RoleId.Value); user.RoleId = role.Id; user.RoleName = role.Name; user.AuthNumbers = role.AuthNumbers; user.RoleLevel = role.Level; await _userDomainService.Add(user); }
/// <summary> /// 导入excel /// </summary> /// <param name="files"></param> /// <returns></returns> public async Task Import(IFormFileCollection files) { H_AssertEx.That(files == null || files.Count == 0, "请选择Excel文件"); //格式限制 var allowType = new string[] { "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }; H_AssertEx.That(files.Any(b => !allowType.Contains(b.ContentType)), "只能上传Excel文件"); ////大小限制 //if (files.Sum(b => b.Length) >= 1024 * 1024 * 4) //{ //} var users = new List <SysUser>(); foreach (IFormFile file in files) { string rootPath = _appSettings.FilePath.ImportExcelPath; H_File.CreateDirectory(rootPath); string filePath = Path.Combine(rootPath, file.FileName); using (var fs = System.IO.File.Create(filePath)) { // 复制文件 file.CopyTo(fs); // 清空缓冲区数据 fs.Flush(); } using (var ep = new ExcelPackage(new FileInfo(filePath))) { var worksheet = ep.Workbook.Worksheets[0]; if (worksheet != null && worksheet.Cells[1, 1].Text.Trim() != "姓名") { throw new H_Exception("上传数据列名有误,请检查"); } foreach (var ws in ep.Workbook.Worksheets) { int colStart = ws.Dimension.Start.Column; //工作区开始列,start=1 int colEnd = ws.Dimension.End.Column; //工作区结束列 int rowStart = ws.Dimension.Start.Row; //工作区开始行号,start=1 int rowEnd = ws.Dimension.End.Row; //工作区结束行号 for (int i = rowStart + 1; i <= rowEnd; i++) //第1行是列名,跳过 { var user = new SysUser(); user.Name = ws.Cells[i, colStart].Text; user.FirstNameInitial = WordsHelper.GetFirstPinyin(user.Name.Substring(0, 1)); user.Password = H_EncryptProvider.HMACSHA256("123456", _appSettings.Key.Sha256Key); users.Add(user); } } } } if (users.Count == 0) { return; } await _userRep.InsertAsync(users); }