Exemple #1
0
        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));
        }
Exemple #2
0
        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));
        }