Exemplo n.º 1
0
// DeleteByEmail deletes the admin which has the given email.
func DeleteByEmail(d db.DB, email string) error {
	adm, err := GetByEmail(d, email)
	if err != nil {
		return err
	}

	if err := db.DeleteByKey(d, admins, []byte(adm.Key)); err != nil {
		return err
	}

	return db.DeleteByKey(d, emails, []byte(email))
}
Exemplo n.º 2
0
// Delete deletes the admin which has the given key.
func Delete(d db.DB, key util.Key) error {
	adminJSON, err := db.GetByKey(d, admins, []byte(key))

	switch {
	case err != nil:
		return err
	case len(adminJSON) == 0:
		return errors.UserNotFoundf("admin for key %s:", key)
	}

	adm := new(Admin)
	if err := json.Unmarshal(adminJSON, adm); err != nil {
		return err
	}

	if err := db.DeleteByKey(d, admins, []byte(key)); err != nil {
		return err
	}

	return db.DeleteByKey(d, emails, []byte(adm.Email))
}
Exemplo n.º 3
0
func DeleteUser(d db.DB, email string) error {
	userBytes, err := db.GetByKey(d, Users, []byte(email))
	if err != nil {
		return err
	}

	if len(userBytes) == 0 {
		return errors.Errorf("user for email %q not found", email)
	}

	err = db.DeleteByKey(d, Users, b(email))
	if err != nil {
		return errors.Annotatef(err, "failed to delete user %q", email)
	}

	err = db.DeleteByKey(d, SessionKeys, b(email))
	if err != nil {
		return errors.Annotatef(err, "failed to log out deleted user %q", email)
	}
	return nil
}
Exemplo n.º 4
0
func LogoutUser(d db.DB, email string, key util.Key) error {
	err := Valid(d, email, key)
	if err != nil {
		return err
	}

	err = db.DeleteByKey(d, SessionKeys, b(email))
	if err != nil {
		return err
	}

	return nil
}
Exemplo n.º 5
0
func ClearLogin(d db.DB, email string) error {
	loginBytes, err := db.GetByKey(d, LoginKeys, []byte(email))
	if err != nil {
		return err
	}

	if len(loginBytes) == 0 {
		return errors.UserNotFoundf("user %q not logged in: ", email)
	}

	login := &Login{}
	if err = json.Unmarshal(loginBytes, &login); err != nil {
		return err
	}

	return db.DeleteByKey(d, LoginKeys, []byte(email))
}
Exemplo n.º 6
0
func Delete(d db.DB, email string) error {
	userBytes, err := db.GetByKey(d, Users, []byte(email))
	if err != nil {
		return err
	}

	if len(userBytes) == 0 {
		return errors.Errorf("user for email %q not found", email)
	}

	err = db.DeleteByKey(d, Users, []byte(email))
	if err != nil {
		return errors.Annotatef(err, "failed to delete user %q", email)
	}

	if _, err := GetLogin(d, email); err == nil {
		return ClearLogin(d, email)
	}
	return nil
}