login

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: MIT Imports: 34 Imported by: 10

Documentation

Index

Constants

View Source
const I18nLoginKey i18n.ModuleKey = "I18nLoginKey"
View Source
const (
	WarnCodePasswordHasBeenChanged = iota + 1
)

Variables

View Source
var (
	StyleCSSURL = assetsPathPrefix + "style.css"
	ZxcvbnJSURL = assetsPathPrefix + "zxcvbn.js"
)
View Source
var (
	ErrUserNotFound        = errors.New("user not found")
	ErrPasswordChanged     = errors.New("password changed")
	ErrWrongPassword       = errors.New("wrong password")
	ErrUserLocked          = errors.New("user locked")
	ErrUserGetLocked       = errors.New("user get locked")
	ErrWrongTOTPCode       = errors.New("wrong totp code")
	ErrTOTPCodeHasBeenUsed = errors.New("totp code has been used")
	ErrEmptyPassword       = errors.New("empty password")
	ErrPasswordNotMatch    = errors.New("password not match")
)
View Source
var DefaultViewCommon = &ViewCommon{
	WrapperClass: "flex pt-16 flex-col max-w-md mx-auto",
	TitleClass:   "leading-tight text-3xl mt-0 mb-6",
	LabelClass:   "block mb-2 text-sm text-gray-600 dark:text-gray-200",
	InputClass:   "block w-full px-4 py-2 mt-2 text-gray-700 placeholder-gray-400 bg-white border border-gray-200 rounded-md dark:placeholder-gray-600 dark:bg-gray-900 dark:text-gray-300 dark:border-gray-700 focus:border-blue-400 dark:focus:border-blue-400 focus:ring-blue-400 focus:outline-none focus:ring focus:ring-opacity-40",
	ButtonClass:  "w-full px-6 py-3 tracking-wide text-white transition-colors duration-200 transform bg-blue-500 rounded-md hover:bg-blue-400 focus:outline-none focus:bg-blue-400 focus:ring focus:ring-blue-300 focus:ring-opacity-50",
}
View Source
var Messages_en_US = &Messages{
	Confirm:                             "Confirm",
	Verify:                              "Verify",
	LoginPageTitle:                      "Sign In",
	AccountLabel:                        "Email",
	AccountPlaceholder:                  "Email",
	PasswordLabel:                       "Password",
	PasswordPlaceholder:                 "Password",
	SignInBtn:                           "Sign In",
	ForgetPasswordLink:                  "Forget your password?",
	ForgetPasswordPageTitle:             "Forget Your Password?",
	ForgotMyPasswordTitle:               "I forgot my password",
	ForgetPasswordEmailLabel:            "Enter your email",
	ForgetPasswordEmailPlaceholder:      "Email",
	SendResetPasswordEmailBtn:           "Send reset password email",
	ResendResetPasswordEmailBtn:         "Resend reset password email",
	SendEmailTooFrequentlyNotice:        "Sending emails too frequently, please try again later",
	ResetPasswordLinkSentPageTitle:      "Forget Your Password?",
	ResetPasswordLinkWasSentTo:          "A reset password link was sent to",
	ResetPasswordLinkSentPrompt:         "You can close this page and reset your password from this link.",
	ResetPasswordPageTitle:              "Reset Password",
	ResetYourPasswordTitle:              "Reset your password",
	ResetPasswordLabel:                  "Change your password",
	ResetPasswordPlaceholder:            "New password",
	ResetPasswordConfirmLabel:           "Re-enter new password",
	ResetPasswordConfirmPlaceholder:     "Confirm new password",
	ChangePasswordPageTitle:             "Change Password",
	ChangePasswordTitle:                 "Change your password",
	ChangePasswordOldLabel:              "Old password",
	ChangePasswordOldPlaceholder:        "Old Password",
	ChangePasswordNewLabel:              "New password",
	ChangePasswordNewPlaceholder:        "New Password",
	ChangePasswordNewConfirmLabel:       "Re-enter new password",
	ChangePasswordNewConfirmPlaceholder: "New Password",
	TOTPSetupPageTitle:                  "TOTP Setup",
	TOTPSetupTitle:                      "Two Factor Authentication",
	TOTPSetupScanPrompt:                 "Scan this QR code with Google Authenticator (or similar) app",
	TOTPSetupSecretPrompt:               "Or manually enter the following code into your preferred authenticator app",
	TOTPSetupEnterCodePrompt:            "Then enter the provided one-time code below",
	TOTPSetupCodePlaceholder:            "Passcode",
	TOTPValidatePageTitle:               "TOTP Validate",
	TOTPValidateTitle:                   "Two Factor Authentication",
	TOTPValidateEnterCodePrompt:         "Enter the provided one-time code below",
	TOTPValidateCodeLabel:               "Authenticator passcode",
	TOTPValidateCodePlaceholder:         "Passcode",
	ErrorSystemError:                    "System Error",
	ErrorCompleteUserAuthFailed:         "Complete User Auth Failed",
	ErrorUserNotFound:                   "User Not Found",
	ErrorIncorrectAccountNameOrPassword: "Incorrect email or password",
	ErrorUserLocked:                     "User Locked",
	ErrorAccountIsRequired:              "Email is required",
	ErrorPasswordCannotBeEmpty:          "Password cannot be empty",
	ErrorPasswordNotMatch:               "Password do not match",
	ErrorIncorrectPassword:              "Old password is incorrect",
	ErrorInvalidToken:                   "Invalid token",
	ErrorTokenExpired:                   "Token expired",
	ErrorIncorrectTOTPCode:              "Incorrect passcode",
	ErrorTOTPCodeReused:                 "This passcode has been used",
	ErrorIncorrectRecaptchaToken:        "Incorrect reCAPTCHA token",
	WarnPasswordHasBeenChanged:          "Password has been changed, please sign-in again",
	InfoPasswordSuccessfullyReset:       "Password successfully reset, please sign-in again",
	InfoPasswordSuccessfullyChanged:     "Password successfully changed, please sign-in again",
}
View Source
var Messages_ja_JP = &Messages{
	Confirm:                             "確認する",
	Verify:                              "検証",
	LoginPageTitle:                      "ログイン",
	AccountLabel:                        "メールアドレス",
	AccountPlaceholder:                  "メールアドレス",
	PasswordLabel:                       "パスワード",
	PasswordPlaceholder:                 "パスワード",
	SignInBtn:                           "ログイン",
	ForgetPasswordLink:                  "パスワードをお忘れですか?",
	ForgetPasswordPageTitle:             "パスワードをお忘れですか?",
	ForgotMyPasswordTitle:               "パスワードを忘れました",
	ForgetPasswordEmailLabel:            "メールアドレスを入力してください",
	ForgetPasswordEmailPlaceholder:      "メールアドレス",
	SendResetPasswordEmailBtn:           "パスワードリセット用メールが送信されました",
	ResendResetPasswordEmailBtn:         "パスワードリセット用メールを再送する",
	SendEmailTooFrequentlyNotice:        "メール送信回数が上限を超えています。しばらく経ってから再度お試しください",
	ResetPasswordLinkSentPageTitle:      "パスワードをお忘れですか?",
	ResetPasswordLinkWasSentTo:          "パスワードリセット用リンクが送信されました",
	ResetPasswordLinkSentPrompt:         "このリンクからパスワードリセット手続きを行い、終了後はページを閉じてください",
	ResetPasswordPageTitle:              "パスワードをリセットしてください",
	ResetYourPasswordTitle:              "パスワードをリセットしてください",
	ResetPasswordLabel:                  "パスワードを変更する",
	ResetPasswordPlaceholder:            "新しいパスワード",
	ResetPasswordConfirmLabel:           "新しいパスワードを再入力",
	ResetPasswordConfirmPlaceholder:     "新しいパスワードを確認する",
	ChangePasswordPageTitle:             "パスワードを変更する",
	ChangePasswordTitle:                 "パスワードを変更する",
	ChangePasswordOldLabel:              "古いパスワード",
	ChangePasswordOldPlaceholder:        "古いパスワード",
	ChangePasswordNewLabel:              "新しいパスワード",
	ChangePasswordNewPlaceholder:        "新しいパスワード",
	ChangePasswordNewConfirmLabel:       "新しいパスワードを再入力する",
	ChangePasswordNewConfirmPlaceholder: "新しいパスワード",
	TOTPSetupPageTitle:                  "二段階認証",
	TOTPSetupTitle:                      "二段階認証",
	TOTPSetupScanPrompt:                 "Google認証アプリ(または同等アプリ)を利用してこのQRコードをスキャンしてください",
	TOTPSetupSecretPrompt:               "または、お好きな認証アプリを利用して、以下のコードを入力してください",
	TOTPSetupEnterCodePrompt:            "以下のワンタイムコードを入力してください",
	TOTPSetupCodePlaceholder:            "パスコード",
	TOTPValidatePageTitle:               "二段階認証",
	TOTPValidateTitle:                   "二段階認証",
	TOTPValidateEnterCodePrompt:         "提供されたワンタイムコードを以下に入力してください",
	TOTPValidateCodeLabel:               "認証パスコード",
	TOTPValidateCodePlaceholder:         "パスコード",
	ErrorSystemError:                    "システムエラー",
	ErrorCompleteUserAuthFailed:         "ユーザー認証に失敗しました",
	ErrorUserNotFound:                   "このユーザーは存在しません",
	ErrorIncorrectAccountNameOrPassword: "メールアドレスまたはパスワードが間違っています",
	ErrorUserLocked:                     "ユーザーがロックされました",
	ErrorAccountIsRequired:              "メールアドレスは必須です",
	ErrorPasswordCannotBeEmpty:          "パスワードは必須です",
	ErrorPasswordNotMatch:               "パスワードが間違っています",
	ErrorIncorrectPassword:              "古いパスワードが間違っています",
	ErrorInvalidToken:                   "このトークンは無効です",
	ErrorTokenExpired:                   "トークンの有効期限が切れています",
	ErrorIncorrectTOTPCode:              "パスコードが間違っています",
	ErrorTOTPCodeReused:                 "このパスコードは既に利用されています",
	ErrorIncorrectRecaptchaToken:        "reCAPTCHAトークンが間違っています",
	WarnPasswordHasBeenChanged:          "パスワードが変更されました。再度ログインしてください",
	InfoPasswordSuccessfullyReset:       "パスワードのリセットに成功しました。再度ログインしてください",
	InfoPasswordSuccessfullyChanged:     "パスワードの変更に成功しました。再度ログインしてください",
}
View Source
var Messages_zh_CN = &Messages{
	Confirm:                             "确认",
	Verify:                              "验证",
	LoginPageTitle:                      "登录",
	AccountLabel:                        "邮箱",
	AccountPlaceholder:                  "邮箱",
	PasswordLabel:                       "密码",
	PasswordPlaceholder:                 "密码",
	SignInBtn:                           "登录",
	ForgetPasswordLink:                  "忘记密码?",
	ForgetPasswordPageTitle:             "忘记密码?",
	ForgotMyPasswordTitle:               "我忘记密码了",
	ForgetPasswordEmailLabel:            "输入您的电子邮箱",
	ForgetPasswordEmailPlaceholder:      "电子邮箱",
	SendResetPasswordEmailBtn:           "发送重置密码电子邮件",
	ResendResetPasswordEmailBtn:         "重新发送重置密码电子邮件",
	SendEmailTooFrequentlyNotice:        "邮件发送过于频繁,请稍后再试",
	ResetPasswordLinkSentPageTitle:      "忘记密码?",
	ResetPasswordLinkWasSentTo:          "已将重置密码链接发送到",
	ResetPasswordLinkSentPrompt:         "您可以关闭此页面并从此链接重置密码。",
	ResetPasswordPageTitle:              "重置密码",
	ResetYourPasswordTitle:              "重置您的密码",
	ResetPasswordLabel:                  "改变您的密码",
	ResetPasswordPlaceholder:            "新密码",
	ResetPasswordConfirmLabel:           "再次输入新密码",
	ResetPasswordConfirmPlaceholder:     "新密码",
	ChangePasswordPageTitle:             "修改密码",
	ChangePasswordTitle:                 "修改您的密码",
	ChangePasswordOldLabel:              "旧密码",
	ChangePasswordOldPlaceholder:        "旧密码",
	ChangePasswordNewLabel:              "新密码",
	ChangePasswordNewPlaceholder:        "新密码",
	ChangePasswordNewConfirmLabel:       "再次输入新密码",
	ChangePasswordNewConfirmPlaceholder: "新密码",
	TOTPSetupPageTitle:                  "双重认证",
	TOTPSetupTitle:                      "双重认证",
	TOTPSetupScanPrompt:                 "使用Google Authenticator(或类似)应用程序扫描此二维码",
	TOTPSetupSecretPrompt:               "或者将以下代码手动输入到您首选的验证器应用程序中",
	TOTPSetupEnterCodePrompt:            "然后在下面输入提供的一次性代码",
	TOTPSetupCodePlaceholder:            "passcode",
	TOTPValidatePageTitle:               "双重认证",
	TOTPValidateTitle:                   "双重认证",
	TOTPValidateEnterCodePrompt:         "在下面输入提供的一次性代码",
	TOTPValidateCodeLabel:               "Authenticator验证码",
	TOTPValidateCodePlaceholder:         "passcode",
	ErrorSystemError:                    "系统错误",
	ErrorCompleteUserAuthFailed:         "用户认证失败",
	ErrorUserNotFound:                   "找不到该用户",
	ErrorIncorrectAccountNameOrPassword: "邮箱或密码错误",
	ErrorUserLocked:                     "用户已锁定",
	ErrorAccountIsRequired:              "邮箱是必须的",
	ErrorPasswordCannotBeEmpty:          "密码不能为空",
	ErrorPasswordNotMatch:               "确认密码不匹配",
	ErrorIncorrectPassword:              "密码错误",
	ErrorInvalidToken:                   "token无效",
	ErrorTokenExpired:                   "token过期",
	ErrorIncorrectTOTPCode:              "passcode错误",
	ErrorTOTPCodeReused:                 "这个passcode已经被使用过了",
	ErrorIncorrectRecaptchaToken:        "reCAPTCHA token错误",
	WarnPasswordHasBeenChanged:          "密码被修改了,请重新登录",
	InfoPasswordSuccessfullyReset:       "密码重置成功,请重新登录",
	InfoPasswordSuccessfullyChanged:     "密码修改成功,请重新登录",
}

Functions

func GetCurrentUser

func GetCurrentUser(r *http.Request) (u interface{})

func GetSessionToken

func GetSessionToken(b *Builder, r *http.Request) string

func IsLoginWIP

func IsLoginWIP(r *http.Request) bool

IsLoginWIP indicates whether the user is in an intermediate step of login process, such as on the TOTP validation page

func MustSetQuery

func MustSetQuery(u string, keyVals ...string) string

func RevokeTOTP

func RevokeTOTP(
	ssup SessionSecureUserPasser,
	db *gorm.DB,
	userModel interface{},
	userID string,
) (err error)

Types

type Builder

type Builder struct {
	LogoutURL string
	// contains filtered or unexported fields
}

func New

func New() *Builder

func (*Builder) AfterChangePassword

func (b *Builder) AfterChangePassword(v HookFunc) (r *Builder)
func (b *Builder) AfterConfirmSendResetPasswordLink(v HookFunc) (r *Builder)

extra vals: - reset link

func (*Builder) AfterExtendSession

func (b *Builder) AfterExtendSession(v HookFunc) (r *Builder)

extra vals: - old session token

func (*Builder) AfterFailedToLogin

func (b *Builder) AfterFailedToLogin(v HookFunc) (r *Builder)

extra vals: - login error

func (*Builder) AfterLogin

