auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes password using bcrypt

func VerifyPassword

func VerifyPassword(hashedPassword, password string) bool

VerifyPassword checks if password matches the hash

Types

type AuthResponse

type AuthResponse struct {
	User  User   `json:"user"`
	Token string `json:"token"`
}

AuthResponse

type ChangePasswordRequest

type ChangePasswordRequest struct {
	OldPassword string `json:"old_password"`
	NewPassword string `json:"new_password"`
}

ChangePasswordRequest

type Config

type Config struct {
	Secret       string
	TokenExpiry  int
	DatabaseName string
}

type LoginRequest

type LoginRequest struct {
	Email    string
	Password string
}

LoginRequest

type Manager

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

func New

func New(config *Config, db *database.MongoDB) (*Manager, error)

func (*Manager) ChangePassword

func (m *Manager) ChangePassword(userID string, req ChangePasswordRequest) error

ChangePassword changes user password

func (*Manager) ChangePasswordHandler

func (m *Manager) ChangePasswordHandler() gin.HandlerFunc

ChangePasswordHandler changes user password

func (*Manager) DeleteAccount

func (m *Manager) DeleteAccount(userID string) error

DeleteAccount deletes user account

func (*Manager) DeleteAccountHandler

func (m *Manager) DeleteAccountHandler() gin.HandlerFunc

DeleteAccountHandler deletes user account

func (*Manager) GenerateToken

func (m *Manager) GenerateToken(userID string) (string, error)

GenerateToken creates a JWT token for the user

func (*Manager) GetProfileHandler

func (m *Manager) GetProfileHandler() gin.HandlerFunc

GetProfileHandler returns current user profile

func (*Manager) GetUserByEmail

func (m *Manager) GetUserByEmail(email string) (*User, error)

GetUserByEmail finds a user by email

func (*Manager) GetUserByID

func (m *Manager) GetUserByID(userID string) (*User, error)

GetUserByID finds a user by ID

func (*Manager) Login

func (m *Manager) Login(req LoginRequest) (*User, string, error)

Login authenticates a user

func (*Manager) LoginHandler

func (m *Manager) LoginHandler() gin.HandlerFunc

LoginHandler returns Gin handler for login

func (*Manager) Middleware

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

Middleware returns auth middleware for protected routes

func (*Manager) Signup

func (m *Manager) Signup(req SignupRequest) (*User, string, error)

Signup creates a new user account

func (*Manager) SignupHandler

func (m *Manager) SignupHandler() gin.HandlerFunc

SignupHandler returns Gin handler for signup

func (*Manager) UpdateProfile

func (m *Manager) UpdateProfile(userID string, req UpdateProfileRequest) (*User, error)

UpdateProfile updates user's custom fields

func (*Manager) UpdateProfileHandler

func (m *Manager) UpdateProfileHandler() gin.HandlerFunc

UpdateProfileHandler updates user profile

func (*Manager) ValidateToken

func (m *Manager) ValidateToken(tokenString string) (string, error)

ValidateToken validates JWT token and returns user ID

type SignupRequest

type SignupRequest struct {
	Email    string
	Password string
	Custom   map[string]interface{}
}

SignupRequest

type UpdateProfileRequest

type UpdateProfileRequest struct {
	Custom map[string]interface{} `json:"custom"`
}

UpdateProfileRequest

type User

type User struct {
	ID        string                 `bson:"_id,omitempty" json:"id"`
	Email     string                 `bson:"email" json:"email"`
	Password  string                 `bson:"password" json:"-"`
	Custom    map[string]interface{} `bson:"custom,omitempty" json:"custom,omitempty"`
	CreatedAt time.Time              `bson:"created_at" json:"created_at"`
}

Jump to

Keyboard shortcuts

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