login

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 35 Imported by: 10

Documentation

Index

Constants

View Source
const (
	I18nAdminLoginKey i18n.ModuleKey = "I18nAdminLoginKey"
)
View Source
const (
	LoginTokenHashLen = 8 // The hash string length of the token stored in the DB.
)
View Source
const (
	OpenChangePasswordDialogEvent = "login_openChangePasswordDialog"
)

Variables

View Source
var DefaultViewCommon = &ViewCommon{
	WrapperClass: "d-flex pt-16 flex-column mx-auto",
	WrapperStyle: "max-width: 28rem;",
	TitleClass:   "text-h5 mb-6 font-weight-bold",
	LabelClass:   "d-block mb-1 grey--text text--darken-2 text-sm-body-2",
}
View Source
var Messages_en_US = &Messages{
	SessionTableHeaderTime:           "Time",
	SessionTableHeaderDevice:         "Device",
	SessionTableHeaderIPAddress:      "IP Address",
	SessionTableHeaderStatus:         "Status",
	SessionsDialogTitle:              "Login Sessions",
	SessionStatusExpired:             "Expired",
	SessionStatusActive:              "Active",
	SessionStatusCurrent:             "Current Session",
	HideIPAddressTips:                "Invisible due to security concerns",
	ExpireOtherSessions:              "Sign out all other sessions",
	SuccessfullyExpiredOtherSessions: "All other sessions have successfully been signed out.",
	UnreadMessagesTemplate:           "{n} unread notes",
	ViewLoginSessions:                "View login sessions",
	Logout:                           "Logout",
	Available:                        "Available",
	Unavailable:                      "Unavailable",
	SuccessfullyRename:               "Successfully renamed",

	LoginWelcomeLabel: "Welcome",
	LoginTitleLabel:   "Qor Admin System",

	LoginAccountLabel:         "Email",
	LoginAccountPlaceholder:   "Please enter your email",
	LoginPasswordLabel:        "Password",
	LoginPasswordPlaceholder:  "Please enter your password",
	LoginSignInButtonLabel:    "Sign in",
	LoginForgetPasswordLabel:  "Forget your password?",
	LoginQor5DescriptionLabel: "Enterprise Systems, Startup Speed",

	LoginProviderGoogleText:    "Sign in with Google",
	LoginProviderMicrosoftText: "Sign in with Microsoft",
	LoginProviderGithubText:    "Sign in with Github",
}
View Source
var Messages_ja_JP = &Messages{
	SessionTableHeaderTime:           "時間",
	SessionTableHeaderDevice:         "デバイス",
	SessionTableHeaderIPAddress:      "IPアドレス",
	SessionTableHeaderStatus:         "ステータス",
	SessionsDialogTitle:              "ログインセッション",
	SessionStatusExpired:             "期限切れ",
	SessionStatusActive:              "有効",
	SessionStatusCurrent:             "現在のセッション",
	HideIPAddressTips:                "セキュリティ保護のため表示できません",
	ExpireOtherSessions:              "他のすべてのセッションからサインアウトする",
	SuccessfullyExpiredOtherSessions: "他のすべてのセッションは正常にサインアウトされました。",
	UnreadMessagesTemplate:           "{n} 件の未読",
	ViewLoginSessions:                "ログインセッションを表示",
	Logout:                           "ログアウト",
	Available:                        "利用可能",
	Unavailable:                      "利用不可",
	SuccessfullyRename:               "名前が変更されました",

	LoginWelcomeLabel: "ようこそ",
	LoginTitleLabel:   "Qor 管理システム",

	LoginAccountLabel:         "メールアドレス",
	LoginAccountPlaceholder:   "メールアドレスを入力してください",
	LoginPasswordLabel:        "パスワード",
	LoginPasswordPlaceholder:  "パスワードを入力してください",
	LoginSignInButtonLabel:    "サインイン",
	LoginForgetPasswordLabel:  "パスワードをお忘れですか?",
	LoginQor5DescriptionLabel: "エンタープライズシステム、スタートアップスピード",

	LoginProviderGoogleText:    "Google でログイン",
	LoginProviderMicrosoftText: "Microsoft でログイン",
	LoginProviderGithubText:    "Github でログイン",
}
View Source
var Messages_zh_CN = &Messages{
	SessionTableHeaderTime:           "时间",
	SessionTableHeaderDevice:         "设备",
	SessionTableHeaderIPAddress:      "IP地址",
	SessionTableHeaderStatus:         "状态",
	SessionsDialogTitle:              "登录会话",
	SessionStatusExpired:             "已过期",
	SessionStatusActive:              "有效",
	SessionStatusCurrent:             "当前会话",
	HideIPAddressTips:                "由于安全原因,隐藏",
	ExpireOtherSessions:              "登出所有其他会话",
	SuccessfullyExpiredOtherSessions: "所有其他会话已成功登出。",
	UnreadMessagesTemplate:           "未读 {n} 条",
	ViewLoginSessions:                "查看登录会话",
	Logout:                           "登出",
	Available:                        "可用",
	Unavailable:                      "不可用",
	SuccessfullyRename:               "成功重命名",

	LoginWelcomeLabel: "欢迎",
	LoginTitleLabel:   "Qor 管理系统",

	LoginAccountLabel:         "邮箱",
	LoginAccountPlaceholder:   "请输入您的邮箱",
	LoginPasswordLabel:        "密码",
	LoginPasswordPlaceholder:  "请输入您的密码",
	LoginSignInButtonLabel:    "登录",
	LoginForgetPasswordLabel:  "忘记密码?",
	LoginQor5DescriptionLabel: "企业级系统,创业速度",

	LoginProviderGoogleText:    "使用 Google 登录",
	LoginProviderMicrosoftText: "使用 Microsoft 登录",
	LoginProviderGithubText:    "使用 Github 登录",
}
View Source
var NopCustomizeCompoFunc = func(ctx context.Context, profileCompo *ProfileCompo, current h.HTMLComponent) (h.HTMLComponent, error) {
	return current, nil
}

