Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Userservice services #2

Merged
merged 48 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ad18c98
Created userservice
ReallyWeirdCat Oct 26, 2024
0c6d8c2
Database tables
ReallyWeirdCat Oct 26, 2024
ddee5e5
Dependencies
ReallyWeirdCat Oct 26, 2024
6a821a7
Models + appdbcontext
ReallyWeirdCat Oct 26, 2024
b833e87
Added registration codes + user termination-related fields
ReallyWeirdCat Oct 26, 2024
64529fa
regcodes to appcontext
ReallyWeirdCat Oct 26, 2024
710428e
Added phone and email to user, set restrictions for username length a…
ReallyWeirdCat Oct 26, 2024
1762cbf
dbcontext in program.cs + gitignored appsettings.development
ReallyWeirdCat Oct 26, 2024
4094164
Removed unneeded deps and swagger from program.cs
ReallyWeirdCat Oct 26, 2024
38248db
Base repository
ReallyWeirdCat Oct 26, 2024
2dcca0a
Renamed db variable
ReallyWeirdCat Oct 26, 2024
3ee6af8
Added repos to program.cs
ReallyWeirdCat Oct 26, 2024
82e001e
Account interface, requests
ReallyWeirdCat Oct 27, 2024
548983f
Requests, responses, exceptions
ReallyWeirdCat Oct 28, 2024
b290217
Validation attributes integrated
ReallyWeirdCat Oct 28, 2024
155919c
Added missing methods and models + integrated args and responces into…
ReallyWeirdCat Oct 28, 2024
0d7baa7
Added serilog & opensearch
ReallyWeirdCat Oct 28, 2024
56ea6f8
Renamed Util to Utils
ReallyWeirdCat Oct 30, 2024
955abbe
Asynchronized repos
ReallyWeirdCat Oct 31, 2024
145554b
Created class implementation for account service. Made Salt mandatory…
ReallyWeirdCat Nov 1, 2024
6368836
Made navprops use virtual objects for better utilization of lazy loading
ReallyWeirdCat Nov 1, 2024
c0b6ddd
Using LogDebug to log various events in the service; immplemented Beg…
ReallyWeirdCat Nov 1, 2024
d5364cf
User's meta and personal data are no longer required to have
ReallyWeirdCat Nov 1, 2024
8629287
Registration initialization, password reset, bcrypt util, default val…
ReallyWeirdCat Nov 1, 2024
f714e19
Fixed interface mismatch
ReallyWeirdCat Nov 1, 2024
9d696a4
Implemented CompletePasswordResetMethod
ReallyWeirdCat Nov 1, 2024
59ed2d1
Interface methods
ReallyWeirdCat Nov 1, 2024
6b33829
Implemented transaction methods
ReallyWeirdCat Nov 1, 2024
c07b630
Dockerfile
ReallyWeirdCat Nov 1, 2024
70ecb36
Refactored logger calls to use the appropriate template
ReallyWeirdCat Nov 2, 2024
6cdc323
Created Avatar validation attribute (does not function at the moment)
ReallyWeirdCat Nov 2, 2024
5ccb3fe
Removed dependency injection from ValidAvatar, integrated into Meta d…
ReallyWeirdCat Nov 2, 2024
5dd7143
Implemented CompleteRegistration method
ReallyWeirdCat Nov 2, 2024
07f1dfd
Resolved todos
ReallyWeirdCat Nov 2, 2024
56eb751
Implemented code verification methods
ReallyWeirdCat Nov 2, 2024
56c3945
Merge pull request #5 from EspadaKomanda/4-транзакции-в-репозиториях
ReallyWeirdCat Nov 2, 2024
ac11c9e
Implemented UnitOfWork for transaction support in repositories
ReallyWeirdCat Nov 2, 2024
46f4d24
Made final touches to UnitOfWork class and integrated the unit-of-wor…
ReallyWeirdCat Nov 2, 2024
4eac3ab
Implemented code resending methods in accountservice
ReallyWeirdCat Nov 2, 2024
fab58c3
Repositories are no longer used directly. UnitOfWork uses dependency …
ReallyWeirdCat Nov 2, 2024
1e34cd4
Deprecated dispose method in UOW
ReallyWeirdCat Nov 2, 2024
5f60afe
Merge pull request #6 from EspadaKomanda/userservice-unitofwork
ReallyWeirdCat Nov 2, 2024
acaf7dd
fixing untracked
Nov 6, 2024
9d7d0d6
Basic work with kafka
Nov 6, 2024
1072c86
Models for profile
ReallyWeirdCat Nov 9, 2024
8ac044b
Implemented profileservice
ReallyWeirdCat Nov 9, 2024
f8b3a13
Method to acquire avatar and username
ReallyWeirdCat Nov 9, 2024
7f026d7
GetUser method
ReallyWeirdCat Nov 9, 2024
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 UserService/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
obj/*
bin/*

appsettings.Development.json
35 changes: 35 additions & 0 deletions UserService/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md.
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net8.0/UserService.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
41 changes: 41 additions & 0 deletions UserService/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/UserService.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/UserService.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/UserService.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
35 changes: 35 additions & 0 deletions UserService/Attributes/Validation/ValidAge.cs
ReallyWeirdCat marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.ComponentModel.DataAnnotations;

namespace UserService.Attributes.Validation;

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
sealed public partial class ValidAge : ValidationAttribute
{
public override bool IsValid(object? value)
{
try
{
if (value != null)
{
DateTime date = (DateTime)value;

// FIXME: Check if this is the actual age we need
int age = DateTime.Now.Year - date.Year;
if (age < 18)
{
return false;
}
}
return true;
}
catch
{
return false;
}
}

public override string FormatErrorMessage(string name)
{
return "You must be at least 18 years old";
}
}
32 changes: 32 additions & 0 deletions UserService/Attributes/Validation/ValidAvatar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;

namespace UserService.Attributes.Validation;

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
sealed public partial class ValidAvatar : ValidationAttribute
{
// FIXME: test regex
private const string Pattern = @"^.{1,150}$";

public override bool IsValid(object? value)
{
try
{
// FIXME: Implementation
return true;
}
catch
{
return false;
}
}

public override string FormatErrorMessage(string name)
{
return "Must be a valid avatar URL in the S3 storage";
}

[GeneratedRegex(Pattern)]
private static partial Regex MyRegex();
}
29 changes: 29 additions & 0 deletions UserService/Attributes/Validation/ValidGuid.cs
ReallyWeirdCat marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.ComponentModel.DataAnnotations;

namespace UserService.Attributes.Validation;

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
sealed public class ValidGuid : ValidationAttribute
{
public override bool IsValid(object? value)
{
try
{
if (value != null)
{
var guid = new Guid(value.ToString()!);
}
return true;
}
catch
{
return false;
}
}

public override string FormatErrorMessage(string name)
{
return "Not a valid GUID";
}

}
40 changes: 40 additions & 0 deletions UserService/Attributes/Validation/ValidName.cs
ReallyWeirdCat marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;

namespace UserService.Attributes.Validation;

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
sealed public partial class ValidName : ValidationAttribute
{
// FIXME: test regex
private const string Pattern = @"^.{1,150}$";

public override bool IsValid(object? value)
{
try
{
if (value != null)
{
string name = value.ToString() ?? "";

if (!MyRegex().IsMatch(name))
{
return false;
}
}
return true;
}
catch
{
return false;
}
}

public override string FormatErrorMessage(string name)
{
return "Name must be between 1 and 150 characters";
}

[GeneratedRegex(Pattern)]
private static partial Regex MyRegex();
}
45 changes: 45 additions & 0 deletions UserService/Attributes/Validation/ValidPassword.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;

namespace UserService.Attributes.Validation;

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
sealed public partial class ValidPassword : ValidationAttribute
{
private const string Pattern = @"^.{8,256}$";
private string? _errorMessage;

public override bool IsValid(object? value)
{
try
{
if (value != null)
{
string password = value.ToString() ?? "";

if (!MyRegex().IsMatch(password))
{
_errorMessage = "Password must be between 8 and 256 characters";
return false;
}
}
return true;
}
catch (Exception e)
{
// FIXME: use logger instead
Console.WriteLine(e);
_errorMessage = "Invalid password. Contact administrator if you think this is a mistake.";
return false;
throw;
}
}

public override string FormatErrorMessage(string name)
{
return _errorMessage ?? "Invalid password";
}

[GeneratedRegex(Pattern)]
private static partial Regex MyRegex();
}
39 changes: 39 additions & 0 deletions UserService/Attributes/Validation/ValidUsername.cs
ReallyWeirdCat marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;

namespace UserService.Attributes.Validation;

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
sealed public partial class ValidUsername : ValidationAttribute
{
private const string Pattern = @"^[a-zA-Z0-9_]{3,18}$";

public override bool IsValid(object? value)
{
try
{
if (value != null)
{
string username = value.ToString() ?? "";

if (!MyRegex().IsMatch(username))
{
return false;
}
}
return true;
}
catch
{
return false;
}
}

public override string FormatErrorMessage(string name)
{
return "Username must be between 3 and 18 characters and contain only letters, numbers, and underscores";
}

[GeneratedRegex(Pattern)]
private static partial Regex MyRegex();
}
32 changes: 32 additions & 0 deletions UserService/Database/ApplicationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.EntityFrameworkCore;
using UserService.Database.Models;

namespace UserService.Database;

public class ApplicationContext : DbContext
{
public DbSet<User> Users { get; set; } = null!;
public DbSet<Meta> Metas { get; set; } = null!;
public DbSet<Role> Roles { get; set; } = null!;
public DbSet<PersonalData> PersonalDatas { get; set; } = null!;
public DbSet<VisitedTour> VisitedTours { get; set; } = null!;
public DbSet<RegistrationCode> RegistrationCodes { get; set; } = null!;

public ApplicationContext(DbContextOptions<ApplicationContext> options) : base(options)
{
Database.EnsureCreated();
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Role>().HasData(
new Role {Id = 1, Name = "user", IsProtected = true},
new Role {Id = 2, Name = "admin", IsProtected = true}
);
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
}

}
27 changes: 27 additions & 0 deletions UserService/Database/Models/Meta.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.ComponentModel.DataAnnotations;
using UserService.Attributes.Validation;

namespace UserService.Database.Models;

public class Meta
{
[Key]
public long Id { get; set; }

[Required]
public long UserId { get; set; }
public virtual User User { get; set; } = null!;

[Required]
public string Name { get; set; } = null!;
[Required]
public string Surname { get; set; } = null!;
public string? Patronymic { get; set; }

[Required]
[ValidAge]
public DateTime Birthday { get; set; }

[ValidAvatar]
public string? Avatar { get; set; }
}
16 changes: 16 additions & 0 deletions UserService/Database/Models/PersonalData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.ComponentModel.DataAnnotations;

namespace UserService.Database.Models;

public class PersonalData
{
[Key]
public long Id { get; set; }

[Required]
public long UserId { get; set; }
public virtual User User { get; set; } = null!;

public string? Passport { get; set; }
public string? Snils { get; set; }
}
Loading