postgres

package
v0.0.0-...-ea8537e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2019 License: AGPL-3.0 Imports: 6 Imported by: 0

README

postgres/

An implementation of the services in models/ that uses postgres as its backing store.

Documentation

Overview

Package postgres provides a PostgreSQL specific implementation of the services we provide.

TODO If there's no rows altered does it return an err? TODO When using them right, transactions are usually a better way to deal with actions in the database. You get rollback and some other cool stuff. Something to consider if you're looking for something to do.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(n int) (string, error)

GenerateRandomString returns a securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func Open

func Open(connStr string) (*sql.DB, error)

Open starts the connection to the database.

Types

type ApplicationService

type ApplicationService struct {
	DB *sql.DB
}

UserService is a PostgreSQL implementation of models.UserService

func (*ApplicationService) CreateOrUpdate

func (s *ApplicationService) CreateOrUpdate(newApp *models.Application) (err error)

CreateOrUpdate tries to make a new Application, if one already exists then it updates the existing one.

func (*ApplicationService) GetByUserID

func (s *ApplicationService) GetByUserID(uid int) (*models.Application, error)

GetByUserID returns a single Application with the given user id.

type UserService

type UserService struct {
	DB *sql.DB
}

UserService is a PostgreSQL implementation of models.UserService

func (*UserService) GetByCode

func (s *UserService) GetByCode(code string) (u *models.User, err error)

GetByCode returns a single user with the given email confirmation code

func (*UserService) GetByEmail

func (s *UserService) GetByEmail(email string) (u *models.User, err error)

GetByEmail returns a single user with the given email.

func (*UserService) GetById

func (s *UserService) GetById(id int) (u *models.User, err error)

GetById returns a single user with the given id.

func (*UserService) GetPasswordReset

func (s *UserService) GetPasswordReset(email string) (string, error)

Creates the user's token for a password reset

func (*UserService) Login

func (s *UserService) Login(u *models.User) error

Login checks to see if a passed user's password matches the one recorded in the database. It expects to receive a user object with at least an email and a password. When Login fails it will return an error, otherwise it will return nil.

func (*UserService) ResetPassword

func (s *UserService) ResetPassword(token string, password string) error

ResetPassword resets the user's password

func (*UserService) Signup

func (s *UserService) Signup(u *models.User) (id int, code string, err error)

Signup inserts a new user into the database. TODO test cases: - Empty fields - Same email - nil user

func (*UserService) TokenChangePassword

func (s *UserService) TokenChangePassword(id int, uid int, password string) error

TokenChangePassword changes password then deletes the token used

func (*UserService) Update

func (s *UserService) Update(u *models.User) error

Update changes the values of a user in the database. It will update all fields in the user model given to it, including nil or zero fields. Don't give it a user with only the changes you want to make.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL