mirror of
https://github.com/ryzij/URL-Shortener.git
synced 2026-07-14 03:56:58 +00:00
Регистрация теперь тоже возвращает jwt
This commit is contained in:
@@ -13,8 +13,8 @@ namespace URL_Shortener.Controllers
|
|||||||
[HttpPost("register")]
|
[HttpPost("register")]
|
||||||
public async Task<IActionResult> RegisterAsync(RegisterUserDTO dto)
|
public async Task<IActionResult> RegisterAsync(RegisterUserDTO dto)
|
||||||
{
|
{
|
||||||
await _userService.RegisterAsync(dto.Name, dto.Email, dto.Password);
|
var jwt = await _userService.RegisterAsync(dto.Name, dto.Email, dto.Password);
|
||||||
return Ok();
|
return Ok(jwt);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("login")]
|
[HttpPost("login")]
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace URL_Shortener.Services
|
|||||||
private readonly AppDbContext _db = db;
|
private readonly AppDbContext _db = db;
|
||||||
private readonly JwtService _jwtService = jwtService;
|
private readonly JwtService _jwtService = jwtService;
|
||||||
|
|
||||||
public async Task RegisterAsync(string userName, string email, string password, CancellationToken cancellationToken = default)
|
public async Task<string> RegisterAsync(string userName, string email, string password, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (await _db.Users.FirstOrDefaultAsync(u => u.Email == email, cancellationToken) != null)
|
if (await _db.Users.FirstOrDefaultAsync(u => u.Email == email, cancellationToken) != null)
|
||||||
throw new Exception("This user already exists.");
|
throw new Exception("This user already exists.");
|
||||||
@@ -23,6 +23,8 @@ namespace URL_Shortener.Services
|
|||||||
|
|
||||||
await _db.Users.AddAsync(user, cancellationToken);
|
await _db.Users.AddAsync(user, cancellationToken);
|
||||||
await _db.SaveChangesAsync(cancellationToken);
|
await _db.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
return _jwtService.GenerateToken(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> LoginAsync(string email, string password, CancellationToken cancellationToken = default)
|
public async Task<string> LoginAsync(string email, string password, CancellationToken cancellationToken = default)
|
||||||
|
|||||||
Reference in New Issue
Block a user