public async Task <IActionResult> Login([FromBody] CredentialsDto credentials) { var user = await _userService.FindByNameAsync(credentials.UserNameOrEmail); if (user == null) { user = await _userService.FindByEmailAsync(credentials.UserNameOrEmail); if (user == null) { return(BadRequest("Login fehlgeschlagen!")); } } user.LastLoginDate = DateTime.Now; await _userService.UpdateUserAsync(user); await userLoginService.CreateAsync(new UserLogin() { DateTimeOfLastLogin = DateTime.Now, UserId = user.Id }); if (user.UserLockEnabled) { return(BadRequest("Benutzer ist gesperrt! Bitte den Administrator kontaktieren")); } var signInAsync = await _signInService.CheckPasswordSignInAsync(user, credentials.Password); if (signInAsync.Succeeded) { var userDto = _mapper.Map <UserDto>(user); var roles = await _userService.GetRolesAsync(user); List <Claim> claims; if (!user.IsSuperAdmin) { claims = await GetAllClaimsOfUser(roles); } else { claims = RoleClaims.GetAllClaims(); } userDto.AccessToken = _signInService.CreateToken(user, roles, claims); return(Ok(userDto)); } return(BadRequest("Login fehlgeschlagen!")); }