Skip to content

Instantly share code, notes, and snippets.

View jjwilliams42's full-sized avatar
💭
<3 code

Josh Williams jjwilliams42

💭
<3 code
View GitHub Profile
@jjwilliams42
jjwilliams42 / CustomPasswordHasher.cs
Created November 18, 2017 08:56
Custom Password Hasher
public class CustomPasswordHasher : IPasswordHasher
{
public IPasswordHasher<User> AspNetPasswordHasher { get; set; }
public byte Version => throw new NotImplementedException();
public CustomPasswordHasher(IPasswordHasher<User> ph)
{
AspNetPasswordHasher = ph;
}
@jjwilliams42
jjwilliams42 / Startup.cs
Last active November 18, 2017 08:54
Startup.cs - Configure
namespace Test
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}
@jjwilliams42
jjwilliams42 / User.cs
Created November 18, 2017 07:57
AspNetUser : IUserAuth
[Alias("AspNetUsers")]
public class User : IUserAuth
{
[Index]
public string Email { get; set; }
[Required]
public bool EmailConfirmed { get; set; } = false;
public string PasswordHash { get; set; }
@jjwilliams42
jjwilliams42 / CustomAuthProvider.cs
Last active October 9, 2019 11:21
ServiceStack Custom Auth Provider
public class CustomAuthProvider : CredentialsAuthProvider
{
public override IHttpResult OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo)
{
var dbFactory = authService.ResolveService<IDbConnectionFactory>();
using (var db = dbFactory.Open())
{
var user = db.LoadSelect<User>(x => x.Email.ToLower() == session.UserAuthName.ToLower()).FirstOrDefault();
@jjwilliams42
jjwilliams42 / CustomAuthRepository.cs
Last active October 9, 2019 11:22
CustomAuthRepository
public class CustomAuthRepository : OrmLiteAuthRepository<AspNetUser, UserAuthDetails>
{
public CustomAuthRepository(IDbConnectionFactory dbFactory, string namedConnnection = null) : base(dbFactory, namedConnnection)
{
}
public override void AssignRoles(string userAuthId, ICollection<string> roles = null, ICollection<string> permissions = null)
{
var userAuth = GetUserAuth(userAuthId) as User;
@jjwilliams42
jjwilliams42 / S0002-AuthUserUpdates
Last active November 11, 2017 06:15
Migration from ASP.NET Identity 2 to Service Stack
ALTER TABLE AspNetUsers
ADD
[PrimaryEmail] nvarchar(max) NULL,
[DisplayName] nvarchar(max) NULL,
[Company] nvarchar(max) NULL,
[Birthdate] datetime NULL,
[BirthdateRaw] nvarchar(max) NULL,
[Address] nvarchar(max) NULL,
[Address2] nvarchar(max) NULL,
[City] nvarchar(max) NULL,
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Mvc.TagHelpers;
using Microsoft.AspNetCore.Mvc.ViewFeatures;