Пример #1
0
        public async Task <IActionResult> Login([FromBody] LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ResponseModel(400, "Invalid value was entered! Please, redisplay form.")));
            }

            var userId = await _appUserService.GetUserIdAsync(model.Email);

            if (userId < 1)
            {
                return(BadRequest(new ResponseModel(400, "Failed", "User not found.")));
            }

            var passwordIsRight = await _appUserService.CheckPasswordAsync(userId, model.Password);

            if (!passwordIsRight)
            {
                return(BadRequest(new ResponseModel(400, "Failed", "Wrong password.")));
            }

            var token = _appUserService.GenerateToken(userId, _configuration["Jwt:Key"], _configuration["Jwt:ExpireTime"]);

            return(Ok(new { Token = token }));
        }
Пример #2
0
        public async Task <IActionResult> SignIn(AppUserLoginDto appUserLoginDto)
        {
            var appUser = await _appUserService.FindByUserNameAsync(appUserLoginDto.UserName);

            if (appUser == null)
            {
                return(BadRequest("kullanıcı adı veya şifre hatalı"));
            }
            else
            {
                if (await _appUserService.CheckPasswordAsync(appUserLoginDto))
                {
                    var roles = await _appUserService.GetRolesByUserNameAsync(appUserLoginDto.UserName);

                    var            token          = _jwtService.GenerateJwt(appUser, roles);
                    JwtAccessToken jwtAccessToken = new JwtAccessToken();
                    jwtAccessToken.Token = token;
                    return(Created("", jwtAccessToken));
                }
                return(BadRequest("kullanıcı adı veya şifre hatalı"));
            }
        }
Пример #3
0
        public async Task <IActionResult> Signin(AppUserSigninDto appUserSigninDto)
        {
            var appUser = await _appUserService.FindByUserNameAsync(appUserSigninDto.UserName);

            if (appUser != null)
            {
                if (await _appUserService.CheckPasswordAsync(appUserSigninDto))
                {
                    var roles = await _appUserService.GetRolesByUserNameAsync(appUserSigninDto.UserName);

                    var token = _jwtService.GenerateJwt(appUser, roles);
                    return(Created("", token));
                }
                else
                {
                    return(BadRequest("hata"));
                }
            }
            else
            {
                return(BadRequest("Wrong UserName or Password !"));
            }
        }