feat(frontend): discord registration/login/linking
also moves the registration form found on the mastodon callback page into a component so we're not repeating the same code for every auth method
This commit is contained in:
		
							parent
							
								
									4780be3019
								
							
						
					
					
						commit
						de733a0682
					
				
					 19 changed files with 545 additions and 212 deletions
				
			
		|  | @ -5,6 +5,7 @@ using Foxnouns.Backend.Database.Models; | |||
| using Foxnouns.Backend.Extensions; | ||||
| using Foxnouns.Backend.Middleware; | ||||
| using Foxnouns.Backend.Services; | ||||
| using Foxnouns.Backend.Utils; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Newtonsoft.Json; | ||||
|  | @ -56,9 +57,10 @@ public class AuthController( | |||
| 
 | ||||
|     public record AddOauthAccountResponse( | ||||
|         Snowflake Id, | ||||
|         AuthType Type, | ||||
|         [property: JsonConverter(typeof(ScreamingSnakeCaseEnumConverter))] AuthType Type, | ||||
|         string RemoteId, | ||||
|         string? RemoteUsername | ||||
|         [property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] | ||||
|             string? RemoteUsername | ||||
|     ); | ||||
| 
 | ||||
|     public record OauthRegisterRequest(string Ticket, string Username); | ||||
|  |  | |||
|  | @ -27,7 +27,8 @@ public class MetaController : ApiControllerBase | |||
|                 new Limits( | ||||
|                     MemberCount: MembersController.MaxMemberCount, | ||||
|                     BioLength: ValidationUtils.MaxBioLength, | ||||
|                     CustomPreferences: ValidationUtils.MaxCustomPreferences | ||||
|                     CustomPreferences: ValidationUtils.MaxCustomPreferences, | ||||
|                     MaxAuthMethods: AuthUtils.MaxAuthMethodsPerType | ||||
|                 ) | ||||
|             ) | ||||
|         ); | ||||
|  | @ -49,5 +50,10 @@ public class MetaController : ApiControllerBase | |||
|     private record UserInfo(int Total, int ActiveMonth, int ActiveWeek, int ActiveDay); | ||||
| 
 | ||||
|     // All limits that the frontend should know about (for UI purposes) | ||||
|     private record Limits(int MemberCount, int BioLength, int CustomPreferences); | ||||
|     private record Limits( | ||||
|         int MemberCount, | ||||
|         int BioLength, | ||||
|         int CustomPreferences, | ||||
|         int MaxAuthMethods | ||||
|     ); | ||||
| } | ||||
|  |  | |||
|  | @ -223,6 +223,15 @@ public class AuthService( | |||
|     { | ||||
|         AssertValidAuthType(authType, null); | ||||
| 
 | ||||
|         // This is already checked when | ||||
|         var currentCount = await db | ||||
|             .AuthMethods.Where(m => m.UserId == userId && m.AuthType == authType) | ||||
|             .CountAsync(ct); | ||||
|         if (currentCount >= AuthUtils.MaxAuthMethodsPerType) | ||||
|             throw new ApiError.BadRequest( | ||||
|                 "Too many linked accounts of this type, maximum of 3 per account." | ||||
|             ); | ||||
| 
 | ||||
|         var authMethod = new AuthMethod | ||||
|         { | ||||
|             Id = snowflakeGenerator.GenerateSnowflake(), | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue