user

package
v0.0.0-...-b1b50a1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package user handles the user management

Scope includes:

  • User creation and edition
  • Authentication

Index

Constants

This section is empty.

Variables

View Source
var UserAPI *core.API

UserAPI exposes User endpoints

Functions

func TearDownUsers

func TearDownUsers(users []User, emailPrefix string) (int64, error)

TearDownUsers deletes one or multiple users from the DB after a test suite. DO NOT USE IN PRODUCTION

Mongo Shell version: db.al_users.deleteMany({ email: {"$in": ["alun.sng+1@gmail.com", "alun.sng+2@gmail.com"]} }) >> { "acknowledged" : true, "deletedCount" : 2 }

Types

type BaseUser

type BaseUser struct {
	Email string `json:"email" bson:"email"`
}

BaseUser has the single Email field to strip out any other field sent during a user registration request or password reset request

An BaseUser does not need an ID as it must be transform into an User for being created in the database

BaseUser must be an exportable struct so that `bson` tag works

type Login

type Login struct {
	ID        primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"` // Uniquely identify to invalidate it
	Timestamp time.Time          `json:"timestamp" bson:"timestamp"`        // Login timestamp
	UserID    primitive.ObjectID `json:"userId" bson:"userId"`              // Logged-in user, should match the token of the token :)
	Token     authToken          `json:"token" bson:"token"`                // Token generated during login
}

Login tracks user login and associated generated token.

If a token was re-generated, it should create another Login as there is no automatic regeneration upon token expiration. UserID field is required to avoid decoding the JWT from `Token`

type PasswordRequest

type PasswordRequest struct {
	RedirectURL string `json:"redirectUrl"`
	// see
	//	userPwdRequestPwdReset => default value: "0"
	//	userPwdRequestNewUser
	RequestType int8 `json:"requestType"`
	BaseUser
}

PasswordRequest involves an email and a request:

  • new user creation
  • password reset request

The redirectURL will tell the server which link has to be added in the email

type User

type User struct {
	ID            primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	BaseUser      `bson:",inline"`
	Username      string        `json:"username,omitempty" bson:"username,omitempty"`
	IsAdmin       bool          `json:"isAdmin" bson:"isAdmin"`
	PwdResetToken pwdResetToken `json:"-" bson:"pwdResetToken,omitempty"` // not present in JSON: https://golang.org/pkg/encoding/json/
}

User represents an entity which can login

db.al_users.insertOne({username:"pouet", password:"plop"}) curl http://localhost:8000/users/register --data '{"username": "plop", "password": "plop"}'

func SetupUser

func SetupUser(user User, emailPrefix string, password string) (User, string, *core.ServiceMessage)

SetupUser should only be used in testing files as it creates an user in the database with a specific emailPrefix and a known password

Jump to

Keyboard shortcuts

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