models

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UserModel *mapi.Model

UserModel stores user model

Functions

func RegisterUserModel

func RegisterUserModel()

RegisterUserModel will allow the ability for a system to use the UserModel

Types

type AuthInfo

type AuthInfo struct {
	Token    string `json:"token,omitempty"`
	Fullname string `json:"fullname,omitempty"`
}

AuthInfo holds information about an authenticated user

func CreateUserWithNewOrg

func CreateUserWithNewOrg(orgName string, fullName string, email string, pwd string) (*AuthInfo, []mapi.APIError)

CreateUserWithNewOrg will create new user with new organization

func SignIn

func SignIn(email string, pwd string) (*AuthInfo, []mapi.APIError)

SignIn will create a JWT token

type Role

type Role string

Role is an enum that describes role in the system

const (
	// Admin is a role that describes users that have
	//		 full access to the entire system
	Admin Role = "ADMIN"
	// Tenant is a role that describes users that own
	//		  an organization
	Tenant Role = "TENANT"
	// User is a role that describes users that is a
	//		part of an organization
	User Role = "USER"
)

type RoleFields

type RoleFields struct {
	OrgName     string             `bson:"orgName,omitempty"`
	Role        Role               `bson:"role" validate:"required"`
	Description string             `bson:"description,omitempty"`
	TenantID    primitive.ObjectID `bson:"tenantId" validate:"required"`
}

RoleFields holds the role a user has to an organization

type UserFields

type UserFields struct {
	ID                primitive.ObjectID `bson:"_id" json:"_id"`
	FullName          string             `bson:"fullName" json:"fullName" validate:"required"`
	Email             string             `bson:"email" json:"email" validate:"required,email"`
	Password          string             `bson:"password" json:"password"`
	EmailConfirmed    bool               `bson:"emailConfirmed,omitempty" json:"emailConfirmed,omitempty"`
	ConfirmationToken string             `bson:"confirmationToken,omitempty" json:"confirmationToken,omitempty"`
	Roles             []RoleFields       `bson:"roles,omitempty" json:"roles,omitempty" validate:"required"`
}

UserFields hold information about a user

func GetUserByUserID added in v0.0.3

func GetUserByUserID(userID primitive.ObjectID) (*UserFields, *mapi.APIError)

GetUserByUserID gets a user from db

func NewUserWithID added in v0.0.3

func NewUserWithID(id primitive.ObjectID, fullName string, email string, plainPwd string, emailConfirmed bool, roles []RoleFields) (UserFields, error)

NewUserWithID creates a new user, encrypts password and depending on email setting

it will create an emailConfirmation token

Jump to

Keyboard shortcuts

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