PIbd-22. Fedorenko G.Y. Lab Work 7 BASE #9
@ -105,11 +105,11 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentException("Некорретно введен email клиента", nameof(model.Email));
|
||||
}
|
||||
if (!Regex.IsMatch(model.Password, @"^(?=.*\d)(?=.*\W)(?=.*[^\d\s]).+$"))
|
||||
{
|
||||
throw new ArgumentException("Некорректно введен пароль клиента", nameof(model.Password));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
if (!Regex.IsMatch(model.Password, @"^(?=.*\d)(?=.*\W)(?=.*[^\d\s]).+$"))
|
||||
{
|
||||
throw new ArgumentException("Некорректно введен пароль клиента", nameof(model.Password));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password));
|
||||
}
|
||||
|
@ -13,13 +13,12 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker
|
||||
protected string _popHost = string.Empty;
|
||||
protected int _popPort;
|
||||
private readonly IMessageInfoLogic _messageInfoLogic;
|
||||
private readonly IClientLogic _clientLogic;
|
||||
private readonly ILogger _logger;
|
||||
public AbstractMailWorker(ILogger<AbstractMailWorker> logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic)
|
||||
public AbstractMailWorker(ILogger<AbstractMailWorker> logger,
|
||||
IMessageInfoLogic messageInfoLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_messageInfoLogic = messageInfoLogic;
|
||||
_clientLogic = clientLogic;
|
||||
}
|
||||
public void MailConfig(MailConfigBindingModel config)
|
||||
{
|
||||
@ -29,7 +28,8 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker
|
||||
_smtpClientPort = config.SmtpClientPort;
|
||||
_popHost = config.PopHost;
|
||||
_popPort = config.PopPort;
|
||||
_logger.LogDebug("Config: {login}, {password}, {clientHost},{ clientPOrt}, { popHost}, { popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort);
|
||||
_logger.LogDebug($"Config: {_mailLogin}, {_mailPassword}, " +
|
||||
$"{_smtpClientHost}, {_smtpClientPort}, {_popHost}, {_popPort}");
|
||||
}
|
||||
public async void MailSendAsync(MailSendInfoBindingModel info)
|
||||
{
|
||||
@ -41,7 +41,9 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text))
|
||||
if (string.IsNullOrEmpty(info.MailAddress) ||
|
||||
string.IsNullOrEmpty(info.Subject) ||
|
||||
string.IsNullOrEmpty(info.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -66,12 +68,10 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker
|
||||
_logger.LogDebug("Check Mail: {Count} new mails", list.Count);
|
||||
foreach (var mail in list)
|
||||
{
|
||||
mail.ClientId = _clientLogic.ReadElement(new() { Email = mail.SenderName })?.Id;
|
||||
_messageInfoLogic.Create(mail);
|
||||
}
|
||||
}
|
||||
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
|
||||
protected abstract Task<List<MessageInfoBindingModel>>
|
||||
ReceiveMailAsync();
|
||||
protected abstract Task<List<MessageInfoBindingModel>> ReceiveMailAsync();
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,8 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker
|
||||
{
|
||||
public class MailKitWorker : AbstractMailWorker
|
||||
{
|
||||
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) { }
|
||||
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic messageInfoLogic)
|
||||
: base(logger, messageInfoLogic) { }
|
||||
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
|
||||
{
|
||||
using var objMailMessage = new MailMessage();
|
||||
@ -35,8 +36,7 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker
|
||||
throw;
|
||||
}
|
||||
}
|
||||
protected override async Task<List<MessageInfoBindingModel>>
|
||||
ReceiveMailAsync()
|
||||
protected override async Task<List<MessageInfoBindingModel>> ReceiveMailAsync()
|
||||
{
|
||||
var list = new List<MessageInfoBindingModel>();
|
||||
using var client = new Pop3Client();
|
||||
@ -57,12 +57,12 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker
|
||||
MessageId = message.MessageId,
|
||||
SenderName = mail.Address,
|
||||
Subject = message.Subject,
|
||||
Body = message.TextBody
|
||||
Body = message.TextBody != null ? message.TextBody : message.HtmlBody
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MailKit.Security.AuthenticationException)
|
||||
catch (AuthenticationException)
|
||||
{ }
|
||||
finally
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace CarpentryWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarpentryWorkshopDatabase))]
|
||||
[Migration("20240505132850_InitialCreate")]
|
||||
[Migration("20240508053502_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -97,6 +97,36 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
|
||||
b.ToTable("Implementers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.MessageInfo", b =>
|
||||
{
|
||||
b.Property<string>("MessageId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int?>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateDelivery")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("SenderName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Subject")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("MessageId");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.ToTable("MessageInfos");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -186,6 +216,15 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
|
||||
b.ToTable("WoodComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.MessageInfo", b =>
|
||||
{
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Messages")
|
||||
.HasForeignKey("ClientId");
|
||||
|
||||
b.Navigation("Client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Client", "Client")
|
||||
@ -232,6 +271,8 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Messages");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
@ -70,6 +70,27 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
|
||||
table.PrimaryKey("PK_Woods", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "MessageInfos",
|
||||
columns: table => new
|
||||
{
|
||||
MessageId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ClientId = table.Column<int>(type: "int", nullable: true),
|
||||
SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
DateDelivery = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Subject = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Body = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_MessageInfos", x => x.MessageId);
|
||||
table.ForeignKey(
|
||||
name: "FK_MessageInfos_Clients_ClientId",
|
||||
column: x => x.ClientId,
|
||||
principalTable: "Clients",
|
||||
principalColumn: "Id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
@ -134,6 +155,11 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_MessageInfos_ClientId",
|
||||
table: "MessageInfos",
|
||||
column: "ClientId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ClientId",
|
||||
table: "Orders",
|
||||
@ -163,6 +189,9 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "MessageInfos");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
@ -94,6 +94,36 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
|
||||
b.ToTable("Implementers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.MessageInfo", b =>
|
||||
{
|
||||
b.Property<string>("MessageId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int?>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateDelivery")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("SenderName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Subject")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("MessageId");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.ToTable("MessageInfos");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -183,6 +213,15 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
|
||||
b.ToTable("WoodComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.MessageInfo", b =>
|
||||
{
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Messages")
|
||||
.HasForeignKey("ClientId");
|
||||
|
||||
b.Navigation("Client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Client", "Client")
|
||||
@ -229,6 +268,8 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
|
||||
|
||||
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Messages");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user