func (b *Builder) AfterLogin(v HookFunc) (r *Builder)

func (*Builder) AfterLogout

func (b *Builder) AfterLogout(v HookFunc) (r *Builder)

func (*Builder) AfterOAuthComplete

func (b *Builder) AfterOAuthComplete(v HookFunc) (r *Builder)

user is goth.User

func (*Builder) AfterResetPassword

func (b *Builder) AfterResetPassword(v HookFunc) (r *Builder)

func (*Builder) AfterTOTPCodeReused

func (b *Builder) AfterTOTPCodeReused(v HookFunc) (r *Builder)

func (*Builder) AfterUserLocked

func (b *Builder) AfterUserLocked(v HookFunc) (r *Builder)

func (*Builder) AuthCookieName

func (b *Builder) AuthCookieName(v string) (r *Builder)

func (*Builder) AutoExtendSession

func (b *Builder) AutoExtendSession(v bool) (r *Builder)

extend the session if successfully authenticated default true

func (*Builder) BeforeSetPassword

func (b *Builder) BeforeSetPassword(v HookFunc) (r *Builder)

extra vals: - password

func (*Builder) ChangePassword

func (b *Builder) ChangePassword(
	r *http.Request,
	oldPassword string,
	password string,
	confirmPassword string,
	otp string,
) error

