controller

package
v0.0.0-...-bf4e675 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUser

func GetUser() gin.HandlerFunc

func GetUserToken

func GetUserToken() gin.HandlerFunc

func GetUsers

func GetUsers() gin.HandlerFunc

func HashToken

func HashToken(token string) string
func DeleteTokens() gin.HandlerFunc {
		return func(c *gin.Context) {
			ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
			defer cancel()
			refreshTokenCollection.DeleteMany(ctx, bson.M{})
			c.JSON(http.StatusOK, gin.H{"message": "Successfully deleted tokens"})
		}
	}

func RevokeRefreshToken(ctx context.Context, userID string) error {

	_, err := refreshTokenCollection.DeleteOne(ctx, bson.M{"user_id": userID})
	return err
}

func StoreRefreshToken(ctx context.Context, userID primitive.ObjectID, refreshToken string) error {

	var refreshTokenDoc models.RefreshToken

	refreshTokenDoc.ID = userID
	refreshTokenDoc.TokenHash = HashToken(refreshToken)
	refreshTokenDoc.ExpiresAt = time.Now().Add(time.Hour * 24 * 7)

	_, err := refreshTokenCollection.InsertOne(ctx, refreshTokenDoc)
	return err
}

func Login

func Login() gin.HandlerFunc

func PasswordHash

func PasswordHash(password string) (string, error)

func RefreshToken

func RefreshToken() gin.HandlerFunc

func SignUp

func SignUp() gin.HandlerFunc

func StoreRefreshToken

func StoreRefreshToken(ctx context.Context, userID primitive.ObjectID, refreshToken string) error

func ValidateRefreshToken

func ValidateRefreshToken(ctx context.Context, userID primitive.ObjectID, refreshToken string) (bool, error)

func VerifyHash

func VerifyHash(providedPassword string, storedPassword string) (bool, string)

func VerifyTokenHash

func VerifyTokenHash(userToken string, storedToken string) (bool, string)

Types

type UserResponse

type UserResponse struct {
	ID        primitive.ObjectID `bson:"id"`
	FirstName *string            `bson:"first_name" binding:"required"`
	LastName  *string            `bson:"last_name" binding:"required"`
	Email     *string            `bson:"email"  binding:"required"`
	PhoneNo   *string            `json:"phone" validate:"required,min=10,max=10"`
}

Jump to

Keyboard shortcuts

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