db

package
v0.0.0-...-e29cf6a Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2015 License: GPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinPasswordLength specifies the minimiun password length
	MinPasswordLength = 6
	// PasswordSaltLength specifies the length of salt used with hashing passwords
	PasswordSaltLength = 16
)

Variables

This section is empty.

Functions

func BackupForTesting

func BackupForTesting()

BackupForTesting creates backup of current database before running tests.

func RestoreFromTesting

func RestoreFromTesting()

RestoreFromTesting restores the database which was backedup before running tests.

func SetupDatabase

func SetupDatabase() gorm.DB

SetupDatabase is just for testing purposes

func TokenExists

func TokenExists(token string) bool

TokenExists returns boolean indicating if specified token exists.

Types

type GCMClient

type GCMClient struct {
	ID int64

	GCMId string `sql:"not null;unique" gorm:"column:gcm_id"`
	Token string `sql:"not null"`
}

GCMClient is object mapped in database. Holds data of GoogleCloudMessaging clients registered by user

func GetGCMClient

func GetGCMClient(id string) (*GCMClient, error)

GetGCMClient returns GCMClient object if found with specified identifier.

func RegisterGCMClient

func RegisterGCMClient(gcmID, token string) (*GCMClient, error)

RegisterGCMClient registers new GoogleCloudMessaging client associating with user through specfied token.

func (*GCMClient) Delete

func (g *GCMClient) Delete()

Delete is shortcut to delete object from database

func (*GCMClient) Save

func (g *GCMClient) Save()

Save is shortcut to save object to database

func (GCMClient) TableName

func (g GCMClient) TableName() string

TableName is function used with gorm library

type PushData

type PushData struct {
	// ID is the primary key used in databse
	ID int64 `json:"-"`
	// CreatedAt is the date when this user was created in database level
	CreatedAt time.Time `json:"-"`
	// DeletedAt is the date when user was /soft/ deleted in database level
	DeletedAt time.Time `json:"-"`

	// Accessed indicates if this data has already pooled by client (the one user design flaw lies in here)
	Accessed bool `json:"-"`

	// UinxTimeStamp is the timestamp which client can specify when sending data
	// Timestamp defaults to 0 if invalid
	UnixTimeStamp int64
	Title         string `sql:"not null"`
	Body          string
	Token         string `sql:"not null" json:"-"`
	// URL to open on client side
	//
	// URL is not validated
	URL string
	// Priority defines whether we send the data to all clients, do we make seound etc.
	//
	// Possible values:
	// 1*: Send to all clients
	// 2: Don't make sound on GCM clients if TCP client is listening
	// 3: Don't send to TCP client
	// * = default
	//
	// Invalid value defaults to 1
	Priority int64 `json:"-"`
	Sound    bool
}

PushData is the object mapped on database. This is the object containing the data user may push through to other devices using this service.

func GetAllPushDatas

func GetAllPushDatas() []PushData

GetAllPushDatas returns /all/ PushData objects in database.

func GetPushesForToken

func GetPushesForToken(token string) []PushData

GetPushesForToken returns PushData objects linked to specified token.

func SavePushData

func SavePushData(title, body, token, strurl string, timestamp, priority int64) (p *PushData, err error)

SavePushData saves push data to the database

func (*PushData) Delete

func (p *PushData) Delete()

Delete is shortcut to delete data from database

func (*PushData) Save

func (p *PushData) Save()

Save is shortcut to save data to database

func (*PushData) SetAccessed

func (p *PushData) SetAccessed()

SetAccessed sets Accessed property to true and saves it to database

func (*PushData) ToJSON

func (p *PushData) ToJSON() ([]byte, error)

ToJSON returns this object as JSON string (byte array)

type User

type User struct {
	// ID is the primary key used in databse
	ID int64
	// CreatedAt is the date when this user was created in database level
	CreatedAt time.Time
	// ModifiedAt is the date when this user was last modified in database level
	ModifiedAt time.Time
	// DeletedAt is the date when user was /soft/ deleted in database level
	DeletedAt time.Time

	// Active is the flag indicating if the user is activated with email or not.
	// If user is not activated it cannot be used. Email activation can be skipped
	// within the server's configuration file
	Active bool
	// ActivateToken is used to securely activate the user with email. It is added
	// to the link sent in the activation email
	ActivateToken string

	// Email is the email user provoided when he/she registered to this service
	Email string `sql:"not null;unique"`
	// Password is the user's password
	Password string
	// Token is the token which is used to push/pool data
	Token string `sql:"unique"`
	// GCMClients are the clients registered with GoogleCloudMessaging service to this user
	GCMClients []GCMClient
}

User is the user object mapped in database. Contains all relevant information about user.

func GetUser

func GetUser(email string) (*User, error)

GetUser returns User object if found with specified email.

func GetUserByToken

func GetUserByToken(token string) (*User, error)

GetUserByToken returns User object if found with specified token.

func NewUser

func NewUser(email, password string) (*User, error)

NewUser creates new user and saves it to database

func (*User) Activate

func (u *User) Activate()

Activate activates the user (sets User.Active to true and saves it to database)

func (*User) AfterFind

func (u *User) AfterFind()

AfterFind is function rab by gorm library after database query is ran agains User table. In this case its used to load data to User object.

func (*User) BeforeCreate

func (u *User) BeforeCreate() error

BeforeCreate is function ran by gorm library before the user is created.

func (*User) Save

func (u *User) Save()

Save is shortcut to save object to database

func (*User) ValidatePassword

func (u *User) ValidatePassword(password string) bool

ValidatePassword checks if specified password is the correct password for the user

Jump to

Keyboard shortcuts

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