Exemple #1
0
        public async Task <ResultModel> Register(RegisterUserInfo userDto)
        {
            var user = MiCakeApp.User.Create(userDto.Act, userDto.Pwd, userDto.Avatar, userDto.Gender);
            await _userRepo.AddAsync(user);

            var token = _jwtSupporter.CreateToken(user);

            var userRes = new LoginResultDto()
            {
                AccessToken = token, HasUser = true, UserInfo = user.Adapt <UserDto>()
            };

            return(new ResultModel(0, "", userRes));
        }
Exemple #2
0
        public async Task <LoginResultDto> Register(RegisterUserDto registerInfo)
        {
            var user = MiCakeApp.User.Create(registerInfo.Phone, registerInfo.Password, registerInfo.Name, registerInfo.Age);
            await _userRepo.AddAsync(user);

            var token = _jwtSupporter.CreateToken(user);

            return(new LoginResultDto()
            {
                AccessToken = token, HasUser = true, UserInfo = null
            });
        }
        private string CreateToken(string userKey, bool userLock, string userRoles)
        {
            var claims = new List <Claim>()
            {
                new Claim("sub", userKey),
                new Claim("lockout", userLock ? "1":"0"),
            };

            if (!string.IsNullOrWhiteSpace(userRoles))
            {
                claims.Add(new Claim(ClaimTypes.Role, userRoles));
            }

            return(_jwtSupporter.CreateToken(new ClaimsIdentity(claims)));
        }
        public async Task <LoginResultDto> Login(LoginDto loginInfo)
        {
            CheckCode(loginInfo.Code);

            var user = await _userRepo.FindUserByPhone(loginInfo.Phone);

            if (user == null)
            {
                return(LoginResultDto.NoUser());
            }

            var token = _jwtSupporter.CreateToken(user);

            return(new LoginResultDto()
            {
                AccessToken = token, HasUser = true, UserInfo = user.Adapt <UserDto>()
            });
        }
        public async Task <WeChatLoginDto> Login(string key)
        {
            CheckValue.NotNullOrWhiteSpace(key, nameof(key));

            var weChatSessionInfo = await _weChatSessionStore.GetSessionInfo(key) ?? throw new ArgumentException("没有找到匹配的微信密匙信息");

            var anyUser = await _wechatRepository.GetUserIdWithOpenId(weChatSessionInfo.OpenId);

            if (anyUser == default)
            {
                return(WeChatLoginDto.NoUser(key));
            }

            var user = await _userRepository.FindAsync(anyUser);

            var token = _jwtSupporter.CreateToken(user);

            return(new WeChatLoginDto()
            {
                AccessToken = token, HasUser = true, UserInfo = user.Adapt <UserDto>()
            });
        }