NoticeError ErrWrongPassword ErrEmptyPassword ErrPasswordNotMatch ErrWrongTOTPCode ErrTOTPCodeHasBeenUsed

func (*Builder) ChangePasswordPageFunc

func (b *Builder) ChangePasswordPageFunc(v web.PageFunc) (r *Builder)

func (*Builder) ChangePasswordPageURL

func (b *Builder) ChangePasswordPageURL(v string) (r *Builder)

func (*Builder) CookieConfig

func (b *Builder) CookieConfig(v CookieConfig) (r *Builder)

func (*Builder) DB

func (b *Builder) DB(v *gorm.DB) (r *Builder)

func (*Builder) ForgetPasswordPageFunc

func (b *Builder) ForgetPasswordPageFunc(v web.PageFunc) (r *Builder)

func (*Builder) ForgetPasswordPageURL

func (b *Builder) ForgetPasswordPageURL(v string) (r *Builder)

func (*Builder) GetSessionMaxAge

func (b *Builder) GetSessionMaxAge() int

func (*Builder) HomeURLFunc

func (b *Builder) HomeURLFunc(v HomeURLFunc) (r *Builder)

func (*Builder) I18n

func (b *Builder) I18n(v *i18n.Builder) (r *Builder)

func (*Builder) LoginPageFunc

func (b *Builder) LoginPageFunc(v web.PageFunc) (r *Builder)

func (*Builder) LoginPageURL

func (b *Builder) LoginPageURL(v string) (r *Builder)

func (*Builder) MaxRetryCount

func (b *Builder) MaxRetryCount(v int) (r *Builder)

default 5 MaxRetryCount <= 0 means no max retry count limit

func (*Builder) Middleware

func (b *Builder) Middleware(cfgs ...MiddlewareConfig) func(next http.Handler) http.Handler

func (*Builder) Mount

func (b *Builder) Mount(mux *http.ServeMux)

func (*Builder) MountAPI

func (b *Builder) MountAPI(mux *http.ServeMux)
func (b *Builder) NoForgetPasswordLink(v bool) (r *Builder)

func (*Builder) OAuthIdentifier

func (b *Builder) OAuthIdentifier(provider string, identifier OAuthIdentifier) (r *Builder)

OAuthIdentifier is an externally-facing account identifier, such as an email address for a Google account. default is email, fallback is userID

func (*Builder) OAuthProviders

func (b *Builder) OAuthProviders(vs ...*Provider) (r *Builder)

func (*Builder) Recaptcha

func (b *Builder) Recaptcha(enable bool, config ...RecaptchaConfig) (r *Builder)

Google reCAPTCHA.

func (*Builder) ResetPasswordLinkSentPageFunc

func (b *Builder) ResetPasswordLinkSentPageFunc(v web.PageFunc) (r *Builder)

func (*Builder) ResetPasswordLinkSentPageURL

func (b *Builder) ResetPasswordLinkSentPageURL(v string) (r *Builder)

func (*Builder) ResetPasswordPageFunc

func (b *Builder) ResetPasswordPageFunc(v web.PageFunc) (r *Builder)

func (*Builder) ResetPasswordPageURL

func (b *Builder) ResetPasswordPageURL(v string) (r *Builder)

func (*Builder) Secret

func (b *Builder) Secret(v string) (r *Builder)

func (*Builder) SessionMaxAge

func (b *Builder) SessionMaxAge(v int) (r *Builder)

seconds default 1h

func (*Builder) TOTP

func (b *Builder) TOTP(enable bool, config ...TOTPConfig) (r *Builder)

func (*Builder) TOTPSetupPageFunc

func (b *Builder) TOTPSetupPageFunc(v web.PageFunc) (r *Builder)

func (*Builder) TOTPSetupPageURL

func (b *Builder) TOTPSetupPageURL(v string) (r *Builder)

func (*Builder) TOTPValidatePageFunc

func (b *Builder) TOTPValidatePageFunc(v web.PageFunc) (r *Builder)

func (*Builder) TOTPValidatePageURL

func (b *Builder) TOTPValidatePageURL(v string) (r *Builder)

func (*Builder) URIPrefix

func (b *Builder) URIPrefix(v string) (r *Builder)

func (*Builder) UserModel

func (b *Builder) UserModel(m interface{}) (r *Builder)

func (*Builder) ViewHelper

func (b *Builder) ViewHelper() *ViewHelper

type ContextUserKey

type ContextUserKey int
const (
	UserKey ContextUserKey = iota
)

type CookieConfig

type CookieConfig struct {
	Path     string
	Domain   string
	SameSite http.SameSite
}

type DisableAutoRedirectToHomePage

type DisableAutoRedirectToHomePage struct{}

DisableAutoRedirectToHomePage makes it possible to visit login page when user is logged in

type FailCode

type FailCode int
const (
	FailCodeSystemError FailCode = iota + 1
	FailCodeCompleteUserAuthFailed
	FailCodeUserNotFound
	FailCodeIncorrectAccountNameOrPassword
	FailCodeUserLocked
	FailCodeAccountIsRequired
	FailCodePasswordCannotBeEmpty
	FailCodePasswordNotMatch
	FailCodeIncorrectPassword
	FailCodeInvalidToken
	FailCodeTokenExpired
	FailCodeIncorrectTOTPCode
	FailCodeTOTPCodeHasBeenUsed
	FailCodeIncorrectRecaptchaToken
)

type HomeURLFunc

type HomeURLFunc func(r *http.Request, user interface{}) string

type HookFunc

type HookFunc func(r *http.Request, user interface{}, extraVals ...interface{}) error

type InfoCode

type InfoCode int
const (
	InfoCodePasswordSuccessfullyReset InfoCode = iota + 1
	InfoCodePasswordSuccessfullyChanged
)

type LoginNotRequired

type LoginNotRequired struct{}

LoginNotRequired executes the next handler regardless of whether the user is logged in or not

type Messages

type Messages struct {
	// common
	Confirm string
	Verify  string
	// login page
	LoginPageTitle      string
	AccountLabel        string
	AccountPlaceholder  string
	PasswordLabel       string
	PasswordPlaceholder string
	SignInBtn           string
	ForgetPasswordLink  string
	// forget password page
	ForgetPasswordPageTitle        string
	ForgotMyPasswordTitle          string
	ForgetPasswordEmailLabel       string
	ForgetPasswordEmailPlaceholder string
	SendResetPasswordEmailBtn      string
	ResendResetPasswordEmailBtn    string
	SendEmailTooFrequentlyNotice   string
	// reset password link sent page
	ResetPasswordLinkSentPageTitle string
	ResetPasswordLinkWasSentTo     string
	ResetPasswordLinkSentPrompt    string
	// reset password page
	ResetPasswordPageTitle          string
	ResetYourPasswordTitle          string
	ResetPasswordLabel              string
	ResetPasswordPlaceholder        string
	ResetPasswordConfirmLabel       string
	ResetPasswordConfirmPlaceholder string
	// change password page
	ChangePasswordPageTitle             string
	ChangePasswordTitle                 string
	ChangePasswordOldLabel              string
	ChangePasswordOldPlaceholder        string
	ChangePasswordNewLabel              string
	ChangePasswordNewPlaceholder        string
	ChangePasswordNewConfirmLabel       string
	ChangePasswordNewConfirmPlaceholder string
	// TOTP setup page
	TOTPSetupPageTitle       string
	TOTPSetupTitle           string
	TOTPSetupScanPrompt      string
	TOTPSetupSecretPrompt    string
	TOTPSetupEnterCodePrompt string
	TOTPSetupCodePlaceholder string
	// TOTP validate page
	TOTPValidatePageTitle       string
	TOTPValidateTitle           string
	TOTPValidateEnterCodePrompt string
	TOTPValidateCodeLabel       string
	TOTPValidateCodePlaceholder string
	// Error Messages
	ErrorSystemError                    string
	ErrorCompleteUserAuthFailed         string
	ErrorUserNotFound                   string
	ErrorIncorrectAccountNameOrPassword string
	ErrorUserLocked                     string
	ErrorAccountIsRequired              string
	ErrorPasswordCannotBeEmpty          string
	ErrorPasswordNotMatch               string
	ErrorIncorrectPassword              string
	ErrorInvalidToken                   string
	ErrorTokenExpired                   string
	ErrorIncorrectTOTPCode              string
	ErrorTOTPCodeReused                 string
	ErrorIncorrectRecaptchaToken        string
	// Warn Messages
	WarnPasswordHasBeenChanged string
	// Info Messages
	InfoPasswordSuccessfullyReset   string
	InfoPasswordSuccessfullyChanged string
}

