Skip to content

Commit 5f0ae18

Browse files
committed
workingOnJWTAuth
1 parent 42b731f commit 5f0ae18

File tree

64 files changed

+12846
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+12846
-9
lines changed
20.4 KB
Binary file not shown.
880 KB
Binary file not shown.

.vs/VSWorkspaceState.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ExpandedNodes": [
3+
""
4+
],
5+
"SelectedNode": "\\WebAPI.sln",
6+
"PreviewInSolutionExplorer": false
7+
}
3.51 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

.vs/WebAPI/v17/.futdcache.v2

0 Bytes
Binary file not shown.

.vs/WebAPI/v17/.suo

34 KB
Binary file not shown.

.vs/slnx.sqlite

88 KB
Binary file not shown.

WebAPI/AuthenticationSettings.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace WebAPI
2+
{
3+
public class AuthenticationSettings
4+
{
5+
public string JwtKey { get; set; }
6+
public int JwtExpireDays { get; set; }
7+
public string JwtIssuer { get; set;}
8+
}
9+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Components;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.EntityFrameworkCore;
4+
using WebAPI.Models;
5+
using WebAPI.Serivces;
6+
7+
namespace WebAPI.Controllers
8+
{
9+
[Microsoft.AspNetCore.Mvc.Route("api/account")]
10+
[ApiController]
11+
public class AccountContorler : ControllerBase
12+
{
13+
private readonly IAccountServices _accountService;
14+
15+
public AccountContorler(IAccountServices accountServices)
16+
{
17+
_accountService = accountServices;
18+
}
19+
[HttpPost("register")]
20+
public ActionResult Register([FromBody]AccountDto dto )
21+
{
22+
var id = _accountService.CreateUser(dto);
23+
return Created($"/api/restuarant/{id}", "ok pomyslnie dodoano");
24+
}
25+
26+
[HttpPost("login")]
27+
public ActionResult Login([FromBody] LoginDto dto)
28+
{
29+
var token = _accountService.GenerateJwt(dto);
30+
return Ok(token);
31+
}
32+
}
33+
}

WebAPI/Entities/User.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class User
77
public string Email { get; set; }
88
public string Password { get; set; }
99
public virtual Role Role { get; set; }
10+
public int RoleId { get; set; }
1011

1112
}
1213
}

WebAPI/Middleware.cs/ErrorHandlingMiddlewarecs.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
1919
}
2020
catch (NotFoundExeption nfex)
2121
{
22-
_logger.LogError(nfex, "Source was not found");
22+
_logger.LogError(nfex, nfex.Message);
2323
context.Response.StatusCode = 404;
2424
await context.Response.WriteAsync("Source was not found");
2525
}
2626
catch (Exception ex)
2727
{
2828
_logger.LogError(ex, ex.Message);
29-
context.Response.StatusCode = 500;
30-
await context.Response.WriteAsync("Something went wrong");
29+
context.Response.StatusCode = 400;
30+
await context.Response.WriteAsync($"Something went wrong bo {ex.Message}");
3131
}
3232
}
3333
}

WebAPI/Migrations/20230802113041_userActualization.Designer.cs

Lines changed: 221 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace WebAPI.Migrations
6+
{
7+
/// <inheritdoc />
8+
public partial class userActualization : Migration
9+
{
10+
/// <inheritdoc />
11+
protected override void Up(MigrationBuilder migrationBuilder)
12+
{
13+
14+
}
15+
16+
/// <inheritdoc />
17+
protected override void Down(MigrationBuilder migrationBuilder)
18+
{
19+
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)