user

package
v0.0.0-...-7514732 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitTokenExpiryIndex

func InitTokenExpiryIndex(ctx context.Context, 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

type MiddlewareTokenManager

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

type MiddlewareUserRepo

type MiddlewareUserRepo interface {
	GetUser(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (bool, error)

func (*TokenManager) SaveToken

func (tm *TokenManager) SaveToken(ctx context.Context, userId string, td *TokenDetails) error

type TokenMgr

type TokenMgr interface {
	SaveToken(ctx context.Context, userId string, td *TokenDetails) error
	GenerateToken(userId string) (*TokenDetails, error)
	FindToken(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (*AccessDetails, error)
	IsExists(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (bool, error)
	DeleteToken(ctx context.Context, 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(ctx context.Context, filter interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)

func (*UserRepo) CreateMailingList

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

func (*UserRepo) CreateUser

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

func (*UserRepo) GetAboutMe

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

func (*UserRepo) GetMailingList

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

func (*UserRepo) GetUser

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

func (*UserRepo) GetUsers

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

func (*UserRepo) IsExists

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

func (*UserRepo) UpdateAboutMe

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

func (*UserRepo) UpdateMailingList

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

func (*UserRepo) UpdateUser

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

type UserRepository

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

	CreateMailingList(ctx context.Context, filter interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)
	GetMailingList(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (*MailingList, error)
	UpdateMailingList(ctx context.Context, 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(ctx context.Context) (*AboutMe, error)

func (*UserService) GetMailingList

func (us *UserService) GetMailingList(ctx context.Context) (*MailingList, error)

func (*UserService) GetUsers

func (us *UserService) GetUsers(ctx context.Context) ([]*User, error)

func (*UserService) Login

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

func (*UserService) Logout

func (us *UserService) Logout(ctx context.Context, accessUuid string) error

func (*UserService) Profile

func (us *UserService) Profile(ctx context.Context, userId string) (*User, error)

func (*UserService) SaveAccessToken

func (us *UserService) SaveAccessToken(ctx context.Context, userId string, td *TokenDetails) error

func (*UserService) SaveUser

func (us *UserService) SaveUser(ctx context.Context, googleLoginResponse *GoogleLoginResponse) error

func (*UserService) SubscribeToMailingList

func (us *UserService) SubscribeToMailingList(ctx context.Context, id string) error

func (*UserService) UnSubscribeFromMailingList

func (us *UserService) UnSubscribeFromMailingList(ctx context.Context, id string) error

func (*UserService) UpdateAboutMe

func (us *UserService) UpdateAboutMe(ctx context.Context, userId, aboutMe, profilePicture string) error

type UserServices

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

Jump to

Keyboard shortcuts

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