auth

package
v1.0.12-rc-1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package auth provides session-based user authentication for Adele applications.

It handles login and logout, "remember me" cookie tokens, retrieval of the currently authenticated user, and bcrypt password hashing, persisting users and remember tokens through the framework's database layer.

Index

Constants

This section is empty.

Variables

View Source
var InvalidPasswordOrUserError = errors.New("the username or password is incorrect")
View Source
var RememberTokenDeleteError = errors.New("error removing remember token form storage")
View Source
var RememberTokenHashError = errors.New("error hashing remember token")
View Source
var RememberTokenStoreError = errors.New("error adding remember token to storage")

Functions

func HashPassword

func HashPassword(password string) (*[]byte, error)

hash a plain text password for secure use in the application

Types

type Auth

type Auth struct {
	AppName  string
	DB       *database.Database
	ErrorLog *log.Logger
	Session  *scs.SessionManager
}

func (*Auth) Check

func (a *Auth) Check(r *http.Request) bool

Check if a user is logged in.

func (*Auth) Login

func (a *Auth) Login(w http.ResponseWriter, r *http.Request, email, password string) (bool, error)

Log a user in.

func (*Auth) Logout

func (a *Auth) Logout(w http.ResponseWriter, r *http.Request) (bool, error)

Log the current user out.

func (*Auth) User

func (a *Auth) User(r *http.Request) *User

Get the current authenticated user

type RememberToken

type RememberToken struct {
	ID            int       `db:"id,omitempty"   json:"id"`
	UserID        int       `db:"user_id"        json:"userId"`
	RememberToken string    `db:"remember_token" json:"-"`
	CreatedAt     time.Time `db:"created_at"     json:"createdAt"`
	UpdatedAt     time.Time `db:"updated_at"     json:"updatedAt"`
}

type User

type User struct {
	ID        int       `db:"id,omitempty" json:"id"`
	FirstName string    `db:"first_name"   json:"firstName"`
	LastName  string    `db:"last_name"    json:"lastName"`
	Email     string    `db:"email"        json:"email"`
	Active    int       `db:"user_active"  json:"active"`
	Password  string    `db:"password"     json:"-"`
	CreatedAt time.Time `db:"created_at"   json:"createdAt"`
	UpdatedAt time.Time `db:"updated_at"   json:"updatedAt"`
}

Jump to

Keyboard shortcuts

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