Skip to content

Commit

Permalink
First Release
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejjanus committed Mar 31, 2023
1 parent 9d9ef71 commit ab6ef0d
Show file tree
Hide file tree
Showing 67 changed files with 3,482 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic.CS1591.severity = silent
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,4 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
/Server/DB/.scripts
8 changes: 8 additions & 0 deletions Docs/API_Docs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions PKiK_Server.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33103.184
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "Server\API\API.csproj", "{B1CD2437-2432-4E55-B757-C602BA992480}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DB", "Server\DB\DB.csproj", "{3093A513-C714-4BA9-A735-07DECCF94A46}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "Server\Services\Services.csproj", "{35E2BFF4-CD1D-4252-9024-13B951836D52}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerShared", "Server\Shared\ServerShared.csproj", "{F1E20FA7-41E0-4B0F-861A-6E43C7A87526}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{99E9891B-BADA-4C60-9059-AD7B377874C0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{607D7389-1451-4569-BA28-BCD0E4C5E0FB}"
ProjectSection(SolutionItems) = preProject
Server\.config\appsettings.json = Server\.config\appsettings.json
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerTests", "Tests\Server\ServerTests.csproj", "{FF0C5CAA-0686-408A-9FCC-8CBAA33FC809}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B1CD2437-2432-4E55-B757-C602BA992480}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1CD2437-2432-4E55-B757-C602BA992480}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1CD2437-2432-4E55-B757-C602BA992480}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1CD2437-2432-4E55-B757-C602BA992480}.Release|Any CPU.Build.0 = Release|Any CPU
{3093A513-C714-4BA9-A735-07DECCF94A46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3093A513-C714-4BA9-A735-07DECCF94A46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3093A513-C714-4BA9-A735-07DECCF94A46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3093A513-C714-4BA9-A735-07DECCF94A46}.Release|Any CPU.Build.0 = Release|Any CPU
{35E2BFF4-CD1D-4252-9024-13B951836D52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35E2BFF4-CD1D-4252-9024-13B951836D52}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35E2BFF4-CD1D-4252-9024-13B951836D52}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35E2BFF4-CD1D-4252-9024-13B951836D52}.Release|Any CPU.Build.0 = Release|Any CPU
{F1E20FA7-41E0-4B0F-861A-6E43C7A87526}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F1E20FA7-41E0-4B0F-861A-6E43C7A87526}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1E20FA7-41E0-4B0F-861A-6E43C7A87526}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1E20FA7-41E0-4B0F-861A-6E43C7A87526}.Release|Any CPU.Build.0 = Release|Any CPU
{99E9891B-BADA-4C60-9059-AD7B377874C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99E9891B-BADA-4C60-9059-AD7B377874C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99E9891B-BADA-4C60-9059-AD7B377874C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99E9891B-BADA-4C60-9059-AD7B377874C0}.Release|Any CPU.Build.0 = Release|Any CPU
{FF0C5CAA-0686-408A-9FCC-8CBAA33FC809}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF0C5CAA-0686-408A-9FCC-8CBAA33FC809}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF0C5CAA-0686-408A-9FCC-8CBAA33FC809}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF0C5CAA-0686-408A-9FCC-8CBAA33FC809}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6CAF5DA4-E79B-4191-88EC-64312E9F538C}
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions Server/.config/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|Server\\DB\\DB.mdf;Integrated Security=True;TrustServerCertificate=True;"
},
"Config": {
"IsDevelopmentEnvironment": true,
"JWT": {
"DaysValid": 7,
"Audience": "",
"Issuer": "PKiK_Messenging_App",
"SecretKey": "95a3fb93623946821bf441624c2ed4465de3addc0552a8f7393534c5ffaf537f"
}
}
}
6 changes: 6 additions & 0 deletions Server/.tools/gen_secret_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import secrets

key = secrets.token_hex(32)
key_string = str(key)

print(key_string)
22 changes: 22 additions & 0 deletions Server/API/API.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>PKiK.Server.API</RootNamespace>
<BaseOutputPath>..\..\.build\Server\bin\</BaseOutputPath>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<DocumentationFile>..\..\Docs\API_Docs.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Shared\Shared.csproj" />
<ProjectReference Include="..\Services\Services.csproj" />
<ProjectReference Include="..\Shared\ServerShared.csproj" />
</ItemGroup>

</Project>
97 changes: 97 additions & 0 deletions Server/API/Controllers/KeyController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using PKiK.Server.Services;
using PKiK.Shared;
using System;

namespace PKiK.Server.API.Controllers {
[ApiController]
[Route("[controller]")]
public class KeyController : ControllerBase {
private readonly IKeyService keyService;
private readonly IAuthenticationService authService;
public KeyController(IKeyService keyService, IAuthenticationService authService) {
this.keyService = keyService;
this.authService = authService;
}

[HttpGet("GetByID/{ID}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetKey([FromRoute] int ID, [FromRoute] string jwt) {
try {
if (!authService.IsValid(jwt)) {
return new StatusCodeResult(401);
}
return Result.Pass(keyService.GetKey(ID), "KeyController", "GetKey");
} catch (Exception exc) {
Log.Event(exc);
return new StatusCodeResult(500);
}
}

[HttpGet("GetByUserID/{ID}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetKeyForUser([FromRoute] int ID, [FromHeader] string jwt) {
try {
if (!authService.IsValid(jwt)) {
return new StatusCodeResult(401);
}
return Result.Pass(keyService.GetUserKey(ID), "KeyController", "GetUserKey");
} catch (Exception exc) {
Log.Event(exc);
return new StatusCodeResult(500);
}
}

[HttpPost("Add")]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult PostKey([FromBody] KeyDTO key, [FromHeader] string jwt) {
try {
if (!authService.IsValid(jwt)) {
return new StatusCodeResult(401);
}
if (!authService.IsUser(jwt, key.User.ID)) {
return new StatusCodeResult(403);
}
return Result.Pass(keyService.AddKey(key), "KeyController", "PostKey");
} catch (Exception exc) {
Log.Event(exc);
return new StatusCodeResult(500);
}
}

[HttpPut("Revoke/{ID}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult RevokeKey([FromRoute] int ID, [FromHeader] string jwt) {
try {
if (!authService.IsValid(jwt)) {
return new StatusCodeResult(401);
}
int userID = authService.GetUserID(jwt);
return Result.Pass(keyService.RevokeKey(ID, userID), "KeyController", "RevokeKey");
} catch (Exception exc) {
Log.Event(exc);
return new StatusCodeResult(500);
}
}
}
}
43 changes: 43 additions & 0 deletions Server/API/Controllers/LoginController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PKiK.Server.Services;
using PKiK.Shared;
using System;

namespace PKiK.Server.API.Controllers {
[ApiController]
[Route("[controller]")]
public class LoginController : ControllerBase {
private readonly ILoginService loginService;
public LoginController(ILoginService loginService, IAuthenticationService authService) {
this.loginService = loginService;
}

[HttpGet("Login")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult Login([FromHeader] string username, [FromHeader] string password) {
try {
return Result.Pass(loginService.Login(username, password), "LoginController", "Login");
} catch (Exception exc) {
Log.Event(exc);
return new StatusCodeResult(500);
}
}

[HttpPost("Register")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult Register([FromBody] UserDTO user) {
try {
return Result.Pass(loginService.Register(user), "LoginController", "Register");
} catch (Exception exc) {
Log.Event(exc);
return new StatusCodeResult(500);
}
}
}
}
Loading

0 comments on commit ab6ef0d

Please sign in to comment.