add working signup + login
This commit is contained in:
		
							parent
							
								
									bc85b7c340
								
							
						
					
					
						commit
						d8cb8c8fa8
					
				
					 27 changed files with 600 additions and 39 deletions
				
			
		| 
						 | 
				
			
			@ -37,8 +37,13 @@ func (s *AccountStore) ByID(ctx context.Context, id ulid.ULID) (a database.Accou
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// ByUsername gets an account by its username.
 | 
			
		||||
func (s *AccountStore) ByUsername(ctx context.Context, username string, host *string) (a database.Account, err error) {
 | 
			
		||||
	q := sqlf.Sprintf("SELECT * FROM accounts WHERE username = %s AND host = %v", username, host)
 | 
			
		||||
func (s *AccountStore) ByUsername(ctx context.Context, username, domain string) (a database.Account, err error) {
 | 
			
		||||
	q := sqlf.Sprintf("SELECT * FROM accounts WHERE username = %s", username)
 | 
			
		||||
	if domain == "" {
 | 
			
		||||
		q = sqlf.Sprintf("%v AND domain IS NULL", q)
 | 
			
		||||
	} else {
 | 
			
		||||
		q = sqlf.Sprintf("%v AND domain = %s", q, domain)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	a, err = Get[database.Account](ctx, s.q, q)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
| 
						 | 
				
			
			@ -64,7 +69,7 @@ func (s *AccountStore) CreateLocal(
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	q := sqlf.Sprintf(
 | 
			
		||||
		"INSERT INTO accounts (id, username, host, email, password) VALUES (%s, %v, NULL, %v, %v) RETURNING *",
 | 
			
		||||
		"INSERT INTO accounts (id, username, domain, email, password) VALUES (%s, %v, NULL, %v, %v) RETURNING *",
 | 
			
		||||
		makeULID(), username, email, hash)
 | 
			
		||||
 | 
			
		||||
	a, err = Get[database.Account](ctx, s.q, q)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue