registration #18

Merged
mfnefd merged 10 commits from registration into main 2024-06-22 21:17:48 +04:00
27 changed files with 1355 additions and 263 deletions

View File

@ -25,11 +25,14 @@ namespace BusinessLogic.BusinessLogic
{
private readonly ILogger _logger;
private readonly IUserStorage _userStorage;
private readonly ITwoFactorAuthService _twoFactorAuthService;
public UserLogic(ILogger<UserLogic> logger, IUserStorage userStorage)
public UserLogic(ILogger<UserLogic> logger, IUserStorage userStorage,
ITwoFactorAuthService twoFactorAuthService)
{
_logger = logger;
_userStorage = userStorage;
_twoFactorAuthService = twoFactorAuthService;
}
public string Create(UserBindingModel model)
@ -53,6 +56,9 @@ namespace BusinessLogic.BusinessLogic
MailSender.Send(new MailRegistration(user));
string code = _twoFactorAuthService.GenerateCode();
MailSender.Send(new MailTwoFactorCode(user, code));
return JwtProvider.Generate(user);
}
@ -132,6 +138,10 @@ namespace BusinessLogic.BusinessLogic
{
throw new AccountException("The passwords don't match.");
}
string code = _twoFactorAuthService.GenerateCode();
MailSender.Send(new MailTwoFactorCode(user, code));
return JwtProvider.Generate(user);
}
@ -166,5 +176,10 @@ namespace BusinessLogic.BusinessLogic
throw new AccountException("The email is not valid.");
}
}
public bool VerifyCode(string code)
{
return _twoFactorAuthService.Verify(code);
}
}
}

View File

@ -6,10 +6,11 @@ using System.Threading.Tasks;
namespace BusinessLogic.Tools.Mail
{
public class Mail
{
public IEnumerable<string> To { get; set; } = null!;
public string Title { get; set; } = null!;
public string Body { get; set; } = null!;
}
public class Mail
{
public IEnumerable<string> To { get; set; } = null!;
public string Title { get; set; } = null!;
public string Body { get; set; } = null!;
public bool IsSendable { get; set; } = true;
}
}

View File

@ -8,39 +8,41 @@ using System.Threading.Tasks;
namespace BusinessLogic.Tools.Mail
{
public class MailSender
{
private static string _email;
private static string _password;
private static string _smtpClientHost;
private static short _smtpClientPort;
public class MailSender
{
private static string _email;
private static string _password;
private static string _smtpClientHost;
private static short _smtpClientPort;
public void SetupMailOptions(MailOptions options)
{
_email = options.Email;
_password = options.Password;
_smtpClientHost = options.SmtpClientHost;
_smtpClientPort = options.SmtpClientPort;
}
public void SetupMailOptions(MailOptions options)
{
_email = options.Email;
_password = options.Password;
_smtpClientHost = options.SmtpClientHost;
_smtpClientPort = options.SmtpClientPort;
}
public static void Send(Mail mail)
{
using SmtpClient client = new SmtpClient(_smtpClientHost, _smtpClientPort);
client.Credentials = new NetworkCredential(_email, _password);
client.EnableSsl = true;
public static void Send(Mail mail)
{
if (!mail.IsSendable) return;
using MailMessage message = new MailMessage();
using SmtpClient client = new SmtpClient(_smtpClientHost, _smtpClientPort);
client.Credentials = new NetworkCredential(_email, _password);
client.EnableSsl = true;
message.From = new MailAddress(_email);
foreach (string to in mail.To)
{
message.To.Add(to);
}
using MailMessage message = new MailMessage();
message.Subject = mail.Title;
message.Body = mail.Body;
message.From = new MailAddress(_email);
foreach (string to in mail.To)
{
message.To.Add(to);
}
client.Send(message);
}
}
message.Subject = mail.Title;
message.Body = mail.Body;
client.Send(message);
}
}
}

View File

