LocalAuthentication
This commit is contained in:
@@ -47,24 +47,24 @@ func (psql PostgresqlStorage) GetAccount(id string) (*Account, error) {
|
||||
if isUUIDv4(id) {
|
||||
stmtAccounts, err := psql.DbConnection.Prepare("SELECT id, namespace, data, metadata FROM accounts WHERE id = $1")
|
||||
if err != nil {
|
||||
return account, fmt.Errorf("psql connection failed")
|
||||
return nil, fmt.Errorf("psql connection failed")
|
||||
}
|
||||
defer stmtAccounts.Close()
|
||||
err = stmtAccounts.QueryRow(id).Scan(&account.ID, &account.Namespace, &data, &metadata)
|
||||
if err != nil {
|
||||
return account, fmt.Errorf("psql select account query failed")
|
||||
return nil, fmt.Errorf("psql select account query failed")
|
||||
}
|
||||
err = json.Unmarshal(data, &account.Data)
|
||||
if err != nil {
|
||||
return account, err
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(metadata, &account.Metadata)
|
||||
if err != nil {
|
||||
return account, err
|
||||
return nil, err
|
||||
}
|
||||
stmtAccount_auth, err := psql.DbConnection.Prepare("SELECT username, password, email, email_validation, phone_number, phone_number_validation FROM account_auth WHERE account_id= $1")
|
||||
if err != nil {
|
||||
return account, fmt.Errorf("psql connection failed")
|
||||
return nil, fmt.Errorf("psql connection failed")
|
||||
}
|
||||
defer stmtAccount_auth.Close()
|
||||
err = stmtAccount_auth.QueryRow(id).Scan(&account.Authentication.Local.Username,
|
||||
@@ -74,22 +74,110 @@ func (psql PostgresqlStorage) GetAccount(id string) (*Account, error) {
|
||||
&account.Authentication.Local.PhoneNumber,
|
||||
&phoneValidation)
|
||||
if err != nil {
|
||||
return account, fmt.Errorf("psql select account auth query failed")
|
||||
return nil, fmt.Errorf("psql select account auth query failed")
|
||||
}
|
||||
err = json.Unmarshal(emailValidation, &account.Authentication.Local.EmailValidation)
|
||||
if err != nil {
|
||||
return account, err
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(phoneValidation, &account.Authentication.Local.PhoneNumberValidation)
|
||||
if err != nil {
|
||||
return account, err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func (PostgresqlStorage) LocalAuthentication(namespace string, username string, email string, phone_number string) (*Account, error) {
|
||||
return nil, fmt.Errorf("")
|
||||
func (psql PostgresqlStorage) LocalAuthentication(namespace string, username string, email string, phone_number string) (*Account, error) {
|
||||
account := &Account{}
|
||||
var (
|
||||
data, metadata, emailValidation, phoneValidation []byte
|
||||
)
|
||||
if username != "" {
|
||||
usernameStmt, err := psql.DbConnection.Prepare("SELECT id, namespace, data, metadata, username, password, email, email_validation, phone_number, phone_number_validation FROM accounts INNER JOIN account_auth ON accounts.id = account_auth.account_id WHERE namespace = $1 AND username = $2;")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = usernameStmt.QueryRow(namespace, username).Scan(&account.ID, &account.Namespace, &data, &metadata, &account.Authentication.Local.Username,
|
||||
&account.Authentication.Local.Password, &account.Authentication.Local.Email, &emailValidation, &account.Authentication.Local.PhoneNumber, &phoneValidation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(metadata, &account.Metadata)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(data, &account.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(emailValidation, &account.Authentication.Local.EmailValidation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(phoneValidation, &account.Authentication.Local.PhoneNumberValidation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return account, nil
|
||||
} else if email != "" {
|
||||
account.Authentication.Local.Email = email
|
||||
emailStmt, err := psql.DbConnection.Prepare("SELECT id, namespace, data, metadata, username, password, email_validation, phone_number, phone_number_validation FROM accounts INNER JOIN account_auth ON accounts.id = account_auth.account_id WHERE namespace = $1 AND email = $2;")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = emailStmt.QueryRow(namespace, email).Scan(&account.ID, &account.Namespace, &data, &metadata, &account.Authentication.Local.Username,
|
||||
&account.Authentication.Local.Password, &emailValidation, &account.Authentication.Local.PhoneNumber, &phoneValidation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(metadata, &account.Metadata)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(data, &account.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(emailValidation, &account.Authentication.Local.EmailValidation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(phoneValidation, &account.Authentication.Local.PhoneNumberValidation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return account, nil
|
||||
} else if phone_number != "" {
|
||||
account.Authentication.Local.PhoneNumber = phone_number
|
||||
phoneStmt, err := psql.DbConnection.Prepare("SELECT id, namespace, data, metadata, username, password, email, email_validation, phone_number_validation FROM accounts INNER JOIN account_auth ON accounts.id = account_auth.account_id WHERE namespace = $1 AND phone_number = $2;")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = phoneStmt.QueryRow(namespace, phone_number).Scan(&account.ID, &account.Namespace, &data, &metadata, &account.Authentication.Local.Username,
|
||||
&account.Authentication.Local.Password, &account.Authentication.Local.Email, &emailValidation, &phoneValidation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(metadata, &account.Metadata)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(data, &account.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(emailValidation, &account.Authentication.Local.EmailValidation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(phoneValidation, &account.Authentication.Local.PhoneNumberValidation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return account, nil
|
||||
}
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func (PostgresqlStorage) GetAccounts(namespaces []string) ([]Account, error) {
|
||||
|
||||
Reference in New Issue
Block a user