db

package
v0.0.0-...-ee9e9f6 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2016 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*sqlx.DB
}

func NewDB

func NewDB(db *sqlx.DB) *DB

Create a new DB used to amnage the data of the server

func (*DB) AuthMiddleware

func (db *DB) AuthMiddleware(response http.ResponseWriter, request *http.Request, next http.HandlerFunc)

func (*DB) ChangePassword

func (db *DB) ChangePassword(user *User, newPassword []byte) (bool, error)

func (*DB) CheckRequest

func (db *DB) CheckRequest(request *http.Request) (bool, int64)

func (*DB) CheckSession

func (db *DB) CheckSession(session *Session) bool

Check if the given session is valid or not

func (*DB) CreateSession

func (db *DB) CreateSession(newSession *Session) error

Create a new session for the user

func (*DB) CreateUser

func (db *DB) CreateUser(newUser *User) error

Create a new user. If a user with the same name already a new error is returned, otherwise is returned the id of the new user

func (*DB) ExistUser

func (db *DB) ExistUser(name string) bool

Check if a user with the given name already exists on the database

func (*DB) GetUser

func (db *DB) GetUser(name string) (*User, error)

Given a name, return all the informations about the user

func (*DB) GetUserById

func (db *DB) GetUserById(id int64) (*User, error)

func (*DB) GetUserSessions

func (db *DB) GetUserSessions(user *User) ([]Session, error)

func (*DB) HasStorage

func (db *DB) HasStorage(user *User) bool

func (*DB) InvalidateSession

func (db *DB) InvalidateSession(session *Session) error

Invalidate a user session,. deleting the data from the database

func (*DB) UpdateSessionCode

func (db *DB) UpdateSessionCode(session *Session, newCode []byte) error

Update a session

type Session

type Session struct {
	Id          int64  `db:"ID"`
	UserId      int64  `db:"user_ID" json:"userId"`
	UserAgent   string `db:"user_agent" json:"userAgent"`
	CodeHash    []byte `db:"code" json:"code"`
	SessionType string `db:"type" json:"sessionType"`
	LastUse     int64  `db:"last_use" json:"lastUse"`
}

Struct that contains the session informations

type User

type User struct {
	Id       int64  `db:"ID"`
	Password []byte `db:"password"`
	Email    string `db:"mail"`
	Name     string `db:"name"`
	Image    string `db:"image"`
}

Struct that holds the informations of the user

Jump to

Keyboard shortcuts

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