@ -8,14 +8,18 @@ using System.Threading.Tasks;
namespace BusinessLogic.Tools.Mail.MailTemplates
{
public class MailRegistration : Mail
{
public MailRegistration(UserBindingModel user)
{
To = [user.Email];
Title = "Приветствуем Вас на нашем сайте!";
Body = $"Спасибо, {user.SecondName} {user.FirstName}, что выбрали НАС.\n" +
$"Надеемся, что Вам что-то уже приглянулось!";
}
}
public class MailRegistration : Mail
{
public MailRegistration(UserBindingModel user)
{
if (user.OnlyImportantMails)
{
IsSendable = false;
}
To = [user.Email];
Title = "Приветствуем Вас на нашем сайте!";
Body = $"Спасибо, {user.SecondName} {user.FirstName}, что выбрали НАС.\n" +
$"Надеемся, что Вам что-то уже приглянулось!";
}
}
}

View File

@ -0,0 +1,21 @@
using Contracts.BindingModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.Tools.Mail.MailTemplates
{
public class MailTwoFactorCode : Mail
{
public MailTwoFactorCode(UserBindingModel user, string code)
{
To = [user.Email];
Title = "Ваш код для подтверждения";
Body = $"Здравствуйте, {user.SecondName} {user.FirstName}! Вот Ваш код для подтверждения:\n" +
$"{code}\n" +
$"Если это не Вы, игноритруйте это сообщение.";
}
}
}

View File

@ -0,0 +1,42 @@
using Contracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.Tools
{
public class TwoFactorAuthService : ITwoFactorAuthService
{
private string _code = string.Empty;
private const int LENGTH_CODE = 5;
public string GenerateCode()
{
_code = _getCode(LENGTH_CODE);
return _code;
}
private string _getCode(int length)
{
string res = "";
var rand = new Random();
for (int i = 0; i < length; i++)
{
res += rand.Next(0, 9).ToString();
}
return res;
}
public bool Verify(string code)
{
if (_code == string.Empty)
{
throw new Exception("Source code is not generated.");
}
return _code == code;
}
}
}

View File

