public async Task <ApiResult <string> > Post(EditSysUserDto Params) { ApiResult <string> res = new ApiResult <string>(); TokenModelBeta token = JwtToken.ParsingJwtToken(HttpContext); //开启事务 try { SysUser userInfo = _mapper.Map <SysUser>(Params); userInfo.Id = Guid.NewGuid().ToString(); userInfo.CreatorTime = DateTime.Now; userInfo.CreatorId = token.Id; await _userService.AddAsync(userInfo); SysUserLogon userLogonInfo = _mapper.Map <SysUserLogon>(Params); userLogonInfo.Id = Guid.NewGuid().ToString(); userLogonInfo.UserId = userInfo.Id; userLogonInfo.LogOnCount = 0; userLogonInfo.UserSecretkey = Md5Crypt.Encrypt(Guid.NewGuid().ToString()); userLogonInfo.UserPassword = Md5Crypt.Encrypt(DES3Encrypt.EncryptString(userLogonInfo.UserPassword.ToLower(), userLogonInfo.UserSecretkey).ToLower(), false).ToLower(); userLogonInfo.PasswordSecurity = UniversalTool.PassSecurityValidation(userLogonInfo.UserPassword); await _userLogonService.AddAsync(userLogonInfo); } catch (Exception ex) { res.code = (int)ApiEnum.Error; res.message = "异常:" + ex.Message; } //事务结束 return(await Task.Run(() => res)); }
public async Task <IActionResult> Add([FromBody] List <FormParam> param) { var res = await _memberService.Login(param); if (res.statusCode != 200) { return(Ok(res)); } //保存认证策略 var modelStr = JsonConvert.SerializeObject(res.data); //加密保存起来 var jmStr = DES3Encrypt.EncryptString(modelStr); var identity = new ClaimsPrincipal( new ClaimsIdentity(new[] { new Claim(KeyHelper.BbsUserKey, jmStr), }, BbsUserAuthorizeAttribute.BbsUserAuthenticationScheme) ); await HttpContext.SignInAsync(BbsUserAuthorizeAttribute.BbsUserAuthenticationScheme, identity, new AuthenticationProperties { AllowRefresh = false }); return(Ok(res)); }
/// <summary> /// 修改登录密码 /// </summary> /// <returns></returns> public async Task <ApiResult <string> > ModifyLoginPwdAsync(StaffModifyPwdParm parm) { var res = new ApiResult <string>() { data = "1", statusCode = (int)ApiEnum.ParameterError }; try { //判断原密码是否正确 parm.HistoryPwd = DES3Encrypt.EncryptString(parm.HistoryPwd); var isExt = ErpStaffDb.IsAny(m => m.LoginPwd == parm.HistoryPwd && m.Guid == parm.Guid); if (!isExt) { res.message = "原密码输入错误~"; return(await Task.Run(() => res)); } //开始修改新密码 parm.NewPwd = DES3Encrypt.EncryptString(parm.NewPwd); ErpStaffDb.Update(m => new ErpStaff() { LoginPwd = parm.NewPwd }, m => m.Guid == parm.Guid); res.statusCode = (int)ApiEnum.Status; } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }
/// <summary> /// 修改一条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <string> > ModifyAsync(ErpStaff parm) { var res = new ApiResult <string>() { data = "1", statusCode = 200 }; try { parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd); ErpStaffDb.Update(m => new ErpStaff() { TrueName = parm.TrueName, Sex = parm.Sex, LoginName = parm.LoginName, Status = parm.Status, Mobile = parm.Mobile, LoginPwd = parm.LoginPwd }, m => m.Guid == parm.Guid); } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }
/// <summary> /// 添加一条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(ErpShops parm) { var res = new ApiResult <string>() { data = "1", statusCode = 200 }; try { //判断登录账号和店铺名是否存在 var isExt = ErpShopsDb.IsAny(m => m.LoginName == parm.LoginName && m.ShopName == parm.ShopName); if (isExt) { res.statusCode = (int)ApiEnum.ParameterError; res.message = "该商铺已存在~"; } else { parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd); parm.Guid = Guid.NewGuid().ToString(); var dbres = ErpShopsDb.Insert(parm); if (!dbres) { res.statusCode = (int)ApiEnum.Error; res.message = "插入数据失败~"; } } } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }
/// <summary> /// 用户登录实现 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <SysUserInfo> > LoginAsync(SysAdminLogin parm) { var res = new ApiResult <SysUserInfo>(); parm.password = DES3Encrypt.EncryptString(parm.password); var model = db.Queryable <SysUserInfo>() .Where(c => c.loginName == parm.loginname).First(); if (model != null) { if (model.loginPWD.Equals(parm.password)) { //修改登录时间 //保存操作日志 res.success = true; res.message = "获取成功"; res.data = model; } else { res.success = false; res.message = "密码错误"; res.statusCode = (int)ApiEnum.Error; } } else { res.success = false; res.statusCode = (int)ApiEnum.Error; res.message = "账号错误~"; } return(await Task.Run(() => res)); }
/// <summary> /// 修改操作 /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <ApiResult <string> > Edit(Member model) { var res = new ApiResult <string>() { statusCode = (int)ApiEnum.Error }; try { //判断账号是否存在 var isexModel = Db.Queryable <Member>().Single(m => m.LoginName == model.LoginName && m.Guid != model.Guid); if (isexModel != null) { res.message = "用户名已存在,请更换~"; return(res); } model.LoginPwd = DES3Encrypt.EncryptString(model.LoginPwd); await Db.Updateable(model).ExecuteCommandAsync(); res.statusCode = (int)ApiEnum.Status; } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(res); }
/// <summary> /// 用户登录实现 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <SysAdmin> > LoginAsync(SysAdminLogin parm) { var res = new ApiResult <SysAdmin>(); try { parm.password = DES3Encrypt.EncryptString(parm.password); var model = Db.Queryable <SysAdmin>() .Where(m => m.LoginName == parm.loginname).First(); if (model != null) { if (model.LoginPwd.Equals(parm.password)) { //修改登录时间 model.LoginDate = DateTime.Now; model.UpLoginDate = model.LoginDate; SysAdminDb.Update(model); #region 保存操作日志 var logModel = new SysLog() { Guid = Guid.NewGuid().ToString(), LoginName = model.LoginName, DepartName = model.DepartmentName, OptionTable = "SysAdmin", Summary = "登录操作", IP = Utils.GetIp(), LogType = (int)LogEnum.Login, Urls = Utils.GetUrl(), AddTime = DateTime.Now }; SysLogDb.Insert(logModel); #endregion res.success = true; res.message = "获取成功!"; res.data = model; } else { res.success = false; res.statusCode = (int)ApiEnum.Error; res.message = "密码错误~"; } } else { res.success = false; res.statusCode = (int)ApiEnum.Error; res.message = "账号错误~"; } } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; res.statusCode = (int)ApiEnum.Error; } return(await Task.Run(() => res)); }
/// <summary> /// 修改菜单 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <string> > ModifyAsync(SysAdmin parm) { var res = new ApiResult <string> { statusCode = (int)ApiEnum.Error }; try { //修改,判断用户是否和其它的重复 var isExisteName = await Db.Queryable <SysAdmin>().AnyAsync(m => m.LoginName == parm.LoginName && m.Guid != parm.Guid); if (isExisteName) { res.message = "用户名已存在,请更换~"; res.statusCode = (int)ApiEnum.ParameterError; return(await Task.Run(() => res)); } parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd); if (!string.IsNullOrEmpty(parm.DepartmentGuid)) { // 说明有父级 根据父级,查询对应的模型 var model = SysOrganizeDb.GetById(parm.DepartmentGuid); parm.DepartmentGuidList = model.ParentGuidList; } var dbres = await Db.Updateable <SysAdmin>().UpdateColumns(m => new SysAdmin() { LoginName = parm.LoginName, LoginPwd = parm.LoginPwd, DepartmentName = parm.DepartmentName, DepartmentGuid = parm.DepartmentGuid, DepartmentGuidList = parm.DepartmentGuidList, TrueName = parm.TrueName, Number = parm.Number, Sex = parm.Sex, Mobile = parm.Mobile, Email = parm.Email, Status = parm.Status }).Where(m => m.Guid == parm.Guid).ExecuteCommandAsync(); if (dbres > 0) { res.statusCode = (int)ApiEnum.Status; res.message = "更新成功!"; } else { res.message = "更新失败!"; } } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(res); }
/// <summary> /// 用户登录实现 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <SysAdminMenuDto> > LoginAsync(SysAdminLogin parm) { var res = new ApiResult <SysAdminMenuDto>() { statusCode = (int)ApiEnum.Error }; try { var adminModel = new SysAdminMenuDto(); parm.password = DES3Encrypt.EncryptString(parm.password); var model = await Db.Queryable <SysAdmin>() .Where(m => m.LoginName == parm.loginname).FirstAsync(); if (model == null) { res.message = "账号错误"; return(res); } if (!model.LoginPwd.Equals(parm.password)) { res.message = "密码错误~"; return(res); } if (!model.Status) { res.message = "登录账号被冻结,请联系管理员~"; return(res); } adminModel.menu = GetMenuByAdmin(model.Guid); if (adminModel == null) { res.message = "当前账号没有授权功能模块,无法登录~"; return(res); } //修改登录时间 model.LoginDate = DateTime.Now; model.UpLoginDate = model.LoginDate; model.LoginSum = model.LoginSum + 1; SysAdminDb.Update(model); res.statusCode = (int)ApiEnum.Status; adminModel.admin = model; res.data = adminModel; } catch (Exception ex) { res.message = ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(res); }
/// <summary> /// 添加部门信息 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(SysAdmin parm) { var res = new ApiResult <string> { statusCode = (int)ApiEnum.ParameterError }; try { //判断用吗是否存在 var isExisteName = await Db.Queryable <SysAdmin>().AnyAsync(m => m.LoginName == parm.LoginName); if (isExisteName) { res.message = "用户名已存在,请更换~"; return(res); } parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd); if (string.IsNullOrEmpty(parm.HeadPic)) { parm.HeadPic = "/themes/img/avatar.jpg"; } parm.Guid = Guid.NewGuid().ToString(); parm.AddDate = DateTime.Now; if (!string.IsNullOrEmpty(parm.DepartmentGuid)) { // 说明有父级 根据父级,查询对应的模型 var model = SysOrganizeDb.GetById(parm.DepartmentGuid); parm.DepartmentGuidList = model.ParentGuidList; } SysAdminDb.Insert(parm); //查询授权表,type=2 更新新的权限值 //添加新的 var authorityList = new List <SysPermissions>(); foreach (var item in parm.RoleList) { authorityList.Add(new SysPermissions() { RoleGuid = item.guid, AdminGuid = parm.Guid, Types = 2 }); } await Db.Insertable(authorityList).ExecuteCommandAsync(); res.statusCode = (int)ApiEnum.Status; } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(await Task.Run(() => res)); }
/// <summary> /// 根据账号密码登录 /// </summary> /// <returns></returns> public async Task <ApiResult <ShopBasicDto> > LoginAsync(StaffLoginDto parm) { var res = new ApiResult <ShopBasicDto> { statusCode = (int)ApiEnum.ParameterError }; //先查询员工账号是否可以登录,如果可以,根据员工的归属加盟商,在查询对应的加盟商 var staffModel = ErpStaffDb.GetSingle(m => m.LoginName == parm.loginName); if (staffModel == null) { res.message = "登录账号错误"; return(await Task.Run(() => res)); } //判断密码 parm.loginPwd = DES3Encrypt.EncryptString(parm.loginPwd); if (staffModel.LoginPwd != parm.loginPwd) { res.message = "密码错误"; return(await Task.Run(() => res)); } if (staffModel.Status != 0) { res.message = "账号被冻结,请联系管理员"; return(await Task.Run(() => res)); } //根据商铺ID查询店铺信息,以及修改账号登录信息 staffModel.LoginCount += 1; staffModel.LastLoginDate = DateTime.Now; staffModel.UpLoginDate = staffModel.LastLoginDate; staffModel.IsDevice = parm.isDevice; staffModel.DeviceName = parm.deviceName; staffModel.Token = parm.token; //修改员工信息 ErpStaffDb.Update(staffModel); //根据员工的关联的加盟商ID,查询加盟商信息 var shopModel = ErpShopsDb.GetSingle(m => m.Guid == staffModel.ShopGuid); if (shopModel == null) { res.message = "店铺不存在!"; return(await Task.Run(() => res)); } res.statusCode = (int)ApiEnum.Status; res.data = new ShopBasicDto() { StaffGuid = staffModel.Guid, ShopGuid = shopModel.Guid, ShopName = shopModel.ShopName, AdminName = staffModel.TrueName, Mobile = staffModel.Mobile }; return(await Task.Run(() => res)); }
/// <summary> /// 登录 /// </summary> /// <param name="param"></param> /// <returns></returns> public async Task <ApiResult <Member> > Login(List <FormParam> param) { var res = new ApiResult <Member>() { statusCode = (int)ApiEnum.Error }; try { if (param == null || param.Count == 0) { res.message = ApiEnum.ParameterError.GetEnumText(); return(res); } var model = await Db.Queryable <Member>().SingleAsync(m => m.LoginName == param[0].value || m.Mobile == param[0].value || m.Email == param[0].value && !m.IsDel); if (model == null) { res.message = "用户名输入错误~"; return(res); } if (!model.Status) { res.message = "账号被冻结,请联系客服专员~"; return(res); } //密码处理 var pass = DES3Encrypt.EncryptString(param[1].value); if (!pass.Equals(model.LoginPwd)) { res.message = "密码输入错误~"; return(res); } //修改时间 model.LoginSum += 1; model.LoginTime = DateTime.Now; await Db.Updateable(model).ExecuteCommandAsync(); res.data = model; res.statusCode = (int)ApiEnum.Status; } catch (Exception ex) { res.message = ex.Message; } return(res); }
/// <summary> /// 修改密码 /// </summary> public async Task <ApiResult <string> > UpdatePwdAsync(UpdatePwdDto parm) { var res = new ApiResult <string> { statusCode = (int)ApiEnum.Error }; try { if (string.IsNullOrEmpty(parm.userId)) { res.message = "当前登录用户已过期"; res.statusCode = (int)ApiEnum.LoginExpireError; return(await Task.Run(() => res)); } if (parm.new_pwd != parm.con_pwd) { res.message = "两次密码输入不一致"; res.statusCode = (int)ApiEnum.ParameterError; return(await Task.Run(() => res)); } var model = await Db.Queryable <SysAdmin>().Where(t => t.Guid == parm.userId).FirstAsync(); if (model.LoginPwd != DES3Encrypt.EncryptString(parm.old_pwd)) { res.message = "原密码错误"; res.statusCode = (int)ApiEnum.ParameterError; return(await Task.Run(() => res)); } model.LoginPwd = DES3Encrypt.EncryptString(parm.new_pwd); var dbres = await Db.Updateable(model).UpdateColumns(t => new { t.LoginPwd }).ExecuteCommandAsync(); if (dbres > 0) { res.statusCode = (int)ApiEnum.Status; res.message = "更新成功!"; } else { res.message = "更新失败!"; } } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(res); }
/// <summary> /// 登录方法 /// </summary> /// <param name="db"></param> /// <param name="lmodel"></param> /// <returns></returns> public ResultJson Logins(SqlSugarClient db, vLoginModel lmodel) { var json = new ResultJson() { backurl = "/fytadmin/index/" }; var model = db.Queryable <sysadmin>().Single(m => m.LoginName == lmodel.loginname); if (model != null) { LogProvider.Error(LoggerEnums.Info.ToString(), DES3Encrypt.EncryptString(lmodel.password)); if (model.LoginPwd.Equals(DES3Encrypt.EncryptString(lmodel.password))) { //判断是否冻结 if (model.Status) { json.data = model; //根据管理员的角色ID查询菜单,目前支持模块化权限验证 var roleModel = db.Queryable <sysrolemenu>().Where(m => m.RoleID == model.RoleID).ToList(); var mlist = roleModel.Select(item => item.MenuID).ToList(); //根据角色关联的菜单ID,查询菜单集合 var menuList = db.Queryable <sysmenu>().Where(m => mlist.Contains(m.ID)).ToList(); var adminModel = new AdminModel() { ID = model.ID, sysadmin = model, sysMenu = menuList }; //将用户登录信息保存的session中 SessionHelper.SetSession(KeyHelper.SESSION_ADMIN_INFO, ProtobufHelper.Serialize(adminModel)); //将登录ID保存到cookie中 CookieHelper.SetCookie(KeyHelper.COOKIE_ADMIN_USERID, DES3Encrypt.EncryptString(model.ID.ToString()), 1); } else { json.status = 403; json.msg = "您的账号被冻结,请联系管理员~"; } } else { json.status = 402; json.msg = "密码错误~"; } } else { json.status = 401; json.msg = "用户名错误~"; } return(json); }
public async Task <ApiResult <string> > Put(string Id, EditSysUserDto Params) { ApiResult <string> res = new ApiResult <string>(); //开启事务 try { SysUser userInfo = _mapper.Map <SysUser>(Params); if (!UniversalTool.ModuleIsNull(userInfo)) { userInfo.Id = Id; await _userService.UpdateAsync(userInfo); } if (string.IsNullOrEmpty(Params.UserPassword) || Params.UserPassword == "********") { Params.UserPassword = null; Params.PasswordSecurity = null; } SysUserLogon userLogonInfo = _mapper.Map <SysUserLogon>(Params); if (!UniversalTool.ModuleIsNull(userLogonInfo)) { SysUserLogon sysUserLogon = await _userLogonService.QueryFirstAsync(s => s.UserId == Id); if (!string.IsNullOrEmpty(Params.UserPassword) && Params.UserPassword != "********") { userLogonInfo.PasswordSecurity = UniversalTool.PassSecurityValidation(userLogonInfo.UserPassword); userLogonInfo.UserSecretkey = Md5Crypt.Encrypt(Guid.NewGuid().ToString()); userLogonInfo.UserPassword = Md5Crypt.Encrypt(DES3Encrypt.EncryptString(userLogonInfo.UserPassword.ToLower(), userLogonInfo.UserSecretkey).ToLower(), false).ToLower(); } userLogonInfo.Id = sysUserLogon.Id; await _userLogonService.UpdateAsync(userLogonInfo); } } catch (Exception ex) { res.code = (int)ApiEnum.Error; res.message = "异常:" + ex.Message; } //事务结束 return(await Task.Run(() => res)); }
/// <summary> /// 添加部门信息 /// </summary> /// <param name="parm"></param> /// <returns></returns> public new async Task <ApiResult <string> > AddAsync(SysAdmin parm) { var res = new ApiResult <string> { statusCode = 200, data = "1" }; try { //判断用吗是否存在 var isExisteName = SysAdminDb.IsAny(m => m.LoginName == parm.LoginName); if (isExisteName) { res.message = "用户名已存在,请更换~"; res.statusCode = (int)ApiEnum.ParameterError; return(await Task.Run(() => res)); } parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd); if (string.IsNullOrEmpty(parm.HeadPic)) { parm.HeadPic = "/themes/img/avatar.jpg"; } parm.Guid = Guid.NewGuid().ToString(); parm.AddDate = DateTime.Now; if (!string.IsNullOrEmpty(parm.DepartmentGuid)) { // 说明有父级 根据父级,查询对应的模型 var model = SysOrganizeDb.GetById(parm.DepartmentGuid); parm.DepartmentGuidList = model.ParentGuidList; } SysAdminDb.Insert(parm); } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; res.statusCode = (int)ApiEnum.Error; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(await Task.Run(() => res)); }
/// <summary> /// 根据用户名密码获取用户信息 /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> public async Task <ApiResult <SysUser> > UserNameAndPassQueryAsync(string username, string password) { var res = new ApiResult <SysUser>(); res.data = new SysUser(); try { var userInfo = await Db.Queryable <SysUser>() .Where(s => s.Account == username) .Mapper(it => it.sysUserLogon, it => it.sysUserLogon.UserId) .FirstAsync(); if (userInfo != null) { password = Md5Crypt.Encrypt(DES3Encrypt.EncryptString(password.ToLower(), userInfo.sysUserLogon.UserSecretkey).ToLower(), false).ToLower(); if (userInfo.sysUserLogon.UserPassword.Equals(password)) { res.data = userInfo; } else { res.code = (int)ApiEnum.Failure; res.message = "账号错误,请重新输入"; } } else { res.code = (int)ApiEnum.Failure; res.message = "用户不存在"; } } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; res.code = (int)ApiEnum.Error; } return(res); }
/// <summary> /// 用户登录实现 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <SysAdmin> > LoginAsync(SysAdminLogin parm) { var res = new ApiResult <SysAdmin>(); try { parm.password = DES3Encrypt.EncryptString(parm.password); var model = Db.Queryable <SysAdmin>() .Where(m => m.LoginName == parm.loginname).First(); if (model != null) { if (model.LoginPwd.Equals(parm.password)) { res.success = true; res.message = "获取成功!"; res.data = model; } else { res.success = false; res.statusCode = (int)ApiEnum.Error; res.message = "密码错误~"; } } else { res.success = false; res.statusCode = (int)ApiEnum.Error; res.message = "账号错误~"; } } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; res.statusCode = (int)ApiEnum.Error; } return(await Task.Run(() => res)); }
/// <summary> /// 修改菜单 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <string> > ModifyAsync(SysAdmin parm) { var res = new ApiResult <string> { statusCode = (int)ApiEnum.Error }; try { //修改,判断用户是否和其它的重复 var isExisteName = await Db.Queryable <SysAdmin>().AnyAsync(m => m.LoginName == parm.LoginName && m.Guid != parm.Guid); if (isExisteName) { res.message = "用户名已存在,请更换~"; res.statusCode = (int)ApiEnum.ParameterError; return(await Task.Run(() => res)); } parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd); if (!string.IsNullOrEmpty(parm.DepartmentGuid)) { // 说明有父级 根据父级,查询对应的模型 var model = SysOrganizeDb.GetById(parm.DepartmentGuid); parm.DepartmentGuidList = model.ParentGuidList; } //查询授权表,type=2 更新新的权限值 //删除 var authority = await Db.Deleteable <SysPermissions>().Where(m => m.AdminGuid == parm.Guid && m.Types == 2).ExecuteCommandAsync(); //添加新的 var authorityList = new List <SysPermissions>(); foreach (var item in parm.RoleList) { authorityList.Add(new SysPermissions() { RoleGuid = item.guid, AdminGuid = parm.Guid, Types = 2 }); } await Db.Insertable(authorityList).ExecuteCommandAsync(); var dbres = await Db.Updateable <SysAdmin>().SetColumns(m => new SysAdmin() { LoginName = parm.LoginName, LoginPwd = parm.LoginPwd, RoleGuid = parm.RoleGuid, DepartmentName = parm.DepartmentName, DepartmentGuid = parm.DepartmentGuid, DepartmentGuidList = parm.DepartmentGuidList, TrueName = parm.TrueName, Number = parm.Number, Sex = parm.Sex, Mobile = parm.Mobile, Email = parm.Email, Status = parm.Status }).Where(m => m.Guid == parm.Guid).ExecuteCommandAsync(); if (dbres > 0) { res.statusCode = (int)ApiEnum.Status; res.message = "更新成功!"; } else { res.message = "更新失败!"; } } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(res); }
/// <summary> /// 用户登录实现 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <SysAdminMenuDto> > LoginAsync(SysAdminLogin parm) { var res = new ApiResult <SysAdminMenuDto>() { statusCode = (int)ApiEnum.Error }; try { var adminModel = new SysAdminMenuDto(); parm.password = DES3Encrypt.EncryptString(parm.password); var model = await Db.Queryable <SysAdmin>().Where(m => m.LoginName == parm.loginname).FirstAsync(); if (model == null) { res.message = "账号错误"; return(res); } if (!model.LoginPwd.Equals(parm.password)) { res.message = "密码错误~"; return(res); } if (!model.Status) { res.message = "登录账号被冻结,请联系管理员~"; return(res); } var(isSystem, isAgent, isSubAdmin) = await roleService.GetRoleByAdminGuid(model.Guid); if (isSystem) { } else if (isAgent) { var exist = await Db.Queryable <CmsAgent>().AnyAsync(p => p.Admin_Guid == model.Guid && p.Status); if (!exist) { res.message = "代理商已经被冻结,请联系管理员"; return(res); } } else if (isSubAdmin) { var exist = await Db.Queryable <CmsMerchant>().AnyAsync(p => p.admin_guid == model.Guid && p.status); if (!exist) { res.message = "商户已经被冻结,请联系管理员"; return(res); } } else { var exist = await Db.Queryable <CmsMerchant>().AnyAsync(p => p.admin_guid == model.CreateBy && p.status); if (!exist) { res.message = "商户已经被冻结,请联系管理员"; return(res); } } adminModel.menu = GetMenuByAdmin(model.Guid); if (adminModel == null) { res.message = "当前账号没有授权功能模块,无法登录~"; return(res); } //修改登录时间 model.LoginDate = DateTime.Now; model.UpLoginDate = model.LoginDate; model.LoginSum = model.LoginSum + 1; SysAdminDb.Update(model); var roleList = await Db.Queryable <SysRole>().Where(m => m.IsSystem).Select(m => m.Guid).ToListAsync(); model.IsSystem = roleList.Intersect(model.RoleList.Select(p => p.guid)).Any(); res.statusCode = (int)ApiEnum.Status; adminModel.admin = model; res.data = adminModel; } catch (Exception ex) { res.message = ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(res); }
/// <summary> /// 异步添加种子数据 /// </summary> /// <param name="DbContext"></param> /// <returns></returns> public static async Task SeedAsync(BaseDbContext DbContext) { try { // 注意!一定要先手动创建一个空的数据库 // 会覆盖,可以设置为true,来备份数据 // 如果生成过了,第二次,就不用再执行一遍了,注释掉该方法即可 DbContext.CreateTableByEntity(false, typeof(SysLog), typeof(SysUser), typeof(SysUserLogon), typeof(SysOrganize), typeof(SysRole), typeof(SysModule), typeof(SysModuleAction), typeof(SysRoleAuthorize), typeof(SysRoleAuthorizeAction), typeof(SysMessage)); #region 追加种子数据 string UserId = Guid.NewGuid().ToString(); string RoleId = Guid.NewGuid().ToString(); string OrganizeId = Guid.NewGuid().ToString(); string ModuleId = Guid.NewGuid().ToString(); string UserSecretkey = Guid.NewGuid().ToString(); if (!await DbContext.Db.Queryable <SysUser>().AnyAsync()) { DbContext.Db.Insertable(new SysOrganize() { Id = OrganizeId, ParentId = "00000000-0000-0000-0000-000000000000", Category = "GROUP", FullName = "仓单系统总管理", FullNameEn = "", ShortName = "仓单系统总管理", DeleteMark = false, DeleteUserId = "", DeleteTime = null, Description = "", IsExpand = true, EnabledMark = true, SortCode = 1, CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable(new SysRole() { Id = RoleId, OrganizeId = OrganizeId, ParentId = "00000000-0000-0000-0000-000000000000", Category = "FATHER", FullName = "系统管理员", FullNameEn = "", DeleteMark = false, DeleteUserId = "", DeleteTime = null, Description = "", IsExpand = true, EnabledMark = true, SortCode = 1, CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable(new SysUser() { Id = UserId, RoleId = RoleId, OrganizeId = OrganizeId, Account = "admin", HeadIcon = "https://b-ssl.duitang.com/uploads/item/201508/12/20150812204143_KHCAQ.thumb.700_0.jpeg", WeChat = "", Tel = "", Birthday = null, RealName = "管理员", Email = "*****@*****.**", Token = "", IsAdministrator = true, Description = "", EnabledMark = true, SortCode = 1, CreatorTime = DateTime.Now, CreatorId = "00000000-0000-0000-0000-000000000000" }).ExecuteCommand(); DbContext.Db.Insertable(new SysUserLogon() { Id = Guid.NewGuid().ToString(), UserId = UserId, Theme = "", Language = "", MultiUserLogin = false, LogOnCount = 0, UserSecretkey = UserSecretkey, PasswordSecurity = UniversalTool.PassSecurityValidation("123456"), UserPassword = Md5Crypt.Encrypt(DES3Encrypt.EncryptString("123456".ToLower(), UserSecretkey).ToLower(), false).ToLower(), }).ExecuteCommand(); DbContext.Db.Insertable(new SysLog() { Id = Guid.NewGuid().ToString(), Account = "系统", NickName = "DbInit", ModuleName = "SeedInitAsync", Result = "OK", ResultData = "初始化数据库所有基础表 和 数据", CreatorUserId = UserId, CreatorTime = DateTime.Now, }).ExecuteCommand(); //主菜单 DbContext.Db.Insertable <SysModule>(new SysModule() { Id = ModuleId, ParentId = "00000000-0000-0000-0000-000000000000", FullName = "系统", FullNameEn = "", Icon = "", UrlAddress = "", ApiUrl = "", IsMenu = true, IsExpand = true, Description = "系统", SortCode = 99, EnabledMark = true, CreatorTime = DateTime.Now, CreatorUserId = UserId, DeleteMark = false, DeleteTime = null, DeleteUserId = null, }).ExecuteCommand(); //子菜单 用户 string userModuleId = Guid.NewGuid().ToString(); DbContext.Db.Insertable <SysModule>(new SysModule() { Id = userModuleId, ParentId = ModuleId, FullName = "用户管理", FullNameEn = "SysUser", Icon = "", UrlAddress = "/SysAdmin/user", ApiUrl = "/Api/SysUser", IsMenu = false, IsExpand = false, Description = "用户管理", SortCode = 4, EnabledMark = true, CreatorTime = DateTime.Now, CreatorUserId = UserId, DeleteMark = false, DeleteTime = null, DeleteUserId = null, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = userModuleId, ActionName = "", RequestMethod = "POST", ACL = "POST", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = userModuleId, ActionName = "", RequestMethod = "PUT", ACL = "PUT", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = userModuleId, ActionName = "", RequestMethod = "GET", ACL = "GET", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = userModuleId, ActionName = "", RequestMethod = "DELETE", ACL = "DELETE", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = userModuleId, ActionName = "GetUserDetails", RequestMethod = "GET", ACL = "GetUserDetails", EnabledMark = true, Description = "获取用户详情 个人中心信息编辑", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = userModuleId, ActionName = "GetTokenUserDetails", RequestMethod = "GET", ACL = "GetTokenUserDetails", EnabledMark = true, Description = "获取用户详情根据Token", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); //子菜单 角色 string roleModuleId = Guid.NewGuid().ToString(); DbContext.Db.Insertable <SysModule>(new SysModule() { Id = roleModuleId, ParentId = ModuleId, FullName = "角色管理", FullNameEn = "SysUser", Icon = "", UrlAddress = "/SysAdmin/role", ApiUrl = "/Api/SysRole", IsMenu = false, IsExpand = false, Description = "角色管理", SortCode = 3, EnabledMark = true, CreatorTime = DateTime.Now, CreatorUserId = UserId, DeleteMark = false, DeleteTime = null, DeleteUserId = null, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = roleModuleId, ActionName = "", RequestMethod = "POST", ACL = "POST", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = roleModuleId, ActionName = "", RequestMethod = "PUT", ACL = "PUT", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = roleModuleId, ActionName = "", RequestMethod = "GET", ACL = "GET", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = roleModuleId, ActionName = "", RequestMethod = "DELETE", ACL = "DELETE", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = roleModuleId, ActionName = "GetRoleTreeList", RequestMethod = "GET", ACL = "GetRoleTreeList", EnabledMark = true, Description = "获取角色树", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); //子菜单 组织 string organizeModuleId = Guid.NewGuid().ToString(); DbContext.Db.Insertable <SysModule>(new SysModule() { Id = organizeModuleId, ParentId = ModuleId, FullName = "组织管理", FullNameEn = "SysUser", Icon = "", UrlAddress = "/SysAdmin/organize", ApiUrl = "/Api/SysOrganize", IsMenu = false, IsExpand = false, Description = "组织管理", SortCode = 2, EnabledMark = true, CreatorTime = DateTime.Now, CreatorUserId = UserId, DeleteMark = false, DeleteTime = null, DeleteUserId = null, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = organizeModuleId, ActionName = "", RequestMethod = "POST", ACL = "POST", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = organizeModuleId, ActionName = "", RequestMethod = "PUT", ACL = "PUT", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = organizeModuleId, ActionName = "", RequestMethod = "GET", ACL = "GET", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = organizeModuleId, ActionName = "", RequestMethod = "DELETE", ACL = "DELETE", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = organizeModuleId, ActionName = "GetOrganizeTreeList", RequestMethod = "GET", ACL = "GetOrganizeTreeList", EnabledMark = true, Description = "获取组织树", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); //子菜单 模块 string moduleModuleId = Guid.NewGuid().ToString(); DbContext.Db.Insertable <SysModule>(new SysModule() { Id = moduleModuleId, ParentId = ModuleId, FullName = "模块管理", FullNameEn = "SysUser", Icon = "", UrlAddress = "/SysAdmin/module", ApiUrl = "/Api/SysModule", IsMenu = false, IsExpand = false, Description = "模块管理", SortCode = 1, EnabledMark = true, CreatorTime = DateTime.Now, CreatorUserId = UserId, DeleteMark = false, DeleteTime = null, DeleteUserId = null, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = moduleModuleId, ActionName = "", RequestMethod = "POST", ACL = "POST", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = moduleModuleId, ActionName = "", RequestMethod = "PUT", ACL = "PUT", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = moduleModuleId, ActionName = "", RequestMethod = "GET", ACL = "GET", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = moduleModuleId, ActionName = "", RequestMethod = "DELETE", ACL = "DELETE", EnabledMark = true, Description = "", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = moduleModuleId, ActionName = "GetModuleTreeList", RequestMethod = "GET", ACL = "GetModuleTreeList", EnabledMark = true, Description = "获取模块树", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); DbContext.Db.Insertable <SysModuleAction>(new SysModuleAction() { Id = Guid.NewGuid().ToString(), ModuleId = moduleModuleId, ActionName = "GetModuleTreeAuthList", RequestMethod = "GET", ACL = "GetModuleTreeAuthList", EnabledMark = true, Description = "获取权限模块树", CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); //角色模块权限 foreach (var item in await DbContext.Db.Queryable <SysModule>().ToListAsync()) { //角色权限 DbContext.Db.Insertable <SysRoleAuthorize>(new SysRoleAuthorize() { Id = Guid.NewGuid().ToString(), RoleId = RoleId, ModuleId = item.Id, CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); } //角色模块按钮权限 foreach (var item in await DbContext.Db.Queryable <SysRoleAuthorize, SysModule, SysModuleAction>((sr, sm, sma) => new object[] { JoinType.Left, sr.ModuleId == sm.Id, JoinType.Left, sm.Id == sma.ModuleId, }) .Where((sr, sm, sma) => sma.Id != null) .Select((sr, sm, sma) => new { id = sr.Id, actionid = sma.Id }).ToListAsync()) { //角色权限 DbContext.Db.Insertable <SysRoleAuthorizeAction>(new SysRoleAuthorizeAction() { Id = Guid.NewGuid().ToString(), RoleAuthId = item.id, ModuleActionId = item.actionid, CreatorTime = DateTime.Now, CreatorUserId = UserId, }).ExecuteCommand(); } } #endregion } catch (Exception ex) { } }
/// <summary> /// 用户登录实现 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <SysAdmin> > LoginAsync(SysAdminLogin parm) { var res = new ApiResult <SysAdmin>(); try { parm.password = DES3Encrypt.EncryptString(parm.password); var model = DbContext._.Db.From <SysAdmin>().Where(d => d.LoginName == parm.loginname).ToFirstDefault(); if (model != null) { if (!model.Status) { res.success = false; res.statusCode = (int)ApiEnum.Error; res.message = "账号冻结~"; } else { if (model.LoginPwd.Equals(parm.password)) { //修改登录时间 model.LoginDate = DateTime.Now; model.UpLoginDate = model.LoginDate; //SysAdminDb.Update(model); DbContext._.Db.Update <SysAdmin>(model, d => d.Guid == model.Guid); #region 保存操作日志 //var logModel = new SysLog() //{ // Guid = Guid.NewGuid().ToString(), // LoginName = model.LoginName, // DepartName = model.DepartmentName, // OptionTable = "SysAdmin", // Summary = "登录操作", // IP = Utils.GetIp(), // LogType = (int)LogEnum.Login, // Urls = Utils.GetUrl(), // AddTime = DateTime.Now //}; //SysLogDb.Insert(logModel); #endregion res.success = true; res.message = "获取成功!"; res.data = model; } else { res.success = false; res.statusCode = (int)ApiEnum.Error; res.message = "密码错误~"; } } } else { res.success = false; res.statusCode = (int)ApiEnum.Error; res.message = "账号错误~"; } } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; res.statusCode = (int)ApiEnum.Error; } return(await Task.Run(() => res)); }
/// <summary> /// 添加部门信息 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(SysAdmin parm) { var res = new ApiResult <string> { statusCode = (int)ApiEnum.ParameterError }; try { //判断用吗是否存在 var isExisteName = await Db.Queryable <SysAdmin>().AnyAsync(m => m.LoginName == parm.LoginName); if (isExisteName) { res.message = $"用户名【{parm.LoginName}】已经存在"; return(res); } if (parm.RoleList == null || parm.RoleList.Count == 0) { res.message = $"请至少选择一个角色"; return(res); } parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd); if (string.IsNullOrEmpty(parm.Guid)) { parm.Guid = Guid.NewGuid().ToString(); } parm.AddDate = DateTime.Now; using var tran = new TransactionScope(); var succ = SysAdminDb.Insert(parm); var authorityList = parm.RoleList .Select(p => new SysPermissions { RoleGuid = p.guid, AdminGuid = parm.Guid, Types = 2 }).ToList(); await Db.Insertable(authorityList).ExecuteCommandAsync(); tran.Complete(); //var rel = await Db.Queryable<CmsAdminMerchantRel>().Where(p => p.Admin_Guid == parm.CreateBy).FirstAsync(); //if (rel != null) //{ // CmsAdminMerchantRelDb.Insert(new CmsAdminMerchantRel // { // Admin_Guid = parm.Guid, // Out_Mch_Id = rel.Out_Mch_Id, // out_sub_mch_id = rel.out_sub_mch_id // }); //} res.statusCode = (int)ApiEnum.Status; res.data = parm.Guid; } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(res); }