Documentation
¶
Index ¶
- Constants
- Variables
- func AddUserMiddleware() mux.Middleware
- func CheckPassword(u *User, password string) error
- func Logout(r *http.Request) error
- func LogoutView(w http.ResponseWriter, r *http.Request)
- func NewAppConfig() django.AppConfig
- func PasswordValidators(fn ...func(*Password) error) func(*PasswordField)
- func ValidateCharacters(isRegister bool, flags PasswordCharacterFlag) func(fields.Field)
- type AuthApplication
- type AuthView
- type BaseUserForm
- type Password
- type PasswordCharValidator
- type PasswordCharacterFlag
- type PasswordField
- type PasswordFieldOptions
- type RegisterFormConfig
- type User
- func (u *User) BeforeCreate(ctx context.Context) error
- func (u *User) BeforeSave(ctx context.Context) error
- func (u *User) DatabaseIndexes(obj attrs.Definer) []migrator.Index
- func (u *User) FieldDefs() attrs.Definitions
- func (u *User) Fields() []any
- func (u *User) SetPassword(password string) *User
- func (u *User) String() string
- func (u *User) UniqueTogether() [][]string
- type UserQuerySet
Constants ¶
View Source
const ( APPVAR_AUTH_EMAIL_LOGIN = "AUTH_EMAIL_LOGIN" // type: bool APPVAR_REGISTER_AUTH_URLS = "REGISTER_AUTH_URLS" // type: bool APPVAR_ALLOW_USER_REGISTER = "ALLOW_USER_REGISTER" // type: bool APPVAR_LOGIN_REDIRECT_URL = "LOGIN_REDIRECT_URL" // type: string || func(*http.Request) string APPVAR_LOGIN_VIEW_REVERSE_URL = "LOGIN_VIEW_REVERSE_URL" // type: string DEFAULT_LOGIN_REDIRECT_URL = "/" // default value for LOGIN_REDIRECT_URL )
View Source
const SESSION_COOKIE_NAME = "user_authentication"
Variables ¶
View Source
var CHECKER = func(hashedPassword, password string) error { if err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password)); err != nil { return autherrors.ErrPwdHashMismatch } return nil }
View Source
var ChrFlagDEFAULT = ChrFlagAll
View Source
var HASHER = func(b string) (string, error) { var bytes, err = bcrypt.GenerateFromPassword([]byte(b), bcrypt.DefaultCost) return string(bytes), err }
Functions ¶
func AddUserMiddleware ¶
func AddUserMiddleware() mux.Middleware
Add a user to a request, if one exists in the session.
func CheckPassword ¶
func LogoutView ¶ added in v1.6.9
func LogoutView(w http.ResponseWriter, r *http.Request)
func NewAppConfig ¶
func PasswordValidators ¶
func PasswordValidators(fn ...func(*Password) error) func(*PasswordField)
func ValidateCharacters ¶
func ValidateCharacters(isRegister bool, flags PasswordCharacterFlag) func(fields.Field)
Checks if: - password is at least minlen characters long - password is at most maxlen characters long - password contains at least one special character if specified - password contains at least one uppercase letter - password contains at least one lowercase letter - password contains at least one digit - password contains at least one non-digit - password does not contain any whitespace
Types ¶
type AuthApplication ¶
type AuthApplication struct {
*apps.AppConfig
Session *scs.SessionManager
LoginWithEmail bool
LoginReverseURL string
}
The AuthApplication struct is the main struct used for the auth app.
var Auth *AuthApplication = &AuthApplication{}
type AuthView ¶
type AuthView[T forms.Form] struct { *views.BaseView OnSuccess func(w http.ResponseWriter, req *http.Request, form T) error // contains filtered or unexported fields }
func RegisterView ¶
func RegisterView(baseView *views.BaseView, cfg RegisterFormConfig, opts ...func(forms.Form)) *AuthView[*BaseUserForm]
func (*AuthView[T]) GetContext ¶
type BaseUserForm ¶
type BaseUserForm struct {
*forms.BaseForm
Request *http.Request
Instance *User
// contains filtered or unexported fields
}
func UserLoginForm ¶
func UserLoginForm(r *http.Request, formOpts ...func(forms.Form)) *BaseUserForm
func UserRegisterForm ¶
func UserRegisterForm(r *http.Request, registerConfig RegisterFormConfig, formOpts ...func(forms.Form)) *BaseUserForm
func (*BaseUserForm) Login ¶
func (f *BaseUserForm) Login() error
func (*BaseUserForm) Save ¶
func (f *BaseUserForm) Save() (*User, error)
func (*BaseUserForm) SetRequest ¶
func (f *BaseUserForm) SetRequest(r *http.Request)
type Password ¶ added in v1.7.2
type Password struct {
Raw string `json:"raw"`
Hash string `json:"hash"`
// contains filtered or unexported fields
}
func NewHashedPassword ¶ added in v1.7.2
func NewPassword ¶ added in v1.7.2
type PasswordCharValidator ¶
type PasswordCharValidator struct {
GenericError error
Flags PasswordCharacterFlag
}
func (*PasswordCharValidator) Validate ¶
func (p *PasswordCharValidator) Validate(password string) error
type PasswordCharacterFlag ¶
type PasswordCharacterFlag uint8
const ( ChrFlagSpecial PasswordCharacterFlag = 1 << iota ChrFlagDigit ChrFlagLower ChrFlagUpper ChrFlagAll = ChrFlagSpecial | ChrFlagDigit | ChrFlagLower | ChrFlagUpper )
type PasswordField ¶
func NewPasswordField ¶
func NewPasswordField(config PasswordFieldOptions, opts ...func(fields.Field)) *PasswordField
func (*PasswordField) Clean ¶
func (p *PasswordField) Clean(ctx context.Context, value interface{}) (interface{}, error)
func (*PasswordField) ValueToForm ¶ added in v1.7.2
func (p *PasswordField) ValueToForm(value interface{}) interface{}
type PasswordFieldOptions ¶ added in v1.7.0
type PasswordFieldOptions struct {
Flags PasswordCharacterFlag
IsRegistering bool
UseDefaultOptions bool
Options []func(fields.Field)
}
type RegisterFormConfig ¶
type RegisterFormConfig struct {
// Include both email and username fields in the registration form.
//
// If this is false - only the field specified by `LoginWithEmail` will be
// included in the form.
AlwaysAllLoginFields bool
// Automatically login the user after registration.
//
// This requires a non-nil http request to be passed to the form.
AutoLogin bool
// Ask for the user's first and last name.
AskForNames bool
// Create an inactive user account.
//
// This is useful for when the user needs to verify their email address
// before they can login.
IsInactive bool
}
type User ¶ added in v1.7.2
type User struct {
models.Model `table:"auth_users" json:"-"`
users.Base
ID uint64 `json:"id" attrs:"primary;readonly"`
Email *drivers.Email `json:"email"`
Username string `json:"username"`
Password *Password `json:"password"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
CreatedAt drivers.DateTime `json:"created_at" attrs:"readonly"`
UpdatedAt drivers.DateTime `json:"updated_at" attrs:"readonly"`
}
func UnAuthenticatedUser ¶
func UnAuthenticatedUser() *User
func (*User) DatabaseIndexes ¶ added in v1.7.2
func (*User) FieldDefs ¶ added in v1.7.2
func (u *User) FieldDefs() attrs.Definitions
func (*User) SetPassword ¶ added in v1.7.2
func (*User) UniqueTogether ¶ added in v1.7.2
type UserQuerySet ¶ added in v1.7.2
type UserQuerySet struct {
*queries.WrappedQuerySet[*User, *UserQuerySet, *queries.QuerySet[*User]]
}
func GetUserQuerySet ¶ added in v1.7.2
func GetUserQuerySet() *UserQuerySet
func (*UserQuerySet) CloneQuerySet ¶ added in v1.7.2
func (qs *UserQuerySet) CloneQuerySet(wrapped *queries.WrappedQuerySet[*User, *UserQuerySet, *queries.QuerySet[*User]]) *UserQuerySet
Source Files
¶
Click to show internal directories.
Click to hide internal directories.