@ -6,15 +6,16 @@ using System.Threading.Tasks;
namespace Contracts.BindingModels
{
public class UserBindingModel
{
public Guid Id { get; set; }
public string FirstName { get; set; } = string.Empty;
public string SecondName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string PasswordHash { get; set; } = string.Empty;
public string? Password { get; set; }
public DateTime Birthday { get; set; }
public RoleBindingModel Role { get; set; } = null!;
}
public class UserBindingModel
{
public Guid Id { get; set; }
public string FirstName { get; set; } = string.Empty;
public string SecondName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string PasswordHash { get; set; } = string.Empty;
public string? Password { get; set; }
public DateTime Birthday { get; set; }
public bool OnlyImportantMails { get; set; }
public RoleBindingModel Role { get; set; } = null!;
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BusinessLogicContracts
{
public interface ITwoFactorAuthService
{
string GenerateCode();
bool Verify(string code);
}
}

View File

@ -10,18 +10,20 @@ using System.Threading.Tasks;
namespace Contracts.BusinessLogicContracts
{
public interface IUserLogic
{
string Login(string email, string password);
public interface IUserLogic
{
string Login(string email, string password);
string Create(UserBindingModel model);
bool VerifyCode(string code);
UserViewModel Update(UserBindingModel model);
string Create(UserBindingModel model);
UserViewModel ReadElement(UserSearchModel model);
UserViewModel Update(UserBindingModel model);
IEnumerable<UserViewModel> ReadElements(UserSearchModel? model);
UserViewModel ReadElement(UserSearchModel model);
UserViewModel Delete(UserSearchModel model);
}
IEnumerable<UserViewModel> ReadElements(UserSearchModel? model);
UserViewModel Delete(UserSearchModel model);
}
}

View File

@ -8,26 +8,28 @@ using System.Threading.Tasks;
namespace Contracts.Converters
{
public static class UserConverter
{
public static UserViewModel ToView(UserBindingModel model) => new()
{
Id = model.Id,
FirstName = model.FirstName,
SecondName = model.SecondName,
Email = model.Email,
Birthday = model.Birthday,
Role = RoleConverter.ToView(model.Role),
};
public static class UserConverter
{
public static UserViewModel ToView(UserBindingModel model) => new()
{
Id = model.Id,
FirstName = model.FirstName,
SecondName = model.SecondName,
Email = model.Email,
Birthday = model.Birthday,
OnlyImportantMails = model.OnlyImportantMails,
Role = RoleConverter.ToView(model.Role),
};
public static UserBindingModel ToBinding(UserViewModel model) => new()
{
Id = model.Id,
FirstName = model.FirstName,
SecondName = model.SecondName,
Email = model.Email,
Birthday = model.Birthday,
Role = RoleConverter.ToBinding(model.Role),
};
}
public static UserBindingModel ToBinding(UserViewModel model) => new()
{
Id = model.Id,
FirstName = model.FirstName,
SecondName = model.SecondName,
Email = model.Email,
Birthday = model.Birthday,
OnlyImportantMails = model.OnlyImportantMails,
Role = RoleConverter.ToBinding(model.Role),
};
}
}

View File

@ -6,9 +6,10 @@ using System.Threading.Tasks;
namespace Contracts.SearchModels
{
public class UserSearchModel
{
public Guid? Id { get; set; }
public string? Email { get; set; }
}
public class UserSearchModel
{
public Guid? Id { get; set; }
public string? Email { get; set; }
public bool? OnlyImportantMails { get; set; }
}
}

View File

@ -6,13 +6,14 @@ using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class UserViewModel
{
public Guid Id { get; set; }
public string FirstName { get; set; } = string.Empty;
public string SecondName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public DateTime Birthday { get; set; }
public RoleViewModel Role { get; set; } = null!;
}
public class UserViewModel
{
public Guid Id { get; set; }
public string FirstName { get; set; } = string.Empty;
public string SecondName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public DateTime Birthday { get; set; }
public bool OnlyImportantMails { get; set; }
public RoleViewModel Role { get; set; } = null!;
}
}

View File

@ -6,12 +6,13 @@ using System.Threading.Tasks;
namespace DataModels.Models
{
public interface IUser : IId
{
string FirstName { get; }
string SecondName { get; }
string PasswordHash { get; }
string Email { get; }
DateTime Birthday { get; }
}
public interface IUser : IId
{
string FirstName { get; }
string SecondName { get; }
string PasswordHash { get; }
string Email { get; }
DateTime Birthday { get; }
bool OnlyImportantMails { get; }
}
}

View File

@ -32,7 +32,7 @@ namespace DatabaseImplement.Implements
public RoleBindingModel? GetElement(RoleSearchModel model)
{
if (model.Id is null && string.IsNullOrWhiteSpace(model.Name))
if (model.Id is null && string.IsNullOrWhiteSpace(model?.Name))
{
return null;
}
@ -46,7 +46,7 @@ namespace DatabaseImplement.Implements
public IEnumerable<RoleBindingModel> GetList(RoleSearchModel? model)
{
var context = new Database();
if (model is null && string.IsNullOrWhiteSpace(model.Name))
if (model is null && string.IsNullOrWhiteSpace(model?.Name))
{
return context.Roles.Select(r => r.GetBindingModel());
}

View File

@ -12,98 +12,99 @@ using System.Threading.Tasks;
namespace DatabaseImplement.Implements
{
public class UserStorage : IUserStorage
{
public UserBindingModel? Delete(UserSearchModel model)
{
if (model.Id is null && model.Email is null)
{
return null;
}
public class UserStorage : IUserStorage
{
public UserBindingModel? Delete(UserSearchModel model)
{
if (model.Id is null && model.Email is null)
{
return null;
}
var context = new Database();
var user = context.Users.FirstOrDefault(u =>
(model.Id.HasValue && u.Id == model.Id)
|| (!string.IsNullOrEmpty(u.Email) && u.Email.Contains(model.Email)));
var context = new Database();
var user = context.Users.FirstOrDefault(u =>
(model.Id.HasValue && u.Id == model.Id)
|| (!string.IsNullOrEmpty(u.Email) && u.Email.Contains(model.Email)));
if (user is null)
{
return null;
}
context.Remove(user);
context.SaveChanges();
if (user is null)
{
return null;
}
context.Remove(user);
context.SaveChanges();
return user.GetBindingModel();
}
return user.GetBindingModel();
}
public UserBindingModel? GetElement(UserSearchModel model)
{
if (model.Id is null && model.Email is null)
{
return null;
}
var context = new Database();
return context.Users
.Include(u => u.Role)
.FirstOrDefault(u =>
(model.Id.HasValue && u.Id == model.Id)
|| (!string.IsNullOrEmpty(u.Email) && u.Email.Contains(model.Email)))
?.GetBindingModel();
}
public UserBindingModel? GetElement(UserSearchModel model)
{
if (model.Id is null && model.Email is null)
{
return null;
}
var context = new Database();
return context.Users
.Include(u => u.Role)
.FirstOrDefault(u =>
(model.Id.HasValue && u.Id == model.Id)
|| (!string.IsNullOrEmpty(u.Email) && u.Email.Contains(model.Email)))
?.GetBindingModel();
}
public IEnumerable<UserBindingModel> GetList(UserSearchModel? model)
{
var context = new Database();
if (model is null)
{
return context.Users
.Include(u => u.Role)
.Select(r => r.GetBindingModel());
}
if (model.Id is null && model.Email is null)
{
return [];
}
return context.Users
.Where(u =>
(model.Id.HasValue && u.Id == model.Id)
|| (!string.IsNullOrEmpty(u.Email) && u.Email.Contains(model.Email)))
.Include(u => u.Role)
.Select(r => r.GetBindingModel());
}
public IEnumerable<UserBindingModel> GetList(UserSearchModel? model)
{
var context = new Database();
if (model is null)
{
return context.Users
.Include(u => u.Role)
.Select(r => r.GetBindingModel());
}
if (model.Id is null && model.Email is null && !model.OnlyImportantMails is null)
{
return [];
}
return context.Users
.Where(u =>
(model.Id.HasValue && u.Id == model.Id)
|| (!string.IsNullOrEmpty(u.Email) && u.Email.Contains(model.Email))
|| (model.OnlyImportantMails.HasValue && u.OnlyImportantMails == model.OnlyImportantMails))
.Include(u => u.Role)
.Select(r => r.GetBindingModel());
}
public UserBindingModel? Insert(UserBindingModel model)
{
var context = new Database();
var role = context.Roles.FirstOrDefault(r => r.Id == model.Role.Id);
if (role is null)
{
return null;
}
var newUser = Models.User.ToUserFromBinding(model, role);
public UserBindingModel? Insert(UserBindingModel model)
{
var context = new Database();
var role = context.Roles.FirstOrDefault(r => r.Id == model.Role.Id);
if (role is null)
{
return null;
}
var newUser = Models.User.ToUserFromBinding(model, role);
context.Users.Add(newUser);
context.SaveChanges();
context.Users.Add(newUser);
context.SaveChanges();
return newUser.GetBindingModel();
}
return newUser.GetBindingModel();
}
public UserBindingModel? Update(UserBindingModel model)
{
var context = new Database();
var user = context.Users
.FirstOrDefault(u => u.Id == model.Id);
var role = context.Roles.FirstOrDefault(r => r.Id == model.Role.Id);
public UserBindingModel? Update(UserBindingModel model)
{
var context = new Database();
var user = context.Users
.FirstOrDefault(u => u.Id == model.Id);
var role = context.Roles.FirstOrDefault(r => r.Id == model.Role.Id);
if (user is null || role is null)
{
return null;
}
if (user is null || role is null)
{
return null;
}
user.Update(model, role);
user.Update(model, role);
context.SaveChanges();
return user.GetBindingModel();
}
}
context.SaveChanges();
return user.GetBindingModel();
}
}
}

View File

@ -0,0 +1,326 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240622162300_second")]
partial class second
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Location")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("SecondName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany("Products")
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany()
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supply", "Supply")
.WithMany("Products")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supply");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.HasOne("DatabaseImplement.Models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId");
b.Navigation("Role");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Navigation("Products");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,221 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class second : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "OnlyImportantMails",
table: "Users",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.CreateTable(
name: "MediaFiles",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Location = table.Column<string>(type: "text", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MediaFiles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Products",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Price = table.Column<double>(type: "double precision", nullable: false),
Rate = table.Column<double>(type: "double precision", nullable: false),
IsBeingSold = table.Column<bool>(type: "boolean", nullable: false),
Amount = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Products", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Purchases",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
DatePurchase = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Purchases", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Sells",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
DateSell = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Sells", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Suppliers",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Deals = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Suppliers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "SupplierProducts",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
SupplierId = table.Column<Guid>(type: "uuid", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SupplierProducts", x => x.Id);
table.ForeignKey(
name: "FK_SupplierProducts_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_SupplierProducts_Suppliers_SupplierId",
column: x => x.SupplierId,
principalTable: "Suppliers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Supplies",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Price = table.Column<double>(type: "double precision", nullable: false),
SupplierId = table.Column<Guid>(type: "uuid", nullable: false),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Supplies", x => x.Id);
table.ForeignKey(
name: "FK_Supplies_Suppliers_SupplierId",
column: x => x.SupplierId,
principalTable: "Suppliers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "SupplyProducts",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
SupplyId = table.Column<Guid>(type: "uuid", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SupplyProducts", x => x.Id);
table.ForeignKey(
name: "FK_SupplyProducts_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_SupplyProducts_Supplies_SupplyId",
column: x => x.SupplyId,
principalTable: "Supplies",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_SupplierProducts_ProductId",
table: "SupplierProducts",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_SupplierProducts_SupplierId",
table: "SupplierProducts",
column: "SupplierId");
migrationBuilder.CreateIndex(
name: "IX_Supplies_SupplierId",
table: "Supplies",
column: "SupplierId");
migrationBuilder.CreateIndex(
name: "IX_SupplyProducts_ProductId",
table: "SupplyProducts",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_SupplyProducts_SupplyId",
table: "SupplyProducts",
column: "SupplyId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "MediaFiles");
migrationBuilder.DropTable(
name: "Purchases");
migrationBuilder.DropTable(
name: "Sells");
migrationBuilder.DropTable(
name: "SupplierProducts");
migrationBuilder.DropTable(
name: "SupplyProducts");
migrationBuilder.DropTable(
name: "Products");
migrationBuilder.DropTable(
name: "Supplies");
migrationBuilder.DropTable(
name: "Suppliers");
migrationBuilder.DropColumn(
name: "OnlyImportantMails",
table: "Users");
}
}
}

View File

@ -22,6 +22,72 @@ namespace DatabaseImplement.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Location")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
@ -37,6 +103,115 @@ namespace DatabaseImplement.Migrations
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
@ -54,6 +229,9 @@ namespace DatabaseImplement.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
@ -72,6 +250,55 @@ namespace DatabaseImplement.Migrations
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany("Products")
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany()
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supply", "Supply")
.WithMany("Products")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supply");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.HasOne("DatabaseImplement.Models.Role", "Role")
@ -80,6 +307,16 @@ namespace DatabaseImplement.Migrations
b.Navigation("Role");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Navigation("Products");
});
#pragma warning restore 612, 618
}
}

View File

@ -4,6 +4,7 @@ using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
@ -11,72 +12,77 @@ using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
public class User : IUser
{
public Guid Id { get; set; }
public class User : IUser
{
public Guid Id { get; set; }
[Required]
public string FirstName { get; set; } = string.Empty;
[Required]
public string FirstName { get; set; } = string.Empty;
[Required]
public string SecondName { get; set; } = string.Empty;
[Required]
public string SecondName { get; set; } = string.Empty;
[Required]
public string PasswordHash { get; set; } = string.Empty;
[Required]
public string PasswordHash { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public DateTime Birthday { get; set; }
[Required]
public DateTime Birthday { get; set; }
public Role? Role { get; set; }
public Role? Role { get; set; }
public UserBindingModel GetBindingModel() => new()
{
Id = Id,
FirstName = FirstName,
SecondName = SecondName,
Email = Email,
PasswordHash = PasswordHash,
Birthday = Birthday,
Role = Role?.GetBindingModel() ?? new()
};
public bool OnlyImportantMails { get; set; } = false;
public static User ToUserFromView(UserViewModel model, Role role) => new()
{
Id = model.Id,
FirstName = model.FirstName,
SecondName = model.SecondName,
Email = model.Email,
Birthday = model.Birthday,
Role = role
};
public UserBindingModel GetBindingModel() => new()
{
Id = Id,
FirstName = FirstName,
SecondName = SecondName,
Email = Email,
PasswordHash = PasswordHash,
Birthday = Birthday,
OnlyImportantMails = OnlyImportantMails,
Role = Role?.GetBindingModel() ?? new()
};
public static User ToUserFromBinding(UserBindingModel model, Role role) => new()
{
Id = model.Id,
FirstName = model.FirstName,
SecondName = model.SecondName,
Email = model.Email,
PasswordHash = model.PasswordHash,
Birthday = model.Birthday,
Role = role
};
public static User ToUserFromView(UserViewModel model, Role role) => new()
{
Id = model.Id,
FirstName = model.FirstName,
SecondName = model.SecondName,
Email = model.Email,
Birthday = model.Birthday,
Role = role
};
public void Update(UserBindingModel model, Role role)
{
if (model is null)
{
throw new ArgumentNullException("Update user: binding model is null");
}
public static User ToUserFromBinding(UserBindingModel model, Role role) => new()
{
Id = model.Id,
FirstName = model.FirstName,
SecondName = model.SecondName,
Email = model.Email,
PasswordHash = model.PasswordHash,
Birthday = model.Birthday,
OnlyImportantMails = model.OnlyImportantMails,
Role = role
};
Email = model.Email;
FirstName = model.FirstName;
SecondName = model.SecondName;
PasswordHash = model.PasswordHash;
Birthday = model.Birthday;
Role = role;
}
}
public void Update(UserBindingModel model, Role role)
{
if (model is null)
{
throw new ArgumentNullException("Update user: binding model is null");
}
Email = model.Email ?? Email;
FirstName = model.FirstName ?? FirstName;
SecondName = model.SecondName ?? SecondName;
PasswordHash = model.PasswordHash ?? PasswordHash;
Birthday = model.Birthday;
OnlyImportantMails = model.OnlyImportantMails;
Role = role ?? Role;
}
}
}

View File

@ -46,6 +46,21 @@ namespace RestAPI.Controllers
}
}
[HttpPost]
public IResult VerifyCode([FromBody] VerifyCodeData data)
{
try
{
var res = _userLogic.VerifyCode(data.code);
return Results.Ok(res);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error verify code");
return Results.Problem(ex.Message);
}
}
[HttpPost]
public IResult Registration([FromBody] UserBindingModel model)
{
@ -128,4 +143,5 @@ namespace RestAPI.Controllers
}
public record class UserData(string email, string password);
public record class VerifyCodeData(string code);
}

