3
3
using Microsoft . EntityFrameworkCore ;
4
4
5
5
using Nullinside . Api . Common ;
6
+ using Nullinside . Api . Common . Auth ;
6
7
using Nullinside . Api . Model . Ddl ;
7
8
8
9
namespace Nullinside . Api . Model . Shared ;
@@ -26,10 +27,9 @@ public static class UserHelpers {
26
27
public static async Task < string ? > GetTokenAndSaveToDatabase ( INullinsideContext dbContext , string email ,
27
28
CancellationToken token = new ( ) , string ? authToken = null , string ? refreshToken = null , DateTime ? expires = null ,
28
29
string ? twitchUsername = null , string ? twitchId = null ) {
29
- string bearerToken = GenerateBearerToken ( ) ;
30
+ string bearerToken = AuthUtils . GenerateBearerToken ( ) ;
30
31
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 ) ;
33
33
if ( null == existing ) {
34
34
dbContext . Users . Add ( new User {
35
35
Email = email ,
@@ -73,22 +73,4 @@ public static class UserHelpers {
73
73
return null ;
74
74
}
75
75
}
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
- }
94
76
}
0 commit comments