user

package
v0.0.0-...-fbf9a92 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound abstracts the  not found error.
	ErrNotFound = errors.New("Entity not found")

	// ErrInvalidID occurs when an ID is not in a valid form.
	ErrInvalidID = errors.New("ID is not in its proper form")

	// ErrAuthenticationFailure occurs when a user attempts to authenticate but
	// anything goes wrong.
	ErrAuthenticationFailure = errors.New("Authentication failed")

	// ErrForbidden occurs when a user tries to do something that is forbidden to them according to our access control policies.
	ErrForbidden = errors.New("Attempted action is not allowed")
)

Functions

func EnsureIndex

func EnsureIndex(ctx context.Context, dbConn *db.DB) error

EnsureIndex fix the indexes in the account collections

func RandStringBytes

func RandStringBytes(n int) string

RandStringBytes Generates Random String by length

func SendOTP

func SendOTP(accountSid string, authToken string, mobile string, pin string)

SendOTP to User with Twilio

Types

type Token

type Token struct {
	Token string `json:"token"`
}

Token is the payload we deliver to users when they authenticate.

func Authenticate

func Authenticate(tknGen TokenGenerator, now time.Time, u *User) (Token, error)

Authenticate finds a user by their email and verifies their password. On success it returns a Token that can be used to authenticate in the future.

The key, keyID, and alg are required for generating the token.

type TokenGenerator

type TokenGenerator interface {
	GenerateToken(auth.Claims) (string, error)
}

TokenGenerator is the behavior we need in our Authenticate to generate tokens for authenticated users.

type User

type User struct {
	ID                       primitive.ObjectID `bson:"_id" json:"id"`
	IDStr                    string             `bson:"idStr" json:"idStr"`
	UserID                   string             `bson:"userId" json:"userId"`
	CreatedAt                time.Time          `json:"createdAt" bson:"createdAt"`
	UpdatedAt                time.Time          `json:"updatedAt" bson:"updatedAt"`
	Deleted                  bool               `json:"-" bson:"deleted"`
	Roles                    []string           `bson:"roles" json:"-"`
	Status                   string             `json:"status" bson:"status"`
	ScreenName               string             `bson:"screenName" json:"screenName"`
	FirstName                string             `bson:"firstName" json:"firstName"`
	LastName                 string             `bson:"lastName" json:"lastName"`
	Email                    string             `bson:"email" json:"email"`
	Mobile                   string             `bson:"mobile" json:"mobile"`
	Profession               string             `bson:"profession" json:"profession"`
	Pin                      string             `bson:"pin" json:"-"`
	ProfileImageURL          *string            `bson:"profileImageURL" json:"profileImageURL"`
	TwitterAccessToken       *string            `bson:"twitterAccessToken" json:"twitterAccessToken"`
	TwitterAccessTokenSecret *string            `bson:"twitterAccessTokenSecret" json:"-"`

	OrgName      string `bson:"orgname" json:"orgname"`
	OrgURL       string `bson:"orgurl" json:"orgurl"`
	OrgFirstName string `bson:"orgfirstName" json:"orgfirstName"`
	OrgLastName  string `bson:"orglastName" json:"orglastName"`
	OrgEmail     string `bson:"orgemail" json:"orgemail"`
	OrgMobile    string `bson:"orgmobile" json:"orgmobile"`
}

User : User Schema model

func ByScreenNanme

func ByScreenNanme(dbConn *db.DB, screenName string) (*User, error)

ByScreenNanme : Returns User by Twitter Screen Name

func Create

func Create(dbConn *db.DB, nu *User) (*User, error)

Create inserts a new user into the database.

func Get

func Get(dbConn *db.DB, id string) (*User, error)

Get gets the specified user from the database.

func Update

func Update(dbConn *db.DB, id string, upd *User) (*User, error)

Update replaces a user document in the database.

Jump to

Keyboard shortcuts

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