View File

@ -20,6 +20,7 @@ builder.Logging.AddLog4Net("log4net.config");
builder.Services.AddTransient<IRoleLogic, RoleLogic>();
builder.Services.AddTransient<IUserLogic, UserLogic>();
builder.Services.AddSingleton<ITwoFactorAuthService, TwoFactorAuthService>();
builder.Services.AddTransient<IRoleStorage, RoleStorage>();
builder.Services.AddTransient<IUserStorage, UserStorage>();
@ -34,7 +35,7 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc(VERSION, new OpenApiInfo { Title = TITLE, Version = VERSION });
c.SwaggerDoc(VERSION, new OpenApiInfo { Title = TITLE, Version = VERSION });
});
var app = builder.Build();
@ -46,15 +47,15 @@ var mailSender = app.Services.GetService<MailSender>();
string? getSection(string section) => builder.Configuration?.GetSection(section)?.Value?.ToString();
jwtProvider?.SetupJwtOptions(new()
{
SecretKey = getSection("JwtOptions:SecretKey") ?? string.Empty,
ExpiresHours = Convert.ToInt16(getSection("JwtOptions:ExpiresHours"))
SecretKey = getSection("JwtOptions:SecretKey") ?? string.Empty,
ExpiresHours = Convert.ToInt16(getSection("JwtOptions:ExpiresHours"))
});
mailSender?.SetupMailOptions(new()
{
Email = getSection("MailOptions:Email") ?? string.Empty,
Password = getSection("MailOptions:Password") ?? string.Empty,
SmtpClientHost = getSection("MailOptions:SmtpClientHost") ?? string.Empty,
SmtpClientPort = Convert.ToInt16(getSection("MailOptions:SmtpClientPort"))
Email = getSection("MailOptions:Email") ?? string.Empty,
Password = getSection("MailOptions:Password") ?? string.Empty,
SmtpClientHost = getSection("MailOptions:SmtpClientHost") ?? string.Empty,
SmtpClientPort = Convert.ToInt16(getSection("MailOptions:SmtpClientPort"))
});
#endregion Setup config
@ -62,8 +63,8 @@ mailSender?.SetupMailOptions(new()
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint($"/swagger/{VERSION}/swagger.json", $"{TITLE} {VERSION}"));
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint($"/swagger/{VERSION}/swagger.json", $"{TITLE} {VERSION}"));
}
app.UseHttpsRedirection();

