Skip to content

Commit

Permalink
feat: Implemented ResetPassword Tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiyarGHD committed Feb 25, 2024
1 parent d9fcc33 commit 7bd365c
Show file tree
Hide file tree
Showing 23 changed files with 4,837 additions and 467 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<IsPackable>true</IsPackable>
<Version>0.0.0.6</Version>
<Version>0.0.0.7</Version>
<Description>client generated code.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>microservice,Identity,Identity,client</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//using EasyMicroservices.IdentityMicroservice.Database.Entities;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces;
using EasyMicroservices.IdentityMicroservice.Database.Entities;
using Microsoft.EntityFrameworkCore;

namespace EasyMicroservices.IdentityMicroservice.Database.Contexts
Expand All @@ -11,7 +12,7 @@ public IdentityContext(IEntityFrameworkCoreDatabaseBuilder builder) : base(build
{
}

//public DbSet<IdentityEntity> Identity { get; set; }
public DbSet<ResetPasswordTokenEntity> ResetPasswordToken { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using EasyMicroservices.Cores.Interfaces;
using EasyMicroservices.IdentityMicroservice.Database.Schemas;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyMicroservices.IdentityMicroservice.Database.Entities
{
public class ResetPasswordTokenEntity : ResetPasswordTokenSchema, IIdSchema<long>
{
public long Id { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using EasyMicroservices.Cores.Database.Schemas;
using EasyMicroservices.Cores.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyMicroservices.IdentityMicroservice.Database.Schemas
{
public class ResetPasswordTokenSchema : FullAbilitySchema
{
public string Token { get; set; }
public bool HasConsumed { get; set; }
public DateTime ExpirationDateTime { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

<ItemGroup>
<Folder Include="Database\Documents\" />
<Folder Include="Database\Entities\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Configuration" Version="0.0.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.15" />
</ItemGroup>

<ItemGroup>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace EasyMicroservices.IdentityMicroservice.Migrations
{
/// <inheritdoc />
public partial class AddedResetPasswordTokens : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ResetPasswordToken",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CreationDateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
ModificationDateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
DeletedDateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
UniqueIdentity = table.Column<string>(type: "nvarchar(450)", nullable: true, collation: "SQL_Latin1_General_CP1_CS_AS"),
Token = table.Column<string>(type: "nvarchar(max)", nullable: true),
HasConsumed = table.Column<bool>(type: "bit", nullable: false),
ExpirationDateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ResetPasswordToken", x => x.Id);
});

migrationBuilder.CreateIndex(
name: "IX_ResetPasswordToken_CreationDateTime",
table: "ResetPasswordToken",
column: "CreationDateTime");

migrationBuilder.CreateIndex(
name: "IX_ResetPasswordToken_DeletedDateTime",
table: "ResetPasswordToken",
column: "DeletedDateTime");

migrationBuilder.CreateIndex(
name: "IX_ResetPasswordToken_IsDeleted",
table: "ResetPasswordToken",
column: "IsDeleted");

migrationBuilder.CreateIndex(
name: "IX_ResetPasswordToken_ModificationDateTime",
table: "ResetPasswordToken",
column: "ModificationDateTime");

migrationBuilder.CreateIndex(
name: "IX_ResetPasswordToken_UniqueIdentity",
table: "ResetPasswordToken",
column: "UniqueIdentity");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ResetPasswordToken");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// <auto-generated />
using System;
using EasyMicroservices.IdentityMicroservice.Database.Contexts;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

#nullable disable

namespace EasyMicroservices.IdentityMicroservice.Migrations
{
[DbContext(typeof(IdentityContext))]
partial class IdentityContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.15")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

modelBuilder.Entity("EasyMicroservices.IdentityMicroservice.Database.Entities.ResetPasswordTokenEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");

SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));

b.Property<DateTime>("CreationDateTime")
.HasColumnType("datetime2");

b.Property<DateTime?>("DeletedDateTime")
.HasColumnType("datetime2");

b.Property<DateTime>("ExpirationDateTime")
.HasColumnType("datetime2");

b.Property<bool>("HasConsumed")
.HasColumnType("bit");

b.Property<bool>("IsDeleted")
.HasColumnType("bit");

b.Property<DateTime?>("ModificationDateTime")
.HasColumnType("datetime2");

b.Property<string>("Token")
.HasColumnType("nvarchar(max)");

b.Property<string>("UniqueIdentity")
.HasColumnType("nvarchar(450)")
.UseCollation("SQL_Latin1_General_CP1_CS_AS");

b.HasKey("Id");

b.HasIndex("CreationDateTime");

b.HasIndex("DeletedDateTime");

b.HasIndex("IsDeleted");

b.HasIndex("ModificationDateTime");

b.HasIndex("UniqueIdentity");

b.ToTable("ResetPasswordToken");
});
#pragma warning restore 612, 618
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyMicroservices.IdentityMicroservice.Contracts.Common
{
public class ResetPasswordTokenContract
{
public long Id { get; set; }
public string Token { get; set; }
public string UniqueIdentity { get; set; }
public bool HasConsumed { get; set; }
public DateTime ExpirationDateTime { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyMicroservices.IdentityMicroservice.Contracts.Requests
{
public class ConsumeResetPasswordTokenRequestContract
{
public string Token { get; set; }
public string Password { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyMicroservices.IdentityMicroservice.Contracts.Requests
{
public class GenerateResetPasswordTokenRequestContract
{
public long ExpireTimeInSeconds { get; set; }
public string UniqueIdentity { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyMicroservices.IdentityMicroservice.Contracts.Requests
{
public class ValidateResetPasswordTokenRequestContract
{
public string Token { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Cores.AspEntityFrameworkCoreApi" Version="0.0.1.43" />
<PackageReference Include="EasyMicroservices.Cores.AspEntityFrameworkCoreApi" Version="0.0.1.55" />
<PackageReference Include="EasyMicroservices.Logger" Version="0.0.0.6" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Mapper.CompileTimeMapper" Version="0.0.0.6" />
<PackageReference Include="EasyMicroservices.Mapper.SerializerMapper" Version="0.0.0.3" />
<PackageReference Include="EasyMicroservices.Mapper.CompileTimeMapper" Version="0.0.0.7" />
<PackageReference Include="EasyMicroservices.Mapper.SerializerMapper" Version="0.0.0.7" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.9" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.2.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,16 @@ namespace EasyMicroservices.IdentityMicroservice.Helpers
{
public static class SecurityHelper
{
public static string Hash(string password)
{
var crypt = new SHA256Managed();
var hash = new StringBuilder();
byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(password));
foreach (byte theByte in crypto)
{
hash.Append(theByte.ToString("x2"));
}
return hash.ToString();
}
}
}
Loading

0 comments on commit 7bd365c

Please sign in to comment.