Skip to content

Commit

Permalink
Merge pull request #19 from TechLiam/v1.3.0
Browse files Browse the repository at this point in the history
V1 3 0
  • Loading branch information
TechLiam authored Oct 18, 2019
2 parents b5c551f + 83b4b4a commit 34578a5
Show file tree
Hide file tree
Showing 24 changed files with 430 additions and 304 deletions.
2 changes: 1 addition & 1 deletion Examples/AskMessage/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void ConfigureServices(IServiceCollection services)
})
.AddSqrl(options =>
{
options.CheckMillieSeconds = 1000;
options.CheckMilliSeconds = 1000;
options.CreateUser = SqrlCreateUser;
options.UserExists = UserExists;
options.UpdateUserId = UpdateUserId;
Expand Down
2 changes: 1 addition & 1 deletion Examples/CustomLoginPage/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void ConfigureServices(IServiceCollection services)
})
.AddSqrl(options =>
{
options.CheckMillieSeconds = 1000;
options.CheckMilliSeconds = 1000;
options.CreateUser = SqrlCreateUser;
options.UserExists = UserExists;
options.UpdateUserId = UpdateUserId;
Expand Down
2 changes: 1 addition & 1 deletion Examples/CustomLoginPageWithHtmlHelpers/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void ConfigureServices(IServiceCollection services)
})
.AddSqrl(options =>
{
options.CheckMillieSeconds = 1000;
options.CheckMilliSeconds = 1000;
options.CreateUser = SqrlCreateUser;
options.UserExists = UserExists;
options.UpdateUserId = UpdateUserId;
Expand Down
2 changes: 1 addition & 1 deletion Examples/HelpersProvidersAndOtherPaths/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void ConfigureServices(IServiceCollection services)
})
.AddSqrl(options =>
{
options.CheckMillieSeconds = 1000;
options.CheckMilliSeconds = 1000;
options.CreateUser = SqrlCreateUser;
options.UserExists = UserExists;
options.UpdateUserId = UpdateUserId;
Expand Down
2 changes: 1 addition & 1 deletion Examples/InMemory/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void ConfigureServices(IServiceCollection services)
})
.AddSqrl(options =>
{
options.CheckMillieSeconds = 1000;
options.CheckMilliSeconds = 1000;
options.CreateUser = SqrlCreateUser;
options.UserExists = UserExists;
options.UpdateUserId = UpdateUserId;
Expand Down
59 changes: 26 additions & 33 deletions Examples/StoringNuts/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void ConfigureServices(IServiceCollection services)
})
.AddSqrl(options =>
{
options.CheckMillieSeconds = 1000;
options.CheckMilliSeconds = 1000;
options.CreateUser = SqrlCreateUser;
options.UserExists = UserExists;
options.UpdateUserId = UpdateUserId;
Expand All @@ -44,15 +44,12 @@ public void ConfigureServices(IServiceCollection services)

//These are used to manage nuts
options.StoreNut = StoreNut;
options.GetNut = GetNut;
options.RemoveNut = RemoveNut;
options.GetAndRemoveNut = GetAndRemoveNut;
options.GetNutIdk = GetNutIdk;
options.CheckNutAuthorized = CheckNutAuthorized;
options.RemoveAuthorizedNut = RemoveAuthorizedNut;

options.StoreCpsSessionId = StoreCpsSessionId;
options.GetUserIdByCpsSessionId = GetUserIdByCpsSessionId;
options.RemoveCpsSessionId = RemoveCpsSessionId;

options.GetUserIdAndRemoveCpsSessionId = GetUserIdAndRemoveCpsSessionId;
});

services.AddMvc();
Expand Down Expand Up @@ -158,16 +155,18 @@ private Task OnTicketReceived(TicketReceivedContext context)
/// </summary>
private static readonly Dictionary<string, NutInfo> AuthorizedNutList = new Dictionary<string, NutInfo>();