type MiddlewareConfig

type MiddlewareConfig interface {
	// contains filtered or unexported methods
}

type NoticeError

type NoticeError struct {
	Level   NoticeLevel
	Message string
}

func (*NoticeError) Error

func (e *NoticeError) Error() string

type NoticeLevel

type NoticeLevel int
const (
	NoticeLevel_Info NoticeLevel = iota
	NoticeLevel_Warn
	NoticeLevel_Error
)

type OAuthIdentifier

type OAuthIdentifier int
const (
	OAuthIdentifierEmail OAuthIdentifier = iota
	OAuthIdentifierName
	OAuthIdentifierNickName
	OAuthIdentifierUserID
)

type OAuthInfo

type OAuthInfo struct {
	OAuthProvider string `` /* 250-byte string literal not displayed */
	OAuthUserID   string `gorm:"index:uidx_users_oauth_provider_user_id,unique,where:o_auth_provider!='' and o_auth_user_id!='' and deleted_at is null"`
	// OAuthIdentifier is an externally-facing account identifier, such as an email address for a Google account.
	// it is used to find the user record on the first login
	OAuthIdentifier string `` /* 131-byte string literal not displayed */
	OAuthAvatar     string `gorm:"-"`
}

func (*OAuthInfo) FindUserByOAuthIdentifier

func (oa *OAuthInfo) FindUserByOAuthIdentifier(db *gorm.DB, model interface{}, provider string, identifier string) (user interface{}, err error)

func (*OAuthInfo) FindUserByOAuthUserID

func (oa *OAuthInfo) FindUserByOAuthUserID(db *gorm.DB, model interface{}, provider string, oid string) (user interface{}, err error)

func (*OAuthInfo) GetAvatar

func (oa *OAuthInfo) GetAvatar() string

func (*OAuthInfo) InitOAuthUserID

func (oa *OAuthInfo) InitOAuthUserID(db *gorm.DB, model interface{}, provider string, identifier string, oid string) error

func (*OAuthInfo) SetAvatar

func (oa *OAuthInfo) SetAvatar(v string)

type OAuthUser

type OAuthUser interface {
	FindUserByOAuthUserID(db *gorm.DB, model interface{}, provider string, oid string) (user interface{}, err error)
	FindUserByOAuthIdentifier(db *gorm.DB, model interface{}, provider string, identifier string) (user interface{}, err error)
	// only update the o_auth_user_id when it's empty(null or ”)
	InitOAuthUserID(db *gorm.DB, model interface{}, provider string, identifier string, oid string) error
	SetAvatar(v string)
	GetAvatar() string
}

type PrimaryFielder

type PrimaryFielder interface {
	PrimaryField() string
}

type Provider

type Provider struct {
	Goth goth.Provider
	Key  string
	Text string
}

type RecaptchaConfig

type RecaptchaConfig struct {
	SiteKey   string
	SecretKey string
}

type SessionSecure

type SessionSecure struct {
	SessionSecure string `gorm:"size:32"`
}

func (*SessionSecure) GetSecure

func (ss *SessionSecure) GetSecure() string

func (*SessionSecure) UpdateSecure

func (ss *SessionSecure) UpdateSecure(db *gorm.DB, model interface{}, id string) error

type SessionSecureUserPasser

type SessionSecureUserPasser interface {
	SessionSecurer
	UserPasser
}

type SessionSecurer

type SessionSecurer interface {
	UpdateSecure(db *gorm.DB, model interface{}, id string) error
	GetSecure() string
}

type TOTPConfig

type TOTPConfig struct {
	Issuer string
}

type UserClaims

type UserClaims struct {
	Provider      string
	Email         string
	Name          string
	UserID        string
	AvatarURL     string
	Location      string
	IDToken       string
	PassUpdatedAt string
	TOTPValidated bool
	jwt.RegisteredClaims
}

type UserPass

type UserPass struct {
	Account  string `gorm:"index:uidx_users_account,unique,where:account!='' and deleted_at is null"`
	Password string `gorm:"size:60"`
	// UnixNano string
	PassUpdatedAt               string
	LoginRetryCount             int
	Locked                      bool
	LockedAt                    *time.Time
	ResetPasswordToken          string `gorm:"index:uidx_users_reset_password_token,unique,where:reset_password_token!=''"`
	ResetPasswordTokenCreatedAt *time.Time
	ResetPasswordTokenExpiredAt *time.Time
	TOTPSecret                  string
	IsTOTPSetup                 bool
	LastUsedTOTPCode            string
	LastTOTPCodeUsedAt          *time.Time
}

