Documentation
¶
Overview ¶
Package user handles the user management
Scope includes:
- User creation and edition
- Authentication
Index ¶
Constants ¶
This section is empty.
Variables ¶
var UserAPI *core.API
UserAPI exposes User endpoints
Functions ¶
func TearDownUsers ¶
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"}'