Alerin
Alerin
CC#
Created by Alerin on 5/8/2023 in #help
❔ How to verify data according to DDD, SOLID and Clean Architecture?
I added this to the model:
public bool IsVerified()
=> Status == StatusType.Verified;
public bool IsVerified()
=> Status == StatusType.Verified;
next:
if(credential.IsVerified() == false)
return false;
if(credential.IsVerified() == false)
return false;
Does it comply with the above rules?
13 replies
CC#
Created by Alerin on 5/8/2023 in #help
❔ How to verify data according to DDD, SOLID and Clean Architecture?
Model:
namespace Stand.Plugins.Identity.Domain.Entities;

/// <summary>
/// Dane logowania
/// Adres mail, numer telefonu, social media, karty RFID itp.
/// </summary>
[Index(nameof(Method), nameof(Value), IsUnique = true)]
public class Credential
{
public int Id { get; set; }
public User User { get; set; } = null!;
public Guid UserId { get; set; }
public MethodType Method { get; set; }
public string Value { get; set; } = string.Empty;
public StatusType Status { get; set; }
public DateTime Created { get; set; } = DateTime.UtcNow;
public enum MethodType
{
None,
Phone,
Email,
}

public enum StatusType
{
None,
Unverified, // Niezweryfikowany
Verified, // Zweryfikowany
Expired, // Wygasły, np. zablokowany itp.
}

public class MethodModel
{
public string Mail { get; set; } = "mail";
public string Phone { get; set; } = "phone";
}
}
namespace Stand.Plugins.Identity.Domain.Entities;

