Пример #1
0
        /// <summary>
        /// 新建用户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private async Task <ResponseBase> AddUser(SaveUserRequest request)
        {
            if (await _sysUserBll.ExistSysUserByAccount(request.Account))
            {
                return(new ResponseBase().GetResponseError(StatusCode.User40002, "用户帐号已存在"));
            }
            var userRole = _sysUserRoleBll.GetSysUserRole(request.UserRoleId);

            if (userRole == null)
            {
                return(new ResponseBase().GetResponseError(StatusCode.UserRole30001, "角色不存在"));
            }
            var user = new SysUser()
            {
                NickName       = request.NickName,
                AuthorityValue = string.Empty,
                Account        = request.Account,
                UserRoleId     = request.UserRoleId,
                DataFlag       = (int)DataFlagEnum.Normal,
                DataLimitArea  = string.Empty,
                DataLimitShop  = string.Empty,
                LastLoginTime  = null,
                StatusFlag     = request.StatusFlag,
                Pwd            = CryptogramHelper.Encrypt3DES(request.Password),
                DataLimitType  = (int)DataLimitTypeEnum.Area
            };
            await _sysUserBll.AddUser(user);

            return(ResponseBase.Success());
        }
Пример #2
0
        /// <summary>
        /// url加密
        /// </summary>
        /// <param name="this"></param>
        /// <returns></returns>
        public static string UrlEncode(this object @this)
        {
            var str = @this.ToString().Trim();

            if (string.IsNullOrWhiteSpace(str))
            {
                return(string.Empty);
            }
            return(HttpUtility.UrlEncode(CryptogramHelper.Encrypt3DES(str)));
        }
Пример #3
0
        /// <summary>
        /// 重置用户密码
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ResponseBase> ProcessAction(ResetPasswordRequest request)
        {
            var user = await _sysUserBll.GetSysUser(request.UserId);

            if (user == null)
            {
                return(new ResponseBase().GetResponseError(StatusCode.User40001, "用户不存在"));
            }
            var newPwd = CryptogramHelper.Encrypt3DES(request.NewPassword);
            await _sysUserBll.ChangePassword(request.UserId, newPwd);

            return(ResponseBase.Success());
        }
Пример #4
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ResponseBase> ProcessAction(ChangePasswordRequest request)
        {
            var user = await _sysUserBll.GetSysUser(request.LoginUserId);

            var oldPwd = CryptogramHelper.Encrypt3DES(request.OldPassword);

            if (oldPwd != user.Pwd)
            {
                return(new ResponseBase().GetResponseError(StatusCode.User40004, "旧密码不正确"));
            }
            var newPwd = CryptogramHelper.Encrypt3DES(request.NewPassword);
            await _sysUserBll.ChangePassword(request.LoginUserId, newPwd);

            return(ResponseBase.Success());
        }
Пример #5
0
        /// <summary>
        /// 根据用户id生成token
        /// </summary>
        /// <param name="userId">用户的id</param>
        /// <returns>token内容</returns>
        public static string GetJwt(int userId)
        {
            var now = DateTime.UtcNow;

            var claims = new Claim[]
            {
                new Claim(JwtRegisteredClaimNames.Sub, CryptogramHelper.Encrypt3DES(userId.ToString(), UidKey)),
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                new Claim(JwtRegisteredClaimNames.Iat, now.ToUniversalTime().ToString(),
                          ClaimValueTypes.Integer64),
            };
            var jwt = new JwtSecurityToken(
                claims: claims,
                notBefore: now,
                expires: DateTime.Now.AddMinutes(TokenTimeOut),
                signingCredentials: new SigningCredentials(GetSecretKey(), SecurityAlgorithms.HmacSha256)
                );
            var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt);

            return(encodedJwt);
        }
Пример #6
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="httpContext"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ResponseBase> ProcessAction(HttpContext httpContext, LoginRequest request)
        {
            var response = new ResponseBase();

            if (!await CheckUserLoginFailedRecord(request.UserAccount))
            {
                return(response.GetResponseError(StatusCode.Login20003, "登录失败次数超过限制"));
            }
            if (string.IsNullOrEmpty(request.UserAccount) || string.IsNullOrEmpty(request.UserPassword))
            {
                return(response.GetResponseBadRequest());
            }
            var pwd  = CryptogramHelper.Encrypt3DES(request.UserPassword);
            var user = await _sysUserBll.GetSysUser(request.UserAccount, pwd);

            if (user == null)
            {
                await _sysUserBll.AddUserLoginFailedRecord(request.UserAccount, SystemConfig.UserLoginConfig.LoginFailedMaxCount, SystemConfig.UserLoginConfig.LoginFailedTimeOut);

                return(response.GetResponseError(StatusCode.Login20001, "帐号或密码错误"));
            }
            if (user.StatusFlag == (int)UserStatusFlagEnum.Disable)
            {
                return(response.GetResponseError(StatusCode.Login20002, "帐号被禁用"));
            }
            var loginView = await GetLoginView(user);

            var userRole = await _sysUserRoleBll.GetSysUserRole(user.UserRoleId);

            AppTicket.SetAppTicket(httpContext, user, userRole);
            await _sysUserBll.UpdateUserLastLoginTime(user.UserId, DateTime.Now);

            await _sysUserBll.RemoveUserLoginFailedRecord(request.UserAccount);

            AddUserLoginLog(user);
            return(response.GetResponseSuccess(loginView));
        }
Пример #7
0
 /// <summary>
 /// url加密
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public static string UrlEncode(this string source)
 {
     return(UrlHelper.UrlEncode(CryptogramHelper.Encrypt3DES(source)));
 }