github.com/code-to-go/safepool.lib@v0.0.0-20221205180519-ee25e63c226e/sql/user.go_ (about)

     1  package sql
     2  
     3  import (
     4  	"github.com/code-to-go/safepool.lib/model"
     5  )
     6  
     7  type Identity []byte
     8  
     9  // GetUsersIdentities returns the id (i.e. the public key) of users for a domain
    10  func GetUsersIdentities(domain string, active bool) ([]Identity, error) {
    11  	// rows, err := Query("GET_USERS_ID_BY_DOMAIN", Args{"domain": domain, "active": active})
    12  	// if core.IsErr(err, "cannot get users ids from db for domain '%s': %v", domain) {
    13  	// 	return nil, err
    14  	// }
    15  
    16  	// var res []security.Identity
    17  	// for rows.Next() {
    18  	// 	var publicKey string
    19  	// 	var identity security.Identity
    20  	// 	err = rows.Scan(&publicKey)
    21  	// 	if !core.IsErr(err, "cannot read user's public key from db: %v") {
    22  	// 		data := DecodeBase64(publicKey)
    23  	// 		err := json.Unmarshal(data, &identity)
    24  	// 		if !core.IsErr(err, "cannot unmarshal identity from db: %v") {
    25  	// 			res = append(res, identity)
    26  	// 		}
    27  	// 	}
    28  	// }
    29  	// return res, nil
    30  	return nil, nil
    31  }
    32  
    33  func GetUsers(domain string) ([]model.User, error) {
    34  	// rows, err := Query("GET_USERS_BY_DOMAIN", Args{"domain": domain})
    35  	// if core.IsErr(err, "cannot get users ids from db for domain '%s': %v", domain) {
    36  	// 	return nil, err
    37  	// }
    38  
    39  	// var res []model.User
    40  	// for rows.Next() {
    41  	// 	var publicKey string
    42  	// 	var active bool
    43  	// 	err = rows.Scan(&publicKey, &active)
    44  	// 	if core.IsErr(err, "cannot read user's public key from db: %v") {
    45  	// 		continue
    46  	// 	}
    47  
    48  	// 	var identity security.Identity
    49  	// 	err := json.Unmarshal(DecodeBase64(publicKey), &identity)
    50  	// 	if core.IsErr(err, "cannot unmarshall identity from db: %v") {
    51  	// 		continue
    52  	// 	}
    53  
    54  	// 	res = append(res, model.User{
    55  	// 		Identity: identity,
    56  	// 		Active:   active,
    57  	// 	})
    58  	// }
    59  	// return res, nil
    60  	return nil, nil
    61  }
    62  
    63  func GetUsersByNick(domain string, nick string, active bool) ([]model.User, error) {
    64  	// rows, err := Query("GET_USERS_BY_NICK", Args{"domain": domain, "nick": nick, "active": active})
    65  	// if core.IsErr(err, "cannot get users by nick from db for domain '%s': %v", domain) {
    66  	// 	return nil, err
    67  	// }
    68  
    69  	// var res []model.User
    70  	// for rows.Next() {
    71  	// 	var data string
    72  	// 	var active bool
    73  	// 	err = rows.Scan(&data, &active)
    74  	// 	if core.IsErr(err, "cannot read user's public key from db: %v") {
    75  	// 		continue
    76  	// 	}
    77  
    78  	// 	identity, err := security.IdentityFromBase64(data)
    79  	// 	if core.IsErr(err, "cannot unmarshall identity from db: %v") {
    80  	// 		continue
    81  	// 	}
    82  
    83  	// 	res = append(res, model.User{
    84  	// 		Identity: identity,
    85  	// 		Active:   active,
    86  	// 	})
    87  	// }
    88  	// return res, nil
    89  	return nil, nil
    90  }
    91  
    92  func SetUser(domain string, user model.User) error {
    93  	// data, err := user.Identity.Base64()
    94  	// if core.IsErr(err, "cannot unmarshall identity of user %s: %v", user.Identity.Nick) {
    95  	// 	return err
    96  	// }
    97  
    98  	// _, err = Exec("SET_USER", Args{"domain": domain, "identity": data, "nick": user.Identity.Nick, "active": user.Active})
    99  	// if core.IsErr(err, "cannot set user %s to db: %v", user.Identity.Nick) {
   100  	// 	return err
   101  	// }
   102  	return nil
   103  }
   104  
   105  func GetAllTrusted(domain string) ([]model.User, error) {
   106  	// rows, err := Query("GET_ALL_TRUSTED", Args{"domain": domain})
   107  	// if core.IsErr(err, "cannot get users by nick from db for domain '%s': %v", domain) {
   108  	// 	return nil, err
   109  	// }
   110  	// var res []model.User
   111  	// for rows.Next() {
   112  	// 	var data string
   113  	// 	err = rows.Scan(&data)
   114  	// 	if core.IsErr(err, "cannot read user's public key from db: %v") {
   115  	// 		continue
   116  	// 	}
   117  
   118  	// 	identity, err := security.IdentityFromBase64(data)
   119  	// 	if core.IsErr(err, "cannot unmarshall identity from db: %v") {
   120  	// 		continue
   121  	// 	}
   122  
   123  	// 	res = append(res, model.User{
   124  	// 		Identity: identity,
   125  	// 		Active:   true,
   126  	// 	})
   127  	// }
   128  	return nil, nil
   129  }
   130  
   131  func SetTrusted(domain string, identity Identity, trusted bool) error {
   132  	// data, err := identity.Base64()
   133  	// if core.IsErr(err, "cannot unmarshall identity of user %s: %v", identity.Nick) {
   134  	// 	return err
   135  	// }
   136  
   137  	// _, err = Exec("SET_TRUSTED", Args{"domain": domain, "identity": data, "trusted": trusted})
   138  	// if core.IsErr(err, "cannot set trusted for user %s to db: %v", identity.Nick) {
   139  	// 	return err
   140  	// }
   141  	return nil
   142  }