user

package
v0.0.0-...-823892c Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitTokenExpiryIndex

func InitTokenExpiryIndex(collection *mongo.Collection) error

func ValidateToken

func ValidateToken(token string, secret string) (*jwt.Token, error)

Types

type AboutMe

type AboutMe struct {
	Id             string `json:"id" bson:"_id"`
	AboutMe        string `json:"about_me" bson:"about_me"`
	ProfilePicture string `json:"profile_picture" bson:"profile_picture"`
}

type AccessDetails

type AccessDetails struct {
	ID         primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	AccessUuid string             `json:"access_uuid" bson:"access_uuid"`
	UserId     string             `json:"user_id" bson:"user_id"`
	ExpiresAt  time.Time          `json:"expires_at" bson:"expires_at"`
}

type GoogleLoginResponse

type GoogleLoginResponse struct {
	ID            string `json:"id"`
	Email         string `json:"email"`
	VerifiedEmail bool   `json:"verified_email"`
	Name          string `json:"name"`
	GivenName     string `json:"given_name"`
	FamilyName    string `json:"family_name"`
	Picture       string `json:"picture"`
	Locale        string `json:"locale"`
}

type LoginResponse

type LoginResponse struct {
	AccessToken string `json:"access_token"`
	AtExpires   int64  `json:"at_expires"`
	GoogleLoginResponse
}

type MailingList

type MailingList struct {
	Name        string       `json:"name" bson:"name"`
	Subscribers []Subscriber `json:"subscribers" bson:"subscribers"`
}

type MediaCloudManager

type MediaCloudManager struct {
	// contains filtered or unexported fields
}

func NewMediaCloudManager

func NewMediaCloudManager(api_uri, folder string) (*MediaCloudManager, error)

func (*MediaCloudManager) UploadImage

func (mcm *MediaCloudManager) UploadImage(ctx context.Context, file *multipart.FileHeader, collection string) (string, error)

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

func NewMiddleware

func NewMiddleware(accessTokenSecret string, userRepo MiddlewareUserRepo, tokenManager MiddlewareTokenManager) *Middleware

func (*Middleware) Authentication

func (m *Middleware) Authentication() gin.HandlerFunc

func (*Middleware) Authorization

func (m *Middleware) Authorization(roles []Role) gin.HandlerFunc

func (*Middleware) JsonMiddleware

func (m *Middleware) JsonMiddleware() gin.HandlerFunc

type MiddlewareTokenManager

type MiddlewareTokenManager interface {
	FindToken(filter interface{}, opts ...*options.FindOneOptions) (*AccessDetails, error)
	ExtractTokenMetadata(token *jwt.Token) (*AccessDetails, error)
}

type MiddlewareUserRepo

type MiddlewareUserRepo interface {
	GetUser(filter interface{}, opts ...*options.FindOneOptions) (*User, error)
}

type Role

type Role string
const (
	Admin  Role = "admin"
	Reader Role = "user"
)

type Subscriber

type Subscriber struct {
	Email     string    `json:"email" bson:"email"`
	Name      string    `json:"name" bson:"name"`
	CreatedAt time.Time `json:"created_at" bson:"created_at"`
}

type TokenDetails

type TokenDetails struct {
	AccessToken string `json:"access_token"`
	AcessUuid   string `json:"-"`
	AtExpires   int64  `json:"at_expires"`
}

type TokenManager

type TokenManager struct {
	// contains filtered or unexported fields
}

func NewTokenManager

func NewTokenManager(accessTokenSecret string, accessTokenValidaityInHours int64, collection *mongo.Collection) *TokenManager

func (*TokenManager) DeleteToken

func (tm *TokenManager) DeleteToken(filter interface{}, opts ...*options.DeleteOptions) error

func (*TokenManager) ExtractTokenMetadata

func (tm *TokenManager) ExtractTokenMetadata(token *jwt.Token) (*AccessDetails, error)

func (*TokenManager) FindToken

func (tm *TokenManager) FindToken(filter interface{}, opts ...*options.FindOneOptions) (*AccessDetails, error)

func (*TokenManager) GenerateToken

func (tm *TokenManager) GenerateToken(userId string) (*TokenDetails, error)

func (*TokenManager) IsExists

func (tm *TokenManager) IsExists(filter interface{}, opts ...*options.FindOneOptions) (bool, error)

func (*TokenManager) SaveToken

func (tm *TokenManager) SaveToken(userId string, td *TokenDetails) error

type TokenMgr

type TokenMgr interface {
	SaveToken(userId string, td *TokenDetails) error
	GenerateToken(userId string) (*TokenDetails, error)
	FindToken(filter interface{}, opts ...*options.FindOneOptions) (*AccessDetails, error)
	IsExists(filter interface{}, opts ...*options.FindOneOptions) (bool, error)
	DeleteToken(filter interface{}, opts ...*options.DeleteOptions) error
}

type Uploader

type Uploader interface {
	UploadImage(ctx context.Context, file *multipart.FileHeader, collection string) (string, error)
}

type User

type User struct {
	ID         string    `json:"id" bson:"_id,omitempty"`
	Name       string    `json:"name" bson:"name"`
	Email      string    `json:"email" bson:"email"`
	IsVerified bool      `json:"is_verified" bson:"is_verified"`
	Role       Role      `json:"role" bson:"role"`
	Picture    string    `json:"picture" bson:"picture"`
	CreatedAt  time.Time `json:"created_at" bson:"created_at"`
	UpdatedAt  time.Time `json:"updated_at" bson:"updated_at"`
}

type UserController

type UserController struct {
	// contains filtered or unexported fields
}

func NewUserController

func NewUserController(service UserServices, uploader Uploader) *UserController

