94 lines
2.4 KiB
C#
94 lines
2.4 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text.RegularExpressions;
|
||
|
||
namespace demo_2023.Models;
|
||
|
||
public class ClientPresenter
|
||
{
|
||
public int Id { get; set; }
|
||
|
||
public string Fio { get; set; } = null!;
|
||
|
||
public string Email { get; set; } = null!;
|
||
|
||
public DateTime Date { get; set; }
|
||
|
||
public int Country { get; set; }
|
||
|
||
public string Phone { get; set; } = null!;
|
||
|
||
private string _Password;
|
||
private string _confirmPassword;
|
||
|
||
public string Password
|
||
{
|
||
get => _Password;
|
||
set
|
||
{
|
||
ValidatePassword(value);
|
||
_Password = value;
|
||
}
|
||
}
|
||
|
||
public string ConfirmPassword
|
||
{
|
||
get => _confirmPassword;
|
||
set
|
||
{
|
||
_confirmPassword = value;
|
||
ValidatePassword(value);
|
||
ValidatePasswordMatch();
|
||
}
|
||
}
|
||
|
||
public string? Spec { get; set; }
|
||
|
||
public string Photopath { get; set; } = null!;
|
||
|
||
public char Gender { get; set; }
|
||
|
||
public int Role { get; set; }
|
||
|
||
public virtual Country CountryNavigation { get; set; } = null!;
|
||
|
||
public virtual Role RoleNavigation { get; set; } = null!;
|
||
|
||
public virtual ICollection<Activity> Activities { get; set; } = new List<Activity>();
|
||
|
||
public virtual ICollection<Activity> ActivitiesNavigation { get; set; } = new List<Activity>();
|
||
|
||
|
||
private void ValidatePassword(string password)
|
||
{
|
||
if (password.Length < 6)
|
||
{
|
||
throw new ArgumentException(nameof(password), "Password must be at least 6 characters");
|
||
}
|
||
|
||
if (!password.Any(char.IsDigit))
|
||
{
|
||
throw new ArgumentException(nameof(password), "Пароль должен содержать цифры");
|
||
}
|
||
|
||
if (!password.Any(char.IsUpper) || !password.Any(char.IsLower))
|
||
{
|
||
throw new ArgumentException(nameof(password), "В пароле должны быть заглавные и строчные буквы");
|
||
}
|
||
|
||
var regex = new Regex(@"[!@#$%^&*()\-_=+{};:,<.>]");
|
||
if (!regex.IsMatch(password))
|
||
{
|
||
throw new ArgumentException(nameof(password), "Пароль должен содержать спецсимволы");
|
||
}
|
||
|
||
}
|
||
private void ValidatePasswordMatch()
|
||
{
|
||
if (_Password != _confirmPassword)
|
||
{
|
||
throw new ArgumentException("Пароли должны совпадать", nameof(ConfirmPassword));
|
||
}
|
||
}
|
||
} |