models

package
v0.0.0-...-83cc74b Latest Latest
Warning

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

Go to latest
Published: May 10, 2020 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPFPURL = "/static/png/default_pfp.png"

DefaultPFPURL is the PFP for the default user.

Functions

func LogoutUser

func LogoutUser(Token string)

LogoutUser is used to logout a user.

func RunDatabaseInitTasks

func RunDatabaseInitTasks()

RunDatabaseInitTasks is used to run all database initialisation tasks.

Types

type User

type User struct {
	ID               string  `json:"id" bson:"_id"`
	Email            string  `json:"email" bson:"email"`
	Verified         bool    `json:"verified" bson:"verified"`
	Admin            bool    `json:"admin" bson:"admin"`
	Banned           bool    `json:"banned" bson:"banned"`
	PasswordHashSalt string  `json:"passwordHashSalt" bson:"passwordHashSalt"`
	FirstName        *string `json:"firstName" bson:"firstName"`
	LastName         *string `json:"lastName" bson:"lastName"`
	PFPUrl           string  `json:"pfpUrl" bson:"pfpUrl"`
}

User is the model which is used to define a user.

func GetUserByEmail

func GetUserByEmail(Email string) *User

GetUserByEmail is used to check if a user exists with their e-mail address and return it if so.

func GetUserByID

func GetUserByID(ID string) *User

GetUserByID is used to get the user by their user ID.

func GetUserByToken

func GetUserByToken(Token string) *User

GetUserByToken is used to get the user by their token.

func LoginUser

func LoginUser(Email string, Password string) (*User, *string)

LoginUser is used to login a user. If the email/password is correct, a user pointer and a string pointer for a token will be returned. If it is not correct, these will be nil.

func NewUser

func NewUser(Email, Password string, Admin, Verified bool, FirstName, LastName *string) (*User, string)

NewUser is used to create a new user and new token with it.

func (*User) Ban

func (u *User) Ban()

Ban is used to drop the ban hammer.

func (*User) ChangeEmail

func (u *User) ChangeEmail(Email string)

ChangeEmail is used to change an email within the database.

func (*User) ChangePFPUrl

func (u *User) ChangePFPUrl(URL string)

ChangePFPUrl is used to change the PFP URL within the database.

func (*User) DemoteFromAdmin

func (u *User) DemoteFromAdmin()

DemoteFromAdmin is used to demote a user from admin.

func (*User) PromoteToAdmin

func (u *User) PromoteToAdmin()

PromoteToAdmin is used to promote a user to admin.

func (*User) SetFirstName

func (u *User) SetFirstName(FirstName string)

SetFirstName is used to set a first name in the database.

func (*User) SetLastName

func (u *User) SetLastName(LastName string)

SetLastName is used to set a last name in the database.

func (*User) SetPassword

func (u *User) SetPassword(Password string)

SetPassword is used to set a password in the database.

func (*User) Unban

func (u *User) Unban()

Unban is used to unban a user.

func (*User) Verify

func (u *User) Verify()

Verify is used to verify an e-mail address.

type VerificationCode

type VerificationCode struct {
	ID     string `json:"id" bson:"_id"`
	UserID string `json:"userId" bson:"userId"`
}

VerificationCode defines a verification code model.

func GetVerificationCode

func GetVerificationCode(ID string) *VerificationCode

GetVerificationCode is used to get a verification code if possible.

func NewVerificationCode

func NewVerificationCode(u *User) (*VerificationCode, error)

NewVerificationCode is used to create a verification code for a user.

func (*VerificationCode) Verify

func (v *VerificationCode) Verify()

Verify is used to verify the user and then delete the object from the DB.

Jump to

Keyboard shortcuts

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