Functions

func AutoMigrateSession added in v3.0.3

func AutoMigrateSession(db *gorm.DB, tablePrefix string) error

func New

func New(pb *presets.Builder) *login.Builder

func NewAdvancedLoginPage added in v3.2.0

func NewAdvancedLoginPage(customize func(ctx *web.EventContext, config *AdvancedLoginPageConfig) (*AdvancedLoginPageConfig, error)) func(vh *login.ViewHelper, pb *presets.Builder) web.PageFunc

Types

type AdvancedLoginPageConfig added in v3.2.0

type AdvancedLoginPageConfig struct {
	WelcomeLabel         string
	TitleLabel           string
	AccountLabel         string
	AccountPlaceholder   string
	PasswordLabel        string
	PasswordPlaceholder  string
	SignInButtonLabel    string
	ForgetPasswordLabel  string
	OAuthProviderDisplay func(provider *login.Provider) OAuthProviderDisplay
	LeftImage            HTMLComponent
	Qor5DescriptionLabel string
	RightMaxWidth        string
	PageTitle            string
}

type CustomizeCompoFunc added in v3.0.4

type CustomizeCompoFunc func(ctx context.Context, profileCompo *ProfileCompo, current h.HTMLComponent) (h.HTMLComponent, error)

type LoginSession added in v3.0.3

type LoginSession struct {
	gorm.Model

	UserID    string    `gorm:"index;not null"`
	Device    string    `gorm:"not null"`
	IP        string    `gorm:"not null"`
	TokenHash string    `gorm:"index;not null"`
	ExpiredAt time.Time `gorm:"not null"`
}

type Messages added in v3.0.3

type Messages struct {
	SessionTableHeaderTime           string
	SessionTableHeaderDevice         string
	SessionTableHeaderIPAddress      string
	SessionTableHeaderStatus         string
	SessionsDialogTitle              string
	SessionStatusExpired             string
	SessionStatusActive              string
	SessionStatusCurrent             string
	HideIPAddressTips                string
	ExpireOtherSessions              string
	SuccessfullyExpiredOtherSessions string
	UnreadMessagesTemplate           string
	ViewLoginSessions                string
	Logout                           string
	Available                        string
	Unavailable                      string
	SuccessfullyRename               string

	LoginWelcomeLabel string
	LoginTitleLabel   string

	LoginAccountLabel         string
	LoginAccountPlaceholder   string
	LoginPasswordLabel        string
	LoginPasswordPlaceholder  string
	LoginSignInButtonLabel    string
	LoginForgetPasswordLabel  string
	LoginQor5DescriptionLabel string

	LoginProviderGoogleText    string
	LoginProviderMicrosoftText string
	LoginProviderGithubText    string
}