private NutInfo GetNut(string nut, bool authorized)
private NutInfo GetAndRemoveNut(string nut, HttpContext httpContext)
{
if (authorized)
if (NutList.ContainsKey(nut))
{
return AuthorizedNutList.ContainsKey(nut) ? AuthorizedNutList[nut] : null;
var info = NutList[nut];
NutList.Remove(nut);
return info;
}
return NutList.ContainsKey(nut) ? NutList[nut] : null;
return null;
}

private void StoreNut(string nut, NutInfo info, bool authorized)
private void StoreNut(string nut, NutInfo info, bool authorized, HttpContext arg4)
{
if (authorized)
{
Expand All @@ -179,46 +178,40 @@ private void StoreNut(string nut, NutInfo info, bool authorized)
}
}

private void RemoveNut(string nut, bool authorized)
private bool RemoveAuthorizedNut(string nut, HttpContext httpContext)
{
if (authorized)
var authorizedNut = AuthorizedNutList.SingleOrDefault(x => x.Key == nut || x.Value.FirstNut == nut);
if (authorizedNut.Key == nut)
{
AuthorizedNutList.Remove(nut);
return true;
}
else
{
NutList.Remove(nut);
}
return false;
}

private bool CheckNutAuthorized(string nut)
{
return AuthorizedNutList.Any(x => x.Key == nut || x.Value.FirstNut == nut);
}

private string GetNutIdk(string nut)
private string GetNutIdk(string nut, HttpContext httpContext)
{
return AuthorizedNutList.Single(x => x.Key == nut || x.Value.FirstNut == nut).Value.Idk;
}


private static readonly Dictionary<string, string> CpsSessions = new Dictionary<string, string>();

private void StoreCpsSessionId(string sessionId, string userId)
private void StoreCpsSessionId(string sessionId, string userId, HttpContext arg3)
{
CpsSessions.Add(sessionId, userId);
}

private string GetUserIdByCpsSessionId(string sessionId)
private string GetUserIdAndRemoveCpsSessionId(string sessionId, HttpContext httpContext)
{
return CpsSessions.ContainsKey(sessionId) ? CpsSessions[sessionId] : null;
}
if (CpsSessions.ContainsKey(sessionId))
{
var userId = CpsSessions[sessionId];
CpsSessions.Remove(userId);
return userId;
}

private void RemoveCpsSessionId(string sessionId)
{
CpsSessions.Remove(sessionId);
return null;
}


}
}
2 changes: 2 additions & 0 deletions Examples/WithDatabase/Database/DatabaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options
public DbSet<SqrlUser> SqrlUser { get; set; }

public DbSet<User> User { get; set; }

public DbSet<NutInfoData> Nuts { get; set; }

public void UpdateDatabase()
{
Expand Down
16 changes: 16 additions & 0 deletions Examples/WithDatabase/Database/NutInfoData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
using SqrlForNet;

namespace WithDatabase.Database
{
public class NutInfoData : NutInfo
{

[Key]
public string Nut { get; set; }

public bool Authorized { get; set; }

}
}
5 changes: 1 addition & 4 deletions Examples/WithDatabase/Database/User.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel;

namespace WithDatabase.Database
{
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,33 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace WithDatabase.Migrations
{
public partial class AddedNutStoreData : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Nuts",
columns: table => new
{
Nut = table.Column<string>(nullable: false),
CreatedDate = table.Column<DateTime>(nullable: false),
IpAddress = table.Column<string>(nullable: true),
FirstNut = table.Column<string>(nullable: true),
Idk = table.Column<string>(nullable: true),
Authorized = table.Column<bool>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Nuts", x => x.Nut);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Nuts");
}
}
}
26 changes: 26 additions & 0 deletions Examples/WithDatabase/Migrations/DatabaseContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
Expand All @@ -18,6 +19,31 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

modelBuilder.Entity("WithDatabase.Database.NutInfoData", b =>
{
b.Property<string>("Nut")
.HasColumnType("nvarchar(450)");

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

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

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

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

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

b.HasKey("Nut");

b.ToTable("Nuts");
});

modelBuilder.Entity("WithDatabase.Database.SqrlUser", b =>
{
b.Property<int>("Id")
Expand Down
Loading

0 comments on commit 34578a5

Please sign in to comment.