mirror of
https://github.com/ryzij/URL-Shortener.git
synced 2026-07-14 03:56:58 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| da47d7fdf3 | |||
| d659a0289f |
@@ -4,6 +4,7 @@ using URL_Shortener.DTO;
|
||||
using URL_Shortener.Models;
|
||||
using HashidsNet;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace URL_Shortener.Controllers
|
||||
{
|
||||
@@ -86,7 +87,9 @@ namespace URL_Shortener.Controllers
|
||||
if (shortUrl == null)
|
||||
return NotFound();
|
||||
|
||||
// TODO: определение пользователя по jwt
|
||||
if (!int.TryParse(User.FindFirstValue(ClaimTypes.NameIdentifier), out var userId) ||
|
||||
shortUrl.UserId != userId)
|
||||
throw new Exception("Not authorized");
|
||||
|
||||
_db.ShortUrls.Remove(shortUrl);
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace URL_Shortener.Services
|
||||
public string GenerateToken(User user)
|
||||
{
|
||||
var claims = new List<Claim>() {
|
||||
new("userName", user.Name),
|
||||
new("userEmail", user.Email),
|
||||
new("id", user.Id.ToString())
|
||||
new(ClaimTypes.Name, user.Name),
|
||||
new(ClaimTypes.Email, user.Email),
|
||||
new(ClaimTypes.NameIdentifier, user.Id.ToString())
|
||||
};
|
||||
var jwt = new JwtSecurityToken(
|
||||
expires: DateTime.UtcNow.Add(options.Value.Expires),
|
||||
|
||||
Reference in New Issue
Block a user