Ejemplo n.º 1
0
        public async Task <IActionResult> SignIn(AppUserLoginDto appUserLoginDto)
        {
            var appUser = await _appUserService.FindByUserName(appUserLoginDto.UserName);

            if (appUser == null)
            {
                return(BadRequest("Username or password is incorrect."));
            }
            else
            {
                if (await _appUserService.CheckPassword(appUserLoginDto))
                {
                    var roles = await _appUserService.GetRolesByUserName(appUserLoginDto.UserName);

                    var            token          = _jwtService.GenerateJwtToken(appUser, roles);
                    JwtAccessToken jwtAccessToken = new JwtAccessToken();
                    jwtAccessToken.Token = token;
                    return(Created("", jwtAccessToken));
                }
                else
                {
                    return(BadRequest("Username or password is incorrect."));
                }
            }
        }
        public async Task <IActionResult> SignIn(AppUserLoginDto loginDto)
        {
            if (ModelState.IsValid)
            {
                AppUser appUser = await appUserService.FindByUserName(loginDto.UserName);

                if (appUserService.CheckPassword(loginDto, appUser) && appUser != null)
                {
                    ICollection <AppRole> roles = await appUserService.GetRolesByUserName(loginDto.UserName);

                    AppUserDto appUserDto = accountHelper.GenerateAppUserDto(appUser, roles);
                    appUserSessionService.Set(appUserDto);
                    logger.LogInformation($"{appUser.UserName} kullanıcısı giriş yaptı");
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    logger.LogInformation($"{loginDto.UserName} Kullanici adi veya parola hatali ");
                    ModelState.AddModelError("", "Kullanici adi veya parola hatali");
                    return(View(loginDto));
                }
            }
            else
            {
                logger.LogInformation("AppUserLoginDto Not Valid");
                ModelState.AddModelError("", "Lütfen gereken tüm alanları doldurunuz");
                return(View(loginDto));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> SignIn(AppUserLoginDto appUserLoginDto)
        {
            // userName =>  var mı ?
            // password => eşleniyor mu ?

            var appUser = await _appUserService.FindByUserName(appUserLoginDto.UserName);

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

                    var token = _jwtService.GenereateJwtToken(appUser, roles);

                    JwtAccessToken jwtAccessToken = new JwtAccessToken();
                    jwtAccessToken.Token = token;
                    return(Created("", jwtAccessToken));
                }

                return(BadRequest("Kullanıcı adı veya şifre hatalı"));
            }
        }
        //[ValidModel]
        public async Task <IActionResult> SignIn([FromBody] AppUserLoginDto appUserLoginDto)
        {
            try
            {
                var appUser = await _appUserService.FindByUsername(appUserLoginDto.Username);

                if (appUser == null)
                {
                    return(BadRequest("Kullanıcı adı veya şifre hatalı"));
                }
                else
                {
                    if (await _appUserService.CheckPassword(appUserLoginDto))
                    {
                        var roles = await _appUserService.GetRolesByUsername(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ı"));
                }
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }
Ejemplo n.º 5
0
 public async Task<IActionResult> Login([FromBody] AppUserLoginDto appUserLoginDto)
 {
     List<ErrorModel> errorModels = new List<ErrorModel>();
     var user = await _appUserService.FindByUserName(appUserLoginDto.Username);
     if (user == null)
     {
         var error = new ErrorModel()
         {
             FieldName = "Username",
             Message = $"{appUserLoginDto.Username} doesn't match."
         };
         errorModels.Add(error);
         var response = new ErrorResponse()
         {
             Errors = errorModels
         };
         return BadRequest(response);
     }
     else
     {
         if (_appUserService.CheckPassword(appUserLoginDto).Result)
         {
             var roles = await _appUserService.GetRolesByUserName(appUserLoginDto.Username);
             var token = _jwtService.GenerateJwt(user, roles);
             LoginSuccessDto loginSuccessDto = new LoginSuccessDto()
             {
                 Token = token,
                 Email = user.Email,
                 Username = user.Username,
                 ProfileImage = user.ProfileImage
             };
             return Ok(loginSuccessDto);
         }
         var error = new ErrorModel()
         {
             FieldName = "Password",
             Message = "Password doesn't match."
         };
         errorModels.Add(error);
         var response = new ErrorResponse()
         {
             Errors = errorModels
         };
         return BadRequest(response);
     }
 }
Ejemplo n.º 6
0
        public async Task <IActionResult> SignIn(AppUserLoginDto appUserLoginDto)
        {
            var appUser = await _appUserService.FindByUserName
                              (appUserLoginDto.UserName);

            if (appUser == null)
            {
                return(BadRequest("Username or password entered incorrectly"));
            }
            else
            {
                if (await _appUserService.CheckPassword(appUserLoginDto))
                {
                    var roles = await _appUserService.GetRolesByUserName(appUserLoginDto.UserName);

                    var token = _jwtService.GenerateJwt(appUser, roles);
                    return(Created("", token));
                }
                return(BadRequest("Username or password entered incorrectly"));
            }
        }