func (*UserController) Callback

func (uc *UserController) Callback(c *gin.Context)

func (*UserController) GetAboutMe

func (uc *UserController) GetAboutMe(c *gin.Context)

func (*UserController) GetMailingList

func (uc *UserController) GetMailingList(c *gin.Context)

func (*UserController) GetUsers

func (uc *UserController) GetUsers(c *gin.Context)

func (*UserController) Login

func (uc *UserController) Login(c *gin.Context)

func (*UserController) Logout

func (uc *UserController) Logout(c *gin.Context)

func (*UserController) Profile

func (uc *UserController) Profile(c *gin.Context)

func (*UserController) SubscribeToMailingList

func (uc *UserController) SubscribeToMailingList(c *gin.Context)

func (*UserController) UnSubscribeFromMailingList

func (uc *UserController) UnSubscribeFromMailingList(c *gin.Context)

func (*UserController) UpdateAboutMe

func (uc *UserController) UpdateAboutMe(c *gin.Context)

type UserRepo

type UserRepo struct {
	// contains filtered or unexported fields
}

func NewUserRepo

func NewUserRepo(collection *mongo.Collection) *UserRepo

func (*UserRepo) CreateAboutMe

func (repo *UserRepo) CreateAboutMe(filter interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)

func (*UserRepo) CreateMailingList

func (repo *UserRepo) CreateMailingList(filter interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)

func (*UserRepo) CreateUser

func (repo *UserRepo) CreateUser(user *User) (*mongo.InsertOneResult, error)

func (*UserRepo) GetAboutMe

func (repo *UserRepo) GetAboutMe(filter interface{}, opts ...*options.FindOneOptions) (*AboutMe, error)

func (*UserRepo) GetMailingList

func (repo *UserRepo) GetMailingList(filter interface{}, opts ...*options.FindOneOptions) (*MailingList, error)

func (*UserRepo) GetUser

func (repo *UserRepo) GetUser(filter interface{}, opts ...*options.FindOneOptions) (*User, error)

func (*UserRepo) GetUsers

func (repo *UserRepo) GetUsers(filter interface{}, opts ...*options.FindOptions) ([]*User, error)

func (*UserRepo) IsExists

func (repo *UserRepo) IsExists(filter interface{}, opts ...*options.FindOneOptions) (bool, error)

func (*UserRepo) UpdateAboutMe

func (repo *UserRepo) UpdateAboutMe(filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

func (*UserRepo) UpdateMailingList

func (repo *UserRepo) UpdateMailingList(filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

func (*UserRepo) UpdateUser

func (repo *UserRepo) UpdateUser(filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

type UserRepository

type UserRepository interface {
	CreateUser(user *User) (*mongo.InsertOneResult, error)
	GetUser(filter interface{}, opts ...*options.FindOneOptions) (*User, error)
	GetUsers(filter interface{}, opts ...*options.FindOptions) ([]*User, error)
	UpdateUser(filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	IsExists(filter interface{}, opts ...*options.FindOneOptions) (bool, error)
	CreateAboutMe(filter interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)
	GetAboutMe(filter interface{}, opts ...*options.FindOneOptions) (*AboutMe, error)
	UpdateAboutMe(filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

	CreateMailingList(filter interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)
	GetMailingList(filter interface{}, opts ...*options.FindOneOptions) (*MailingList, error)
	UpdateMailingList(filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
}

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

func NewUserService

func NewUserService(repo UserRepository, tokenMgr TokenMgr) *UserService

func (*UserService) Callback

func (us *UserService) Callback(ctx *gin.Context) (*GoogleLoginResponse, error)

func (*UserService) GenerateAccessToken

func (us *UserService) GenerateAccessToken(userId string) (*TokenDetails, error)

func (*UserService) GetAboutMe

func (us *UserService) GetAboutMe() (*AboutMe, error)

func (*UserService) GetMailingList

func (us *UserService) GetMailingList() (*MailingList, error)

func (*UserService) GetUsers

func (us *UserService) GetUsers() ([]*User, error)

func (*UserService) Login

func (us *UserService) Login(ctx *gin.Context) (string, error)

func (*UserService) Logout

func (us *UserService) Logout(accessUuid string) error

func (*UserService) Profile

func (us *UserService) Profile(userId string) (*User, error)

func (*UserService) SaveAccessToken

func (us *UserService) SaveAccessToken(userId string, td *TokenDetails) error

func (*UserService) SaveUser

func (us *UserService) SaveUser(googleLoginResponse *GoogleLoginResponse) error

func (*UserService) SubscribeToMailingList

func (us *UserService) SubscribeToMailingList(id string) error

func (*UserService) UnSubscribeFromMailingList

func (us *UserService) UnSubscribeFromMailingList(id string) error

func (*UserService) UpdateAboutMe

func (us *UserService) UpdateAboutMe(userId, aboutMe, profilePicture string) error

type UserServices

type UserServices interface {
	Login(ctx *gin.Context) (string, error)
	Callback(ctx *gin.Context) (*GoogleLoginResponse, error)
	SaveAccessToken(userId string, td *TokenDetails) error
	GenerateAccessToken(userId string) (*TokenDetails, error)
	SaveUser(googleLoginResponse *GoogleLoginResponse) error
	Logout(accessUuid string) error
	Profile(userId string) (*User, error)
	UpdateAboutMe(userId, aboutMe, profilePicture string) error
	GetAboutMe() (*AboutMe, error)
	SubscribeToMailingList(id string) error
	UnSubscribeFromMailingList(id string) error
	GetMailingList() (*MailingList, error)
	GetUsers() ([]*User, error)
}

Jump to

Keyboard shortcuts

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