func (*Messages) UnreadMessages added in v3.0.3

func (m *Messages) UnreadMessages(n int) string

type OAuthProviderDisplay added in v3.2.0

type OAuthProviderDisplay struct {
	Text string
}

type Profile added in v3.0.3

type Profile struct {
	ID          string
	Name        string
	Avatar      string
	Roles       []string
	Status      string
	Fields      []*ProfileField
	NotifCounts []*activity.NoteCount
}

func (*Profile) GetFirstRole added in v3.0.3

func (u *Profile) GetFirstRole() string

type ProfileBuilder added in v3.0.3

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

func NewProfileBuilder added in v3.0.3

func NewProfileBuilder(
	currentProfileFunc func(ctx context.Context) (*Profile, error),
	renameCallback RenameCallback,
) *ProfileBuilder

func (*ProfileBuilder) CustomizeButtons added in v3.0.3

func (b *ProfileBuilder) CustomizeButtons(v func(ctx context.Context, buttons ...h.HTMLComponent) ([]h.HTMLComponent, error)) *ProfileBuilder

func (*ProfileBuilder) DisableNotification added in v3.0.3

func (b *ProfileBuilder) DisableNotification(v bool) *ProfileBuilder

func (*ProfileBuilder) Install added in v3.0.3

func (b *ProfileBuilder) Install(pb *presets.Builder) error

func (*ProfileBuilder) LogoutURL added in v3.0.3

func (b *ProfileBuilder) LogoutURL(s string) *ProfileBuilder

func (*ProfileBuilder) NewCompo added in v3.0.3

func (b *ProfileBuilder) NewCompo(evCtx *web.EventContext, idSuffix string) h.HTMLComponent

func (*ProfileBuilder) PrependCompos added in v3.0.3

func (b *ProfileBuilder) PrependCompos(f func(ctx context.Context, profileCompo *ProfileCompo) ([]h.HTMLComponent, error)) *ProfileBuilder

func (*ProfileBuilder) SessionBuilder added in v3.0.3

func (b *ProfileBuilder) SessionBuilder(lsb *SessionBuilder) *ProfileBuilder

func (*ProfileBuilder) WrapPrependCompo added in v3.0.4

func (b *ProfileBuilder) WrapPrependCompo(w func(in CustomizeCompoFunc) CustomizeCompoFunc) *ProfileBuilder

func (*ProfileBuilder) WrapRenameCallback added in v3.0.4

func (b *ProfileBuilder) WrapRenameCallback(w func(in RenameCallback) RenameCallback) *ProfileBuilder

func (*ProfileBuilder) WrapSubtitleCompo added in v3.0.4

func (b *ProfileBuilder) WrapSubtitleCompo(w func(in CustomizeCompoFunc) CustomizeCompoFunc) *ProfileBuilder

type ProfileCompo added in v3.0.3

type ProfileCompo struct {
	ID string `json:"id"`
	// contains filtered or unexported fields
}

func ProfileCompoFromContext added in v3.0.3

func ProfileCompoFromContext(ctx context.Context) *ProfileCompo

func ProfileCompoFromEventContext added in v3.0.3

func ProfileCompoFromEventContext(evCtx *web.EventContext) *ProfileCompo

func (*ProfileCompo) CompoID added in v3.0.3

func (c *ProfileCompo) CompoID() string

func (*ProfileCompo) MarshalHTML added in v3.0.3

func (c *ProfileCompo) MarshalHTML(ctx context.Context) ([]byte, error)

func (*ProfileCompo) MustGetEventContext added in v3.0.3

func (c *ProfileCompo) MustGetEventContext(ctx context.Context) (*web.EventContext, *Messages)

func (*ProfileCompo) Rename added in v3.0.3

func (c *ProfileCompo) Rename(ctx context.Context, req RenameRequest) (r web.EventResponse, _ error)

type ProfileField added in v3.0.3

type ProfileField struct {
	Name  string
	Value string
}

type RenameCallback added in v3.0.4

