-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
565da3f
commit 6c8316f
Showing
3 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters