force unique user name
This commit is contained in:
		
							parent
							
								
									a1d842c7a3
								
							
						
					
					
						commit
						8a462252af
					
				| @ -35,7 +35,7 @@ export function FundErrorModal () { | ||||
|       onHide={() => setError(false)} | ||||
|     > | ||||
|       <Modal.Body> | ||||
|         <p>you're out of sats!</p> | ||||
|         <p className='font-weight-bolder'>you are out of sats</p> | ||||
|         <div className='d-flex justify-content-end'> | ||||
|           <Link href='/wallet?type=fund'> | ||||
|             <Button variant='success' onClick={() => setError(false)}>fund</Button> | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| export function ensureProtocol (value) { | ||||
|   if (!/^[a-z0-9]+:(\/\/)?/.test(value)) { | ||||
|   if (!/^([a-z0-9]+:\/\/|mailto:)/.test(value)) { | ||||
|     value = 'http://' + value | ||||
|   } | ||||
|   return value | ||||
|  | ||||
| @ -9,15 +9,32 @@ const options = { | ||||
|   providers: [ | ||||
|     Providers.GitHub({ | ||||
|       clientId: process.env.GITHUB_ID, | ||||
|       clientSecret: process.env.GITHUB_SECRET | ||||
|       clientSecret: process.env.GITHUB_SECRET, | ||||
|       profile: profile => { | ||||
|         return { | ||||
|           ...profile, | ||||
|           name: profile.login | ||||
|         } | ||||
|       } | ||||
|     }), | ||||
|     Providers.Twitter({ | ||||
|       clientId: process.env.TWITTER_ID, | ||||
|       clientSecret: process.env.TWITTER_SECRET | ||||
|       clientSecret: process.env.TWITTER_SECRET, | ||||
|       profile: profile => { | ||||
|         console.log(profile) | ||||
|         return { | ||||
|           ...profile, | ||||
|           name: profile.screen_name | ||||
|         } | ||||
|       } | ||||
|     }), | ||||
|     Providers.Email({ | ||||
|       server: process.env.EMAIL_SERVER, | ||||
|       from: process.env.EMAIL_FROM | ||||
|       from: process.env.EMAIL_FROM, | ||||
|       profile: profile => { | ||||
|         console.log(profile) | ||||
|         return profile | ||||
|       } | ||||
|     }) | ||||
|   ], | ||||
|   adapter: Adapters.Prisma.Adapter({ prisma }), | ||||
|  | ||||
							
								
								
									
										24
									
								
								prisma/migrations/20210521192356_name_trigger/migration.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								prisma/migrations/20210521192356_name_trigger/migration.sql
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | ||||
| -- AlterEnum | ||||
| ALTER TYPE "WithdrawlStatus" ADD VALUE 'UNKNOWN_FAILURE'; | ||||
| 
 | ||||
| CREATE OR REPLACE FUNCTION assign_name() RETURNS TRIGGER AS $$ | ||||
|     DECLARE | ||||
|     BEGIN | ||||
|         -- if doesn't have a name, SPLIT email on @ and assign to name | ||||
|         IF NEW.name IS NULL THEN | ||||
|             NEW.name = SPLIT_PART(NEW.email, '@', 1); | ||||
|         END IF; | ||||
|         -- replace unsupported characters (non alphanum + _) in name with _ | ||||
|         NEW.name = REGEXP_REPLACE(NEW.name, '\W|_', '_', 'gi'); | ||||
|         -- while name exists append random number | ||||
|         WHILE EXISTS (SELECT 1 FROM users WHERE name = NEW.name) LOOP | ||||
|             NEW.name = NEW.name || floor(random() * 10 + 1)::int; | ||||
|         END LOOP; | ||||
| 
 | ||||
|         RETURN NEW; | ||||
|     END; | ||||
| $$ LANGUAGE plpgsql; | ||||
| 
 | ||||
| CREATE TRIGGER name_tgr | ||||
|     BEFORE INSERT ON "users" | ||||
|     FOR EACH ROW EXECUTE PROCEDURE assign_name(); | ||||
| @ -14,7 +14,7 @@ model User { | ||||
|   id            Int         @id @default(autoincrement()) | ||||
|   createdAt     DateTime    @default(now()) @map(name: "created_at") | ||||
|   updatedAt     DateTime    @updatedAt @map(name: "updated_at") | ||||
|   name          String?     @unique | ||||
|   name          String      @unique | ||||
|   email         String?     @unique | ||||
|   emailVerified DateTime?   @map(name: "email_verified") | ||||
|   image         String? | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user