예제 #1
0
        public async Task <ApiResult <JsonWebToken> > Login([FromQuery] BasicInput basicInput, [FromBody] LoginInput input,
                                                            [FromServices] ILoginService loginService)
        {
            //var validResult = verifyCodeService.CheckCode(input.VerifyCodeId, input.VerifyCode, false);
            //if (!validResult)
            //{
            //    return Result<JsonWebToken>(CommonStatusCode.VerifyCodeError);
            //}

            var(code, userInfo) = await loginService.LoginAsync(
                Request.GetString("appKey"),
                input.Account.FromBase64String(),
                input.Password.FromBase64String());

            if (code != DefaultStatusCode.Success)
            {
                return(Result <JsonWebToken>(code));
            }

            //生成Token
            var entry = new JwtTokenEntity
            {
                AppId      = userInfo.AppId.ToString(),
                UserId     = userInfo.Id.ToString(),
                RoleIds    = string.Join(',', userInfo.RoleIds),
                ClientType = basicInput.ClientType.ToString(),
                Nickname   = userInfo.Nickame,
                Email      = userInfo.Email,
                Phone      = userInfo.Phone
            };
            var token = await _jwtTokenService.CreateTokenAsync(entry);

            return(Result(DefaultStatusCode.Success, token));
        }
예제 #2
0
        public async Task <UserReturn> Login(LoginInfo loginInfo)
        {
            var user = await _userManager.Users
                       .SingleOrDefaultAsync(user => user.UserName == loginInfo.UserName.ToLower());

            if (user == null)
            {
                throw new Exception("Invalid UserName");
            }

            var result = await _signInManager
                         .CheckPasswordSignInAsync(user, loginInfo.Password, false);

            if (!result.Succeeded)
            {
                throw new Exception("Invalid Password");
            }

            return(new UserReturn
            {
                Id = user.Id,
                AccessToken = await _tokenService.CreateTokenAsync(user)
            });
        }