type RenameCallback func(ctx context.Context, newName string) error

type RenameRequest added in v3.0.3

type RenameRequest struct {
	Name string `json:"name"`
}

type SessionBuilder added in v3.0.3

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

func NewSessionBuilder added in v3.0.3

func NewSessionBuilder(lb *login.Builder, db *gorm.DB) *SessionBuilder

func (*SessionBuilder) Activity added in v3.0.3

func (*SessionBuilder) AutoMigrate added in v3.0.3

func (b *SessionBuilder) AutoMigrate() (r *SessionBuilder)

func (*SessionBuilder) CreateSession added in v3.0.3

func (b *SessionBuilder) CreateSession(r *http.Request, uid string) error

func (*SessionBuilder) ExpireAllSessions added in v3.0.3

func (b *SessionBuilder) ExpireAllSessions(uid string) error

func (*SessionBuilder) ExpireCurrentSession added in v3.0.3

func (b *SessionBuilder) ExpireCurrentSession(r *http.Request, uid string) error

func (*SessionBuilder) ExpireOtherSessions added in v3.0.3

func (b *SessionBuilder) ExpireOtherSessions(r *http.Request, uid string) error

func (*SessionBuilder) ExtendSession added in v3.0.3

func (b *SessionBuilder) ExtendSession(r *http.Request, uid string, oldToken string) error

func (*SessionBuilder) GetLoginBuilder added in v3.0.3

func (b *SessionBuilder) GetLoginBuilder() *login.Builder

func (*SessionBuilder) Install added in v3.0.3

func (b *SessionBuilder) Install(pb *presets.Builder) error

func (*SessionBuilder) IsPublicUser added in v3.0.3

func (b *SessionBuilder) IsPublicUser(f func(user any) bool) *SessionBuilder

func (*SessionBuilder) IsSessionValid added in v3.0.3

func (b *SessionBuilder) IsSessionValid(r *http.Request, uid string) (valid bool, err error)

func (*SessionBuilder) Middleware added in v3.0.3

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

func (*SessionBuilder) Mount added in v3.0.3

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

func (*SessionBuilder) MountAPI added in v3.0.3

func (b *SessionBuilder) MountAPI(mux *http.ServeMux)

func (*SessionBuilder) OpenSessionsDialog added in v3.0.3

func (b *SessionBuilder) OpenSessionsDialog() string

func (*SessionBuilder) Secret added in v3.0.3

func (b *SessionBuilder) Secret(v string) *SessionBuilder

func (*SessionBuilder) TablePrefix added in v3.0.3

func (b *SessionBuilder) TablePrefix(prefix string) *SessionBuilder

type ViewCommon

type ViewCommon struct {
	WrapperClass string
	WrapperStyle string
	TitleClass   string
	LabelClass   string
}

func (*ViewCommon) ErrNotice

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

func (*ViewCommon) ErrorBody

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

func (*ViewCommon) FormSubmitBtn

func (vc *ViewCommon) FormSubmitBtn(
	label string,
) *VBtnBuilder

func (*ViewCommon) InfoNotice

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

func (*ViewCommon) InjectRecaptchaAssets

func (vc *ViewCommon) InjectRecaptchaAssets(ctx *web.EventContext, formID string, tokenFieldID string)

requirements: - submit button

  • add class `g-recaptcha`
  • add attr `data-sitekey=<key>`
  • add attr `data-callback=onSubmit`

- add token field like `Input("token").Id("token").Type("hidden")`

func (*ViewCommon) InjectZxcvbn

func (vc *ViewCommon) InjectZxcvbn(ctx *web.EventContext)

func (*ViewCommon) Input

func (vc *ViewCommon) Input(
	id string,
	placeholder string,
	val string,
) *vx.VXFieldBuilder

func (*ViewCommon) Notice

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

func (*ViewCommon) PasswordInput

func (vc *ViewCommon) PasswordInput(
	id string,
	placeholder string,
	val string,
	canReveal bool,
) *vx.VXFieldBuilder

func (*ViewCommon) PasswordInputWithStrengthMeter

func (vc *ViewCommon) PasswordInputWithStrengthMeter(in *vx.VXFieldBuilder, id string, val string) HTMLComponent

need to import zxcvbn.js

func (*ViewCommon) WarnNotice

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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