Skip to content

Commit

Permalink
auto-login
Browse files Browse the repository at this point in the history
  • Loading branch information
hoseinzadehashraf committed Jan 17, 2024
1 parent 565da3f commit 6c8316f
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Controllers/Pages/BaseLogin.Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ public partial class LoginForm : IViewModel
[ValidateNever]
public User Item { get; set; }
}
public partial class AutoLoginForm : IViewModel
{
public string Token { get; set; }
}
}
88 changes: 88 additions & 0 deletions Domain/Structure/AutoLoginClaim.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
namespace Olive.Microservices.Hub
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Olive;
using Olive.Entities;

/// <summary>Represents an instance of Email claim entity type.</summary>

public partial class AutoLoginClaim : GuidEntity
{
/// <summary>Initializes a new instance of the EmailClaim class.</summary>
public AutoLoginClaim()
{
Created = LocalTime.Now;
Expire = LocalTime.Now.AddSeconds(10);
}

/// <summary>Gets or sets the value of Created on this Email claim instance.</summary>
public DateTime Created { get; set; }
public DateTime Expire { get; set; }

/// <summary>Gets or sets the value of Email on this Email claim instance.</summary>
[System.ComponentModel.DataAnnotations.StringLength(200)]
public string Email { get; set; }

/// <summary>Gets or sets the value of Email on this Email claim instance.</summary>
[System.ComponentModel.DataAnnotations.StringLength(200)]
public string ReturnUrl { get; set; }

/// <summary>Gets or sets the value of Token on this Email claim instance.</summary>
[System.ComponentModel.DataAnnotations.StringLength(200)]
public string Token { get; set; }

/// <summary>
/// Find and returns an instance of Email claim from the database by its Token.<para/>
/// If no matching Email claim is found, it returns Null.<para/>
/// </summary>
/// <param name="token">The Token of the requested Email claim.</param>
/// <returns>
/// The Email claim instance with the specified Token or null if there is no Email claim with that Token in the database.<para/>
/// </returns>
public static Task<AutoLoginClaim> FindByToken(string token)
{
return Database.FirstOrDefault<AutoLoginClaim>(e => e.Token == token);
}

/// <summary>Returns a textual representation of this Email claim.</summary>
public override string ToString() => Email;

/// <summary>Returns a clone of this Email claim.</summary>
/// <returns>
/// A new Email claim object with the same ID of this instance and identical property values.<para/>
/// The difference is that this instance will be unlocked, and thus can be used for updating in database.<para/>
/// </returns>
public new AutoLoginClaim Clone() => (AutoLoginClaim)base.Clone();

/// <summary>
/// Validates the data for the properties of this Email claim and throws a ValidationException if an error is detected.<para/>
/// </summary>
protected override async Task ValidateProperties()
{
var result = new List<string>();

if (Email.IsEmpty())
result.Add("Email cannot be empty.");

if (Email?.Length > 200)
result.Add("The provided Email is too long. A maximum of 200 characters is acceptable.");

if (Token.IsEmpty())
result.Add("Token cannot be empty.");

if (Token?.Length > 200)
result.Add("The provided Token is too long. A maximum of 200 characters is acceptable.");

// Ensure uniqueness of Token.

if (await Database.Any<AutoLoginClaim>(e => e.Token == Token && e != this))
result.Add("Token must be unique. There is an existing Email claim record with the provided Token.");

if (result.Any())
throw new ValidationException(result.ToLinesString());
}
}
}
2 changes: 1 addition & 1 deletion Olive.Microservices.Hub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Authors>Geeks Ltd</Authors>
<RepositoryUrl>https://github.com/Geeksltd/Olive.Microservices.Hub/tree/master/Olive.Microservices.Hub</RepositoryUrl>
<PackageIcon>icon.png</PackageIcon>
<Version>1.5.38</Version>
<Version>1.5.39</Version>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<Nullable>warnings</Nullable>
Expand Down

0 comments on commit 6c8316f

Please sign in to comment.