View File

@ -20,9 +20,9 @@ namespace WebApp.Pages
throw new Exception("Something wrong LOL!");
}
this.SetJWT((string)response);
TempData["jwt"] = (string)response;
return RedirectToPage("Index");
return RedirectToPage("TwoFactor");
}
}
}

View File

@ -74,6 +74,13 @@
</label>
</div>
<div class="form-check d-flex justify-content-center mb-4">
<input asp-for="UserModel.OnlyImportantMails" class="form-check-input me-2" type="checkbox" id="policy" />
<label class="form-check-label" for="policy">
Send only important mails
</label>
</div>
<!-- Submit button -->
<button type="submit" data-mdb-button-init data-mdb-ripple-init class="btn btn-primary btn-block mb-4">
Sign up

View File

@ -30,9 +30,9 @@ namespace WebApp.Pages
throw new Exception("Something wrong LOL!");
}
this.SetJWT((string)response);
TempData["jwt"] = (string)response;
return RedirectToPage("Index");
return RedirectToPage("TwoFactor");
}
}
}

View File

@ -0,0 +1,128 @@
@page
@model WebApp.Pages.TwoFactorModel
<div class="row justify-content-center mt-7">
<style>
.icon-circle[class*=text-] [fill]:not([fill=none]), .icon-circle[class*=text-] svg:not([fill=none]), .svg-icon[class*=text-] [fill]:not([fill=none]), .svg-icon[class*=text-] svg:not([fill=none]) {
fill: currentColor !important;
}
.svg-icon-xl > svg {
width: 3.25rem;
height: 3.25rem;
}
.hover-lift-light {
transition: box-shadow .25s ease,transform .25s ease,color .25s ease,background-color .15s ease-in;
}
.mt-4 {
margin-top: 1.5rem !important;
}
.w-100 {
width: 100% !important;
}
.btn-group-lg > .btn, .btn-lg {
padding: 0.8rem 1.85rem;
font-size: 1.1rem;
border-radius: 0.3rem;
}
.btn-purple {
color: #fff;
background-color: #6672e8;
border-color: #6672e8;
}
.text-center {
text-align: center !important;
}
.py-4 {
padding-top: 1.5rem !important;
padding-bottom: 1.5rem !important;
}
.form-control-lg {
min-height: calc(1.5em + 1rem + 2px);
padding: 0.5rem 1rem;
font-size: 1.25rem;
border-radius: 0.3rem;
}
.form-control {
display: block;
width: 100%;
padding: 0.375rem 0.75rem;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #1e2e50;
background-color: #f6f9fc;
background-clip: padding-box;
border: 1px solid #dee2e6;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border-radius: 0.25rem;
transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}
</style>
<div class="col-lg-5 text-center">
<a href="index.html">
<img src="assets/img/svg/logo.svg" alt="">
</a>
<div class="card mt-5">
<div class="card-body py-5 px-lg-5">
<div class="svg-icon svg-icon-xl text-purple">
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512"><title>ionicons-v5-g</title><path d="M336,208V113a80,80,0,0,0-160,0v95" style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"></path><rect x="96" y="208" width="320" height="272" rx="48" ry="48" style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"></rect></svg>
</div>
<h3 class="fw-normal text-dark mt-4">
2-step verification
</h3>
<p class="mt-4 mb-1">
We sent a verification code to your email.
</p>
<p>
Please enter the code in the field below.
</p>
<form method="post">
<div class="row mt-4 pt-2">
<div class="col">
<input type="text" maxlength="1" class="form-control form-control-lg text-center py-4"
name="code" required autofocus>
</div>
<div class="col">
<input type="text" maxlength="1" class="form-control form-control-lg text-center py-4"
name="code" required>
</div>
<div class="col">
<input type="text" maxlength="1" class="form-control form-control-lg text-center py-4"
name="code" required>
</div>
<div class="col">
<input type="text" maxlength="1" class="form-control form-control-lg text-center py-4"
name="code" required>
</div>
<div class="col">
<input type="text" maxlength="1" class="form-control form-control-lg text-center py-4"
name="code" required>
</div>
</div>
<button type="submit" class="btn btn-purple btn-lg w-100 hover-lift-light mt-4">
Verify my account
</button>
</form>
</div>
</div>
<p class="text-center text-muted mt-4">
Didn't receive it?
<a href="#!" class="text-decoration-none ms-2">
Resend code
</a>
</p>
</div>
</div>

View File

@ -0,0 +1,35 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages
{
public class TwoFactorModel : PageModel
{
[BindProperty]
public int[] Code { get; set; } = [];
public void OnGet()
{
}
public IActionResult OnPost(string[] code)
{
var stringCode = string.Join(string.Empty, Code);
if (string.IsNullOrEmpty(stringCode))
{
throw new Exception("Looo");
}
var response = (string)APIClient.PostRequest("user/verifycode", new { code = stringCode });
var isCorrect = Convert.ToBoolean(response);
if (isCorrect)
{
this.SetJWT((string)TempData["jwt"]);
return RedirectToPage("Index");
}
else
{
throw new Exception("Wrong code! Please retry");
}
}
}
}

View File

@ -37,6 +37,12 @@
<input asp-for="UserModel.Birthday" type="date" id="birthday" class="form-control" />
<label class="form-label" for="birthday">Birthday</label>
</div>
<!-- Sending Policy input -->
<div class="form-outline mb-4">
<input asp-for="UserModel.OnlyImportantMails" type="checkbox" id="policy" />
<label class="form-label" for="policy">Send only important mails</label>
</div>
<!-- Hidden inputs -->
<input type="hidden" asp-for="UserModel.Id" />