func (*UserPass) ConsumeResetPasswordToken

func (up *UserPass) ConsumeResetPasswordToken(db *gorm.DB, model interface{}) error

func (*UserPass) EncryptPassword

func (up *UserPass) EncryptPassword()

func (*UserPass) FindUser

func (up *UserPass) FindUser(db *gorm.DB, model interface{}, account string) (user interface{}, err error)

func (*UserPass) GenerateResetPasswordToken

func (up *UserPass) GenerateResetPasswordToken(db *gorm.DB, model interface{}) (token string, err error)

func (*UserPass) GetAccountName

func (up *UserPass) GetAccountName() string

func (*UserPass) GetIsTOTPSetup

func (up *UserPass) GetIsTOTPSetup() bool

func (*UserPass) GetLastUsedTOTPCode

func (up *UserPass) GetLastUsedTOTPCode() (code string, usedAt *time.Time)

func (*UserPass) GetLocked

func (up *UserPass) GetLocked() bool

func (*UserPass) GetLoginRetryCount

func (up *UserPass) GetLoginRetryCount() int

func (*UserPass) GetPasswordUpdatedAt

func (up *UserPass) GetPasswordUpdatedAt() string

func (*UserPass) GetResetPasswordToken

func (up *UserPass) GetResetPasswordToken() (token string, createdAt *time.Time, expired bool)

func (*UserPass) GetTOTPSecret

func (up *UserPass) GetTOTPSecret() string

func (*UserPass) IncreaseRetryCount

func (up *UserPass) IncreaseRetryCount(db *gorm.DB, model interface{}) error

func (*UserPass) IsPasswordCorrect

func (up *UserPass) IsPasswordCorrect(password string) bool

func (*UserPass) LockUser

func (up *UserPass) LockUser(db *gorm.DB, model interface{}) error

func (*UserPass) SetIsTOTPSetup

func (up *UserPass) SetIsTOTPSetup(db *gorm.DB, model interface{}, v bool) error

func (*UserPass) SetLastUsedTOTPCode

func (up *UserPass) SetLastUsedTOTPCode(db *gorm.DB, model interface{}, passcode string) error

func (*UserPass) SetPassword

func (up *UserPass) SetPassword(db *gorm.DB, model interface{}, password string) error

func (*UserPass) SetTOTPSecret

func (up *UserPass) SetTOTPSecret(db *gorm.DB, model interface{}, key string) error

func (*UserPass) UnlockUser

func (up *UserPass) UnlockUser(db *gorm.DB, model interface{}) error

type UserPasser

type UserPasser interface {
	FindUser(db *gorm.DB, model interface{}, account string) (user interface{}, err error)
	EncryptPassword()
	IsPasswordCorrect(password string) bool
	IncreaseRetryCount(db *gorm.DB, model interface{}) error
	GenerateResetPasswordToken(db *gorm.DB, model interface{}) (token string, err error)
	ConsumeResetPasswordToken(db *gorm.DB, model interface{}) error

	GetAccountName() string
	GetPasswordUpdatedAt() string
	GetLoginRetryCount() int
	GetLocked() bool
	GetIsTOTPSetup() bool
	GetTOTPSecret() string
	GetLastUsedTOTPCode() (code string, usedAt *time.Time)
	GetResetPasswordToken() (token string, createdAt *time.Time, expired bool)

	SetPassword(db *gorm.DB, model interface{}, password string) error
	SetIsTOTPSetup(db *gorm.DB, model interface{}, v bool) error
	SetTOTPSecret(db *gorm.DB, model interface{}, key string) error
	SetLastUsedTOTPCode(db *gorm.DB, model interface{}, passcode string) error

	LockUser(db *gorm.DB, model interface{}) error
	UnlockUser(db *gorm.DB, model interface{}) error
}

type ViewCommon

type ViewCommon struct {
	WrapperClass string
	TitleClass   string
	LabelClass   string
	InputClass   string
	ButtonClass  string
}

func (*ViewCommon) ErrNotice

func (vc *ViewCommon) ErrNotice(msg string) HTMLComponent

func (*ViewCommon) ErrorBody

func (vc *ViewCommon) ErrorBody(msg string) HTMLComponent

func (*ViewCommon) InfoNotice

func (vc *ViewCommon) InfoNotice(msg string) HTMLComponent

func (*ViewCommon) Notice

func (vc *ViewCommon) Notice(vh *ViewHelper, msgr *Messages, w http.ResponseWriter, r *http.Request) HTMLComponent

func (*ViewCommon) PasswordInputWithRevealFunction

func (vc *ViewCommon) PasswordInputWithRevealFunction(
	name string,
	placeholder string,
	id string,
	val string,
) HTMLComponent

func (*ViewCommon) PasswordStrengthMeter

func (vc *ViewCommon) PasswordStrengthMeter(inputID string) HTMLComponent

func (*ViewCommon) WarnNotice

func (vc *ViewCommon) WarnNotice(msg string) HTMLComponent

type ViewHelper

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

func (*ViewHelper) ChangePasswordURL

func (vh *ViewHelper) ChangePasswordURL() string

func (*ViewHelper) FindUserByID

func (vh *ViewHelper) FindUserByID(id string) (user interface{}, err error)

func (*ViewHelper) ForgetPasswordPageURL

func (vh *ViewHelper) ForgetPasswordPageURL() string

func (*ViewHelper) GetFailCodeFlash

func (vh *ViewHelper) GetFailCodeFlash(w http.ResponseWriter, r *http.Request) FailCode

func (*ViewHelper) GetFailFlashMessage

func (vh *ViewHelper) GetFailFlashMessage(msgr *Messages, w http.ResponseWriter, r *http.Request) string

func (*ViewHelper) GetInfoCodeFlash

func (vh *ViewHelper) GetInfoCodeFlash(w http.ResponseWriter, r *http.Request) InfoCode

func (*ViewHelper) GetInfoFlashMessage

func (vh *ViewHelper) GetInfoFlashMessage(msgr *Messages, w http.ResponseWriter, r *http.Request) string

func (*ViewHelper) GetNoticeFlash

func (vh *ViewHelper) GetNoticeFlash(w http.ResponseWriter, r *http.Request) *NoticeError

func (*ViewHelper) GetSecondsToRedoFlash

func (vh *ViewHelper) GetSecondsToRedoFlash(w http.ResponseWriter, r *http.Request) int

func (*ViewHelper) GetWarnCodeFlash

func (vh *ViewHelper) GetWarnCodeFlash(w http.ResponseWriter, r *http.Request) WarnCode

func (*ViewHelper) GetWarnFlashMessage

func (vh *ViewHelper) GetWarnFlashMessage(msgr *Messages, w http.ResponseWriter, r *http.Request) string

func (*ViewHelper) GetWrongChangePasswordInputFlash

func (vh *ViewHelper) GetWrongChangePasswordInputFlash(w http.ResponseWriter, r *http.Request) WrongChangePasswordInputFlash

func (*ViewHelper) GetWrongForgetPasswordInputFlash

func (vh *ViewHelper) GetWrongForgetPasswordInputFlash(w http.ResponseWriter, r *http.Request) WrongForgetPasswordInputFlash

func (*ViewHelper) GetWrongLoginInputFlash

func (vh *ViewHelper) GetWrongLoginInputFlash(w http.ResponseWriter, r *http.Request) WrongLoginInputFlash

func (*ViewHelper) GetWrongResetPasswordInputFlash

func (vh *ViewHelper) GetWrongResetPasswordInputFlash(w http.ResponseWriter, r *http.Request) WrongResetPasswordInputFlash

func (*ViewHelper) I18n

func (vh *ViewHelper) I18n() *i18n.Builder
func (vh *ViewHelper) NoForgetPasswordLink() bool

func (*ViewHelper) OAuthBeginURL

func (vh *ViewHelper) OAuthBeginURL() string

func (*ViewHelper) OAuthEnabled

func (vh *ViewHelper) OAuthEnabled() bool

func (*ViewHelper) OAuthProviders

func (vh *ViewHelper) OAuthProviders() []*Provider

func (*ViewHelper) PasswordLoginURL

func (vh *ViewHelper) PasswordLoginURL() string

func (*ViewHelper) RecaptchaEnabled

func (vh *ViewHelper) RecaptchaEnabled() bool

func (*ViewHelper) RecaptchaSiteKey

func (vh *ViewHelper) RecaptchaSiteKey() string

func (*ViewHelper) ResetPasswordURL

func (vh *ViewHelper) ResetPasswordURL() string

func (*ViewHelper) SendResetPasswordLinkURL

func (vh *ViewHelper) SendResetPasswordLinkURL() string

func (*ViewHelper) TOTPEnabled

func (vh *ViewHelper) TOTPEnabled() bool

func (*ViewHelper) TOTPIssuer

func (vh *ViewHelper) TOTPIssuer() string

func (*ViewHelper) UserPassEnabled

func (vh *ViewHelper) UserPassEnabled() bool

func (*ViewHelper) ValidateTOTPURL

func (vh *ViewHelper) ValidateTOTPURL() string

type WarnCode

type WarnCode int

type WrongChangePasswordInputFlash

type WrongChangePasswordInputFlash struct {
	OldPassword     string
	NewPassword     string
	ConfirmPassword string
	TOTP            string
}

type WrongForgetPasswordInputFlash

type WrongForgetPasswordInputFlash struct {
	Account string
	TOTP    string
}

type WrongLoginInputFlash

type WrongLoginInputFlash struct {
	Account  string
	Password string
}

type WrongResetPasswordInputFlash

type WrongResetPasswordInputFlash struct {
	Password        string
	ConfirmPassword string
	TOTP            string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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