public async Task <bool> CheckPasswordAsync(AppUserLoginDto appUserLoginDto) { var context = new JwtContext(); var appUser = await context.AppUsers.Where(x => x.UserName == appUserLoginDto.UserName).FirstOrDefaultAsync(); return(appUser.Password == appUserLoginDto.Password ? true : false); }
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ı")); } }
public async Task <IActionResult> Index(AppUserLoginDto model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); if (user != null) { if (await _userManager.IsEmailConfirmedAsync(user)) { var result = await _signInManager.PasswordSignInAsync(user, model.Password, model.RememberMe, false); if (result.Succeeded) { var role = await _userManager.GetRolesAsync(user); if (role.Contains("Admin")) { return(RedirectToAction("Index", "Home", new { area = "Admin" })); } else { return(RedirectToAction("Index", "Home", new { area = "Member" })); } } } else { ViewBag.Unconfirm = "Hesabınızı onaylıyınız!"; } } } return(View()); }
//[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)); } }
public async Task <IActionResult> Login(AppUserLoginDto model) { if (ModelState.IsValid) { var user = await _userManager.FindByNameAsync(model.Username); if (user != null) { var result = await _signInManager.PasswordSignInAsync(user, model.Password, false, false); if (result.Succeeded) { var role = await _userManager.GetRolesAsync(user); if (role.Contains("Admin")) { return(RedirectToAction("Index", "Forms", new { area = "Admin" })); } } } ModelState.AddModelError("", "Kullanıcı Adı veya şifre yanlış"); } return(View(model)); }
public async Task <IActionResult> SignIn(AppUserLoginDto model) { if (ModelState.IsValid) { var user = await _userManager.FindByNameAsync(model.UserName); if (user != null) { var identityResult = await _signInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, false); if (identityResult.Succeeded) { var userRoles = await _userManager.GetRolesAsync(user); if (userRoles.Contains("Admin")) { return(RedirectToAction("Index", "Home", new { area = "Admin" })); } else { return(RedirectToAction("Index", "Home", new { area = "Member" })); } } } ModelState.AddModelError("", "Kullanıcı adı veya şifre hatalı."); } return(View("Index", model)); }
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)); } }
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 <UsersLoginResultDto> Login(AppUserLoginDto userDto) { var user = await _userManager.FindByNameAsync(userDto.UserName); try { var result = await _signInManager.CheckPasswordSignInAsync(user, userDto.Password, false); if (!result.Succeeded) { throw new BusinessException("Неправильный логин или пароль"); } } catch (Exception) { throw new BusinessException("Неправильный логин или пароль"); } var appUser = await _userManager.Users .FirstOrDefaultAsync(u => u.NormalizedUserName == userDto.UserName.ToUpper()); var token = await GenerateJwtToken(appUser); return(new UsersLoginResultDto { Name = user.UserName, Token = token }); }
public async Task <IActionResult> Post([FromBody] AppUserLoginDto login) { // 实体映射转换 var command = new UserLoginCommand(login.Account, login.Password, login.VerificationCode); bool flag = await _mediator.Send(command); if (flag) { return(Ok(new { code = 20001, msg = $"{login.Account} 用户登录成功", data = login })); } else { return(Unauthorized(new { code = 40101, msg = $"{login.Account} 用户登录失败", data = login })); } }
public async Task <bool> CheckPassword(AppUserLoginDto appUserLoginDto) { var appUser = await _appUserDal.GetByFilterAsync (I => I.UserName == appUserLoginDto.UserName); return(appUser.Password == appUserLoginDto.Password ? true : false); }
public async Task <IActionResult> SignIn(AppUserLoginDto appUserLoginDto) { var user = await _appUserService.CheckUserAsync(appUserLoginDto); if (user != null) { return(Created("", _jwtService.GenerateJwt(user))); } return(BadRequest("Wrong username or password !")); }
public async Task <IActionResult> SignIn(AppUserLoginDto appUserLoginDto) { var user = await _appUserService.CheckUserAsync(appUserLoginDto); if (user != null) { return(Created("", _jwtService.GenerateJwt(user))); } return(BadRequest("kullanıcı adı veya şifre hatalı")); }
public async Task <bool> CheckPassword(AppUserLoginDto appUserLoginDto) { var appUser = await _appUserDal.GetByFilter(I => I.UserName == appUserLoginDto.UserName); if (appUser.Password == appUserLoginDto.Password) { return(true); } return(false); }
public async Task <IActionResult> Login2(AppUserLoginDto app) { if (ModelState.IsValid) { if (await authApi.Login(app)) { return(View()); } } return(Content("Login Başarısız")); }
public Task <AppUser> CheckUserAsync(AppUserLoginDto appUserLoginDto) { var appUser = _genericDal.GetAsync(p => p.UserName == appUserLoginDto.UserName && p.Password == appUserLoginDto.Password); if (appUser != null) { return(appUser); } else { return(null); } }
public async Task <IActionResult> SignIn(AppUserLoginDto model) { var user = await _appUserService.FindByEmail(model.Email); if (user != null && BCrypt.Net.BCrypt.Verify(model.Password, user.Password)) { var roles = await _appUserService.GetRolesByEmail(model.Email); var token = _jwtService.GenerateJwt(user, roles); return(Created("", new { token.Token, user.Id, expiresIn = 30 * 60 })); } return(BadRequest(new { Error = "Kullanıcı adı veya şifre yanlış.", ErrorType = "EMAIL_OR_PASSWORD_WRONG" })); }
public async Task <bool> CheckPassword(AppUserLoginDto appUserLoginDto) { var appUser = await _appUserDal.GetByFilter(x => x.Password == appUserLoginDto.Password); //await _appUserDal.GetByFilter(x => x.Password == appUserLoginDto.Password); //return appUser.Password == appUserLoginDto.Password ? true : false; if (appUser != null) { return(true); } return(false); }
public async Task <IActionResult> SignIn(AppUserLoginDto appUserLoginDto) { if (ModelState.IsValid) { if (await _appUserService.CheckUser(appUserLoginDto.Email, appUserLoginDto.Password)) { await CookieConfiguration(appUserLoginDto.Email, appUserLoginDto.Password, appUserLoginDto.RememberMe); //giriş başarılı return(RedirectToAction("Index", "Home", new { @area = "Admin" })); } //giriş başarısız ModelState.AddModelError("", "Kullanıcı adı yada parola hatalı."); } return(View(appUserLoginDto)); }
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); } }
public async Task <AppUser> Login(AppUserLoginDto appUserLoginDto) { var appUser = await _appUserService.GetByTCNumber(appUserLoginDto.TCNumber); if (appUser == null) { return(null); } if (!HashingHelper.VerifyPasswordHash(appUserLoginDto.Password, appUser.PasswordHash, appUser.PasswordSalt)) { return(null); } return(appUser); }
public async Task <IActionResult> Login([FromBody] AppUserLoginDto loginDto) { _logger.LogDebug($"[POST] api/auth/login"); if (null == loginDto) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var user = await _userManager.FindByUsernameAsync(loginDto.UserName); if (null == user) { return(BadRequest()); } if (!PasswordHasher.Match(loginDto.UserPassword, user.PasswordHash)) { return(BadRequest()); } var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_appConfig.TokenConfigs.Key)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var claims = AddClaims(user); var roles = AddRoles(user); var token = new JwtSecurityToken( issuer: _appConfig.TokenConfigs.Issuer, audience: _appConfig.TokenConfigs.Audience, claims: claims, expires: DateTime.UtcNow.AddMinutes(60), signingCredentials: creds ) { Payload = { ["roles"] = roles } }; return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token), expiration = token.ValidTo })); }
public async Task <IActionResult> Index(AppUserLoginDto loginDto) { if (ModelState.IsValid) { AppUser user = await _userManager.FindByNameAsync(loginDto.UserName); if (user != null) { var result = await _signInManager.PasswordSignInAsync(loginDto.UserName, loginDto.Password, false, false); return(RedirectToAction("Index", "Home", new { area = "Admin" })); } else { ModelState.AddModelError("", "Kullanıcı adı veya şifre hatalı"); } } return(View("Index", loginDto)); }
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")); } }
public async Task <IActionResult> Index(AppUserLoginDto loginDto) { var user = await _userManager.FindByEmailAsync(loginDto.Email); if (user != null) { var result = await _signInManager.PasswordSignInAsync(user, loginDto.Password, loginDto.RememberMe, false); if (result.Succeeded) { var role = await _userManager.GetRolesAsync(user); if (role.Contains("Admin")) { return(RedirectToAction("Index", "Home", new { area = "Admin" })); } return(RedirectToAction("Index", "Home", new { area = "Member" })); } } ModelState.AddModelError("", "Your e-mail address or password is not correct"); return(View(loginDto)); }
public async Task <IActionResult> LoginUser(AppUserLoginDto model) { var user = await userManager.FindByEmailAsync(model.Email); if (user is not null && await userManager.CheckPasswordAsync(user, model.Password)) { var TokenDescriptor = new SecurityTokenDescriptor() { Subject = new ClaimsIdentity(new Claim[] { new Claim("UserID", user.Id.ToString()) }), Expires = DateTime.UtcNow.AddDays(3), SigningCredentials = new SigningCredentials( new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration.GetValue <string>("AppSettings:JWTSecrets"))) , SecurityAlgorithms.HmacSha256Signature ), }; var TokenHandler = new JwtSecurityTokenHandler(); var securitytoken = TokenHandler.CreateToken(TokenDescriptor); var token = TokenHandler.WriteToken(securitytoken); return(Ok(new { token, user.Id })); }
public async Task <bool> Login(AppUserLoginDto appUser) { appUser.CustomerId = Convert.ToInt32((context.HttpContext.Request.Cookies["customer"])); string jsonData = JsonConvert.SerializeObject(appUser); var stringContent = new StringContent(jsonData, Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync("Auth/Login", stringContent); if (response.IsSuccessStatusCode) { var token = JsonConvert .DeserializeObject <AccessToken> (await response.Content.ReadAsStringAsync()); context.HttpContext.Session.SetString("token", token.Token); context.HttpContext.Response.Cookies.Append("customer", token.CustomerId.ToString()); return(true); } return(false); }
public async Task <ActionResult> Login(AppUserLoginDto appUserLoginDto) { try { var appUser = await _authService.Login(appUserLoginDto); if (appUser == null) { return(Unauthorized("Kullanıcı adı veya şifre geçerli değil.")); } var person = await _personService.GetPersonByTCNumberAsync(appUser.TCNumber); var accessToken = await _authService.CreateAccessToken(appUser, person.Id); return(Ok(accessToken)); } catch (Exception ex) { return(Unauthorized(ex.Message)); } }
public async Task <IActionResult> SignIn([FromQuery] AppUserLoginDto appUserLoginDto) { var appUser = await this.appUserService.FindByUserNameAsync(appUserLoginDto.UserName); if (appUser == null) { return(BadRequest("Username or password is invalid")); } if (await this.appUserService.CheckPasswordAsync(appUserLoginDto)) { var roles = await this.appUserService.GetRolesByUserName(appUserLoginDto.UserName); var token = this.jwtService.GenerateJwt(appUser, roles); JwtAccessToken Token = new JwtAccessToken { Token = token }; return(Created("", Token)); } return(BadRequest("Username or password is invalid")); }
public IActionResult SignIn(AppUserLoginDto appUserLoginDto) { return(Created("", "")); }