コード例 #1
0
        /// <summary>
        /// login
        /// </summary>
        /// <param name="loginParam"></param>
        /// <returns></returns>
        ResponseResult ISysUserService.Login(LoginParam loginParam)
        {
            var user = SysUserRepository.GetEntity(loginParam.LoginName);

            if (user == null)
            {
                Result.Msg  = "账号或密码错误";
                Result.Code = ResponseStatusCode.ERROR;
                return(Result);
            }
            var enPassword = KeyDerivationHelper.GetEncriptPassword(loginParam.Password, user.Salt);

            // byte[]存到binary =》 从十进制转换成了十六进制
            if (!user.Password.SequenceEqual(enPassword))
            {
                Result.Msg  = "账号或密码错误";
                Result.Code = ResponseStatusCode.ERROR;
                return(Result);
            }
            var token = JwtHelper.IssueJWT(new TokenModel()
            {
                Uid = user.Id
            }, APIAppsetting.JWTSecretKey);
            var path = SysFileRelationService.GetUserHeadImgPath(user.Id, Model.Enum.UploadType.UserPicture);

            Result.Data = new { token, name = user.Name, avatar = path, email = user.Phone };
            Result.Msg  = "登录成功";
            Result.Code = ResponseStatusCode.OK;
            return(Result);
        }
コード例 #2
0
        /// <summary>
        /// 更新密码
        /// </summary>
        /// <param name="id"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public ResponseResult UpdatePassword(int id, string password)
        {
            if (password == null)
            {
                Result.Msg = "密码不能为空";
                return(Result);
            }
            var user = SysUserRepository.GetEntity(id);

            if (user == null)
            {
                Result.Msg = "该用户不存在";
                return(Result);
            }
            var encriptPassword = KeyDerivationHelper.GetEncriptPassword(password, user.Salt);

            user.Password = encriptPassword;
            var r = SysUserRepository.Update(user, f => new { f.Password });

            if (!r)
            {
                Result.Msg = "更新密码失败,请联系管理员";
                return(Result);
            }

            Result.Msg  = "更新密码成功";
            Result.Code = ResponseStatusCode.OK;
            return(Result);
        }
コード例 #3
0
        public override ResponseResult Add(SysUser t)
        {
            if (SysUserRepository.GetEntity(t.Account) != null)
            {
                Result.Msg = "该用户名已存在";
                return(Result);
            }

            t.Password = KeyDerivationHelper.GetEncriptPassword(t.Account, out byte[] bt);
            t.Salt     = bt;
            return(base.Add(t));
        }