/// <summary>
/// Dane logowania
/// Adres mail, numer telefonu, social media, karty RFID itp.
/// </summary>
[Index(nameof(Method), nameof(Value), IsUnique = true)]
public class Credential
{
public int Id { get; set; }
public User User { get; set; } = null!;
public Guid UserId { get; set; }
public MethodType Method { get; set; }
public string Value { get; set; } = string.Empty;
public StatusType Status { get; set; }
public DateTime Created { get; set; } = DateTime.UtcNow;
public enum MethodType
{
None,
Phone,
Email,
}

public enum StatusType
{
None,
Unverified, // Niezweryfikowany
Verified, // Zweryfikowany
Expired, // Wygasły, np. zablokowany itp.
}

public class MethodModel
{
public string Mail { get; set; } = "mail";
public string Phone { get; set; } = "phone";
}
}
13 replies
CC#
Created by Alerin on 5/8/2023 in #help
❔ How to verify data according to DDD, SOLID and Clean Architecture?
public async Task<Guid> AuthAsync(string value, Credential.MethodType type, string code)
{
var credential = await _credentialRepository.GetByValueAsync(value, type);

// Jeżeli poświadczenie nie istnieje czyli nie ma użytkownika w bazie danych
if (credential == null)
throw new AuthenticationException("Invalid credentials.");

if(credential.Status != Credential.StatusType.Verified)
throw new AuthenticationException("The credential is unverified");

var authentication = await _authenticationRepository.GetAsync(credential.User);

// Jeżeli kod się nie zgadza
if (authentication == null)
throw new AuthenticationException("Invalid authorization.");

// Jeżeli przekroczono ilość prób logowania (anti brute force)
if (authentication.Attempts <= 0)
throw new AuthenticationException("Authorization attempts exceeded.");

// Jeżeli kod jest nie poprawny
if(authentication.Code != code)
{
authentication.Attempts--;
await _authenticationRepository.UpdateAsync(credential.User, authentication);
throw new AuthenticationException("Invalid authorization code.");
}

if (this.Ip == null)
throw new AuthenticationException("Ip is empty");

var session = await _sessionRepository.AddAsync(new(credential.User, this.Ip, this.Metadata));

return session;
}
public async Task<Guid> AuthAsync(string value, Credential.MethodType type, string code)
{
var credential = await _credentialRepository.GetByValueAsync(value, type);

// Jeżeli poświadczenie nie istnieje czyli nie ma użytkownika w bazie danych
if (credential == null)
throw new AuthenticationException("Invalid credentials.");

if(credential.Status != Credential.StatusType.Verified)
throw new AuthenticationException("The credential is unverified");

var authentication = await _authenticationRepository.GetAsync(credential.User);

// Jeżeli kod się nie zgadza
if (authentication == null)
throw new AuthenticationException("Invalid authorization.");

// Jeżeli przekroczono ilość prób logowania (anti brute force)
if (authentication.Attempts <= 0)
throw new AuthenticationException("Authorization attempts exceeded.");

// Jeżeli kod jest nie poprawny
if(authentication.Code != code)
{
authentication.Attempts--;
await _authenticationRepository.UpdateAsync(credential.User, authentication);
throw new AuthenticationException("Invalid authorization code.");
}

if (this.Ip == null)
throw new AuthenticationException("Ip is empty");

var session = await _sessionRepository.AddAsync(new(credential.User, this.Ip, this.Metadata));

return session;
}
13 replies
CC#
Created by Alerin on 4/15/2023 in #help
❔ Is the functionality of my code in the right place
.
4 replies
CC#
Created by Alerin on 4/15/2023 in #help
❔ Is the functionality of my code in the right place
I'm wondering if this functionality violates the standards. I don't know if it would be better to create a new class, e.g. Services, which will handle this.
4 replies
CC#
Created by Alerin on 2/1/2023 in #help
❔ The application is available worldwide
Thanks for your help, I'll look for solutions and wait for someone else to comment on the topic.
28 replies
CC#
Created by Alerin on 2/1/2023 in #help
❔ The application is available worldwide
Do you know any ready-made solutions that work like this?
28 replies
CC#
Created by Alerin on 2/1/2023 in #help
❔ The application is available worldwide
You can create a central application that manages the data, and the servers and the application on them will act as a cache and possibly communication between them.
28 replies
CC#
Created by Alerin on 2/1/2023 in #help
❔ The application is available worldwide
You are right too, now there is such a fast internet in the world. 250ms is not much with final rendering.
28 replies
CC#
Created by Alerin on 2/1/2023 in #help
❔ The application is available worldwide
There is little movie data that does not change so it can be replicated. Unfortunately, there can be many users, so keeping it in one database can be problematic, especially since there are different regions of the world.
28 replies
CC#
Created by Alerin on 2/1/2023 in #help
❔ The application is available worldwide
Unfortunately rest or grpc I have to handle myself. Here I have a problem with the database, user data, videos, etc.
28 replies
CC#
Created by Alerin on 2/1/2023 in #help
❔ The application is available worldwide
I will stream the movie with cdn77 or cloudflare.
28 replies
CC#
Created by Alerin on 2/1/2023 in #help
❔ The application is available worldwide
I thought to create a server per region, make the application and database on one server and add the region prefix to the database. ASP.Net is able to handle a lot of requests from one server. We anticipate around 50-100k online users.
28 replies
CC#
Created by Alerin on 2/1/2023 in #help
❔ The application is available worldwide
I was commissioned to create a netflix-like system for a movie producer. Currently, it will be a few videos, but the platform is expected to develop.
28 replies
CC#
Created by Alerin on 2/1/2023 in #help
❔ The application is available worldwide
I was thinking about mssql which is best for ef core.
28 replies
CC#
Created by Alerin on 2/1/2023 in #help
❔ The application is available worldwide
I understand that it can also be done with the cache, but what if the cache in the US will be different than in, for example, Asia?
28 replies
CC#
Created by Alerin on 2/1/2023 in #help
❔ The application is available worldwide
I had such a problem when, for example, I wanted to make 10 queries to the database, then the whole thing took about 400ms
28 replies
CC#
Created by Alerin on 2/1/2023 in #help
❔ The application is available worldwide
I thought about blazor wasm because it works on the phone and the rest is rest api or grpc. When it comes to the time to the database, the problem arises when there are many queries. For example, download a list of elements, then add something else to this list, etc. There is clean data in the database, only the server parses it to, for example, dto.
28 replies
CC#
Created by Alerin on 12/6/2022 in #help
✅ Can I create a Liststring in mssql ef core?
10 replies
CC#
Created by Alerin on 12/6/2022 in #help
✅ Can I create a Liststring in mssql ef core?
modelBuilder.Entity<Template>()
.Property(e => e.HashTags)
.HasConversion(
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null!),
v => JsonSerializer.Deserialize<List<string>>(v, (JsonSerializerOptions)null!),
new ValueComparer<ICollection<string>>(
(c1, c2) => c1.SequenceEqual(c2),
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
c => (ICollection<string>)c.ToList()));
modelBuilder.Entity<Template>()
.Property(e => e.HashTags)
.HasConversion(
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null!),
v => JsonSerializer.Deserialize<List<string>>(v, (JsonSerializerOptions)null!),
new ValueComparer<ICollection<string>>(
(c1, c2) => c1.SequenceEqual(c2),
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
c => (ICollection<string>)c.ToList()));
Work
10 replies