33using Microsoft . EntityFrameworkCore ;
44
55using Nullinside . Api . Common ;
6+ using Nullinside . Api . Common . Auth ;
67using Nullinside . Api . Model . Ddl ;
78
89namespace Nullinside . Api . Model . Shared ;
@@ -26,10 +27,9 @@ public static class UserHelpers {
2627 public static async Task < string ? > GetTokenAndSaveToDatabase ( INullinsideContext dbContext , string email ,
2728 CancellationToken token = new ( ) , string ? authToken = null , string ? refreshToken = null , DateTime ? expires = null ,
2829 string ? twitchUsername = null , string ? twitchId = null ) {
29- string bearerToken = GenerateBearerToken ( ) ;
30+ string bearerToken = AuthUtils . GenerateBearerToken ( ) ;
3031 try {
31- // We prevent banned users from logging into the site.
32- User ? existing = await dbContext . Users . FirstOrDefaultAsync ( u => u . Email == email && ! u . IsBanned , token ) ;
32+ User ? existing = await dbContext . Users . FirstOrDefaultAsync ( u => u . Email == email , token ) ;
3333 if ( null == existing ) {
3434 dbContext . Users . Add ( new User {
3535 Email = email ,
@@ -73,22 +73,4 @@ public static class UserHelpers {
7373 return null ;
7474 }
7575 }
76-
77- /// <summary>
78- /// Generates a new unique bearer token.
79- /// </summary>
80- /// <returns>A bearer token.</returns>
81- public static string GenerateBearerToken ( ) {
82- // This method is trash but it doesn't matter. We should be doing real OAuth tokens with expirations and
83- // renewals. Right now nothing that exists on the site requires this level of sophistication.
84- string allowed = "ABCDEFGHIJKLMONOPQRSTUVWXYZabcdefghijklmonopqrstuvwxyz0123456789" ;
85- int strlen = 255 ; // Or whatever
86- char [ ] randomChars = new char [ strlen ] ;
87-
88- for ( int i = 0 ; i < strlen ; i ++ ) {
89- randomChars [ i ] = allowed [ RandomNumberGenerator . GetInt32 ( 0 , allowed . Length ) ] ;
90- }
91-
92- return new string ( randomChars ) ;
93- }
9476}
0 commit comments