示例#1
0
        public async Task <BaseResponse <AccessToken> > SignIn(SigninViewModelResource signinViewModel)
        {
            AppUser user = await userManager.FindByEmailAsync(signinViewModel.Email);

            if (user != null)
            {
                bool isUser = await userManager.CheckPasswordAsync(user, signinViewModel.Password);

                if (isUser)
                {
                    AccessToken  acessToken               = _tokenHandle.CreateAccessToken(user);
                    Claim        refreshTokenClaim        = new Claim("refreshToken", acessToken.RefreshToken);
                    Claim        refreshTokenEndDateClaim = new Claim("refreshTokenEndDate", DateTime.Now.AddMinutes(_tokenOptions.RefreshTokenExpiration).ToString());
                    List <Claim> refreshClaimList         = userManager.GetClaimsAsync(user).Result.Where(x => x.Type.Contains("refreshToken")).ToList();
                    if (refreshClaimList.Any())
                    {
                        await userManager.ReplaceClaimAsync(user, refreshClaimList[0], refreshTokenClaim);

                        await userManager.ReplaceClaimAsync(user, refreshClaimList[1], refreshTokenEndDateClaim);
                    }
                    else
                    {
                        await userManager.AddClaimsAsync(user, new[] { refreshTokenClaim, refreshTokenEndDateClaim });
                    }
                    return(new BaseResponse <AccessToken>(acessToken));
                }
                return(new BaseResponse <AccessToken>("Email ve ya sifre sehvdir"));
            }
            return(new BaseResponse <AccessToken>("Email ve ya sifre sehvdir"));
        }
示例#2
0
        public async Task <IActionResult> SignIn(SigninViewModelResource signinViewModelResource)
        {
            var response = await this.authenticationService.SignIn(signinViewModelResource);

            if (response.Success)
            {
                return(Ok(response.Extra));
            }
            else
            {
                return(BadRequest(response.Message));
            }
        }