database

package
v0.0.0-...-9fb3cb1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2015 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBUser    = "postgres"
	DBPasword = "password"
	DBName    = "pnw_conf"
)

Variables

View Source
var (
	// ErrInternalServerError is for occasions when we goof something up
	// but need a pretty error to return to the user. For example,
	// there's a function where we return an error to the user. However,
	// that error could be the result of a bad SQL statement, and
	// the user doesn't need to know how much we suck at SQL. So, instead,
	// we just show this.
	ErrInternalServerError = errors.New("Internal server error.")

	ErrNoUser = errors.New("No users.")

	ErrNoUsernameInCookie = errors.New("No user identifier inside of cookie.")
)
View Source
var (
	DB *sql.DB

	Pool = &redis.Pool{
		MaxIdle:     3,
		IdleTimeout: 240 * time.Second,
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial("unix", redisSocket)
			if err != nil {
				return nil, err
			}
			return c, err
		},
		TestOnBorrow: func(c redis.Conn, t time.Time) error {
			_, err := c.Do("PING")
			return err
		},
	}
)

Functions

func GetAllUsernames

func GetAllUsernames() ([]string, error)

GetAllUsernames returns a slice of all the usernames in the database.

func GetUserData

func GetUserData(session *sessions.Session) (string, error)

GetUserData simply returns a user's custom data, as well as any database errors that occurred.

func GetUserEmail

func GetUserEmail(session *sessions.Session) (string, error)

GetUserEmail is a more lightweight way to get a user's email that should usually skip a database call. It relies on having the user's email inside the session, so make sure to validate the session beforehand!

Types

type FailedAttempt

type FailedAttempt struct {
	IP       string    // Address where attempt originated
	User     string    // Account of attempt
	Attempts int       // Number of attempts
	Last     time.Time // Time of last attempt
}

type User

type User struct {
	Email           string    // User email address
	Name            string    // Username
	School          string    // Organization
	Password        []byte    // Bcrypt hashed pasword
	PasswordChanged time.Time // Last time password was changed

	// User's misc. data stored as XML. []byte instead of string because of
	// this issue:
	// https://github.com/go-sql-driver/mysql/wiki/Examples#ignoring-null-values
	Data []byte
}

func CheckUser

func CheckUser(id string) (*User, bool, error)

CheckUser returns a user's basic information, a bool indicating whether the user exists, and an error if one occurred.

func GetUser

func GetUser(session *sessions.Session) (*User, error)

GetUser returns a user's basic information, sans custom user data. The err will describe any database issues.

func GetUserAndData

func GetUserAndData(session *sessions.Session) (*User, error)

GetUserAndData returns the entire row of data for a user. It's similar to calling GetUser and GetUserData, but more efficient.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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