Documentation
¶
Index ¶
- func GetUser() gin.HandlerFunc
- func GetUserToken() gin.HandlerFunc
- func GetUsers() gin.HandlerFunc
- func HashToken(token string) string
- func Login() gin.HandlerFunc
- func PasswordHash(password string) (string, error)
- func RefreshToken() gin.HandlerFunc
- func SignUp() gin.HandlerFunc
- func StoreRefreshToken(ctx context.Context, userID primitive.ObjectID, refreshToken string) error
- func ValidateRefreshToken(ctx context.Context, userID primitive.ObjectID, refreshToken string) (bool, error)
- func VerifyHash(providedPassword string, storedPassword string) (bool, string)
- func VerifyTokenHash(userToken string, storedToken string) (bool, string)
- type UserResponse
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 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 RefreshToken ¶
func RefreshToken() gin.HandlerFunc
func SignUp ¶
func SignUp() gin.HandlerFunc
func StoreRefreshToken ¶
func ValidateRefreshToken ¶
Types ¶
type UserResponse ¶
Click to show internal directories.
Click to hide internal directories.