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 ¶
- func GenerateRandomBytes(n int) ([]byte, error)
- func GenerateRandomString(n int) (string, error)
- func Open(connStr string) (*sql.DB, error)
- type ApplicationService
- type UserService
- func (s *UserService) GetByCode(code string) (u *models.User, err error)
- func (s *UserService) GetByEmail(email string) (u *models.User, err error)
- func (s *UserService) GetById(id int) (u *models.User, err error)
- func (s *UserService) GetPasswordReset(email string) (string, error)
- func (s *UserService) Login(u *models.User) error
- func (s *UserService) ResetPassword(token string, password string) error
- func (s *UserService) Signup(u *models.User) (id int, code string, err error)
- func (s *UserService) TokenChangePassword(id int, uid int, password string) error
- func (s *UserService) Update(u *models.User) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateRandomBytes ¶
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 ¶
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.
Types ¶
type ApplicationService ¶
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 ¶
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 ¶
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