user

package
v0.0.0-...-82ef3d0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithPayload

func ContextWithPayload(ctx context.Context, p *Payload) context.Context

ContextWithPayload adds a payload to a context.

func ResponseWithTokenCookie

func ResponseWithTokenCookie(w http.ResponseWriter, p *Payload) error

ResponseWithTokenCookie adds a cookie to a response with the provided payload's token.

Types

type InsertUser

type InsertUser struct {
	Name      string    `bson:"name"`
	Username  string    `bson:"username"`
	Email     string    `bson:"email"`
	Password  string    `bson:"password"`
	CreatedAt time.Time `bson:"createdAt"`
}

InsertUser is an user to be inserted in the database.

func (*InsertUser) HashPw

func (iU *InsertUser) HashPw() error

HashPw hashes the password.

type Payload

type Payload struct {
	ID       *primitive.ObjectID `json:"id"`
	Username string              `json:"username"`
}

Payload is the user data that can used in a token.

func PayloadFromContext

func PayloadFromContext(ctx context.Context) *Payload

PayloadFromContext gets a payload from a context.

func PayloadFromToken

func PayloadFromToken(t string) *Payload

PayloadFromToken gets a payload from a token. If the token is invalid, or any other error occurs, a nil pointer is returned.

func PayloadFromTokenCookie

func PayloadFromTokenCookie(r *http.Request) *Payload

PayloadFromTokenCookie gets a payload from a request's token cookie. If the cookie doesn't exist, or any other error occurs, a nil pointer is returned.

func PayloadFromUser

func PayloadFromUser(u *User) *Payload

PayloadFromUser gets a payload from an user.

func (*Payload) Token

func (p *Payload) Token() (string, error)

Token returns a token from a payload.

type User

type User struct {
	ID        *primitive.ObjectID `bson:"_id"`
	Name      string              `bson:"name"`
	Username  string              `bson:"username"`
	Email     string              `bson:"email"`
	Password  string              `bson:"password"`
	CreatedAt time.Time           `bson:"createdAt"`
}

User is an user in the database.

func (*User) ComparePw

func (u *User) ComparePw(plainTextPw string) bool

ComparePw compares a plain text password with a hashed one to check if there's a match.

Jump to

Keyboard shortcuts

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