Beispiel #1
0
func (u *Account) PreInsert(s gorp.SqlExecutor) error {
	//u.Account_id = CreateGUID()
	//u.Version = time.Now()

	var val int
	if err := s.SelectOne(&val, "select max(sort) from jzb_accounts"); err == nil {
		u.Sort = val + 1
	}
	fmt.Println(u)
	return nil
}
Beispiel #2
0
func (b *AccountManagerBinding) get(
	db gorp.SqlExecutor, id snowflake.Snowflake) (*AccountBinding, error) {

	var row AccountWithStaffCapability
	err := db.SelectOne(
		&row,
		"SELECT a.id, a.nonce, a.mac, a.encrypted_system_key, a.encrypted_user_key,"+
			" a.encrypted_private_key, a.public_key,"+
			" c.id AS staff_capability_id, c.nonce AS staff_capability_nonce,"+
			" c.encrypted_private_data, c.public_data"+
			" FROM account a LEFT OUTER JOIN capability c ON a.staff_capability_id = c.id"+
			" WHERE a.id = $1",
		id.String())
	if err != nil {
		if err == sql.ErrNoRows {
			return nil, proto.ErrAccountNotFound
		}
		return nil, err
	}

	ab := row.Bind(b.Backend)

	rows, err := db.Select(
		PersonalIdentity{},
		"SELECT namespace, id, account_id, verified FROM personal_identity WHERE account_id = $1",
		id.String())
	switch err {
	case sql.ErrNoRows:
	case nil:
		ab.identities = make([]proto.PersonalIdentity, len(rows))
		for i, row := range rows {
			ab.identities[i] = &PersonalIdentityBinding{row.(*PersonalIdentity)}
		}
	default:
		return nil, err
	}

	return ab, nil
}
Beispiel #3
0
func (b *AccountManagerBinding) resolve(
	db gorp.SqlExecutor, namespace, id string) (*AccountBinding, error) {

	var pid PersonalIdentity
	err := db.SelectOne(
		&pid,
		"SELECT account_id FROM personal_identity WHERE namespace = $1 AND id = $2",
		namespace, id)
	if err != nil {
		if err == sql.ErrNoRows {
			return nil, proto.ErrAccountNotFound
		}
		return nil, err
	}

	var accountID snowflake.Snowflake
	if err := accountID.FromString(pid.AccountID); err != nil {
		return nil, err
	}

	return b.get(db, accountID)
}