Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/obj/Debug
/bin
.idea
appsettings.Development.json
54 changes: 54 additions & 0 deletions backend/Migrations/20230408214038_InitialCreate.Designer.cs

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

37 changes: 37 additions & 0 deletions backend/Migrations/20230408214038_InitialCreate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace backend.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Username = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Users");
}
}
}
51 changes: 51 additions & 0 deletions backend/Migrations/DataContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using backend.modules.shared.database;

#nullable disable

namespace backend.Migrations
{
[DbContext(typeof(DataContext))]
partial class DataContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);

modelBuilder.Entity("backend.modules.auth.NormalUserModel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");

NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));

b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");

b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");

b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");

b.HasKey("Id");

b.ToTable("Users");
});
#pragma warning restore 612, 618
}
}
}
29 changes: 24 additions & 5 deletions backend/Program.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
var builder = WebApplication.CreateBuilder(args);
using System.Text;
using backend.modules.shared.database;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;

// Add services to the container.
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddAuthentication(opt =>
{
opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(opt =>
{
opt.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = "http://localhost:5001",
ValidAudience = "http://localhost:5001",
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("superSecretKey@345"))
};
});
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<DataContext>();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();
Expand Down
8 changes: 0 additions & 8 deletions backend/appsettings.Development.json

This file was deleted.

12 changes: 12 additions & 0 deletions backend/appsettings.Development.json--example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"ConnectionStrings": {
"WebApiDatabase": "Host=; Database=; Username=; Password="
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ApplicationUrl": "https://localhost:5001;http://localhost:5000"
}
3 changes: 2 additions & 1 deletion backend/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ApplicationUrl": "https://localhost:5001;http://localhost:5000"
}
10 changes: 10 additions & 0 deletions backend/backend.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.4" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

Expand Down
17 changes: 17 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.8'

services:
database:
image: postgres:15-alpine
ports:
- '5432:5432'
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: krowtify
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- pgdata:/var/lib/postgresql/data/pgdata

volumes:
pgdata:
32 changes: 32 additions & 0 deletions backend/modules/auth/AuthController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using backend.modules.user;
using Microsoft.AspNetCore.Mvc;

namespace backend.modules.auth;


[Route("api/auth")]
[ApiController]
public class AuthController : ControllerBase
{
private UserService _userService;

public AuthController()
{
_userService = new UserService();
}
// [HttpPost("/login")]
// public IActionResult Login([FromBody] AuthNormalUserLoginModel user)
// {
//
// }
[HttpPost("/register")]
public IActionResult Register([FromBody] AuthNormalUserRegisterModel userFormData)
{

var user = _userService.GetByName(userFormData.Username);
if (user)
{

}
}
}
34 changes: 34 additions & 0 deletions backend/modules/auth/AuthModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.ComponentModel.DataAnnotations;

namespace backend.modules.auth;

public class NormalUserModel
{
public int Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string Email { get; set; }
}

public class AuthNormalUserLoginModel
{
[Required]
public string Username { get; set; }
[Required]
public string Password { get; set; }
}

public class AuthNormalUserRegisterModel
{
[Required]
public string Username { get; set; }
[Required]
public string Password { get; set; }
[Required]
public string Email { get; set; }
}

public class AuthenticatedResponseModel
{
public string? Token { get; set; }
}
11 changes: 11 additions & 0 deletions backend/modules/auth/AuthService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace backend.modules.auth;

public interface IAuthService
{

}

public class AuthService
{

}
21 changes: 21 additions & 0 deletions backend/modules/shared/database/DataContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using backend.modules.auth;
using Microsoft.EntityFrameworkCore;

namespace backend.modules.shared.database;

public class DataContext : DbContext
{
private readonly IConfiguration _configuration;

public DataContext()
{
_configuration = new ConfigurationManager();
}

protected override void OnConfiguring(DbContextOptionsBuilder options)
{
options.UseNpgsql(_configuration.GetConnectionString("WebApiDatabase"));
}

public DbSet<NormalUserModel> Users { get; set; }
}
24 changes: 24 additions & 0 deletions backend/modules/user/UserService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using backend.modules.auth;
using backend.modules.shared.database;

namespace backend.modules.user;

interface IUserService
{
NormalUserModel? GetByName(string name);
}

public class UserService : IUserService
{
private DataContext _context;

public UserService()
{
_context = new DataContext();
}

public NormalUserModel? GetByName(string name)
{
return _context.Users.Find(name);
}
}
Binary file modified backend/obj/Debug/net7.0/backend.assets.cache
Binary file not shown.
Binary file modified backend/obj/Debug/net7.0/backend.csproj.AssemblyReference.cache
Binary file not shown.
Loading