mirror of
https://github.com/knadh/listmonk.git
synced 2024-11-13 02:55:04 +08:00
Style and add OIDC logo to the login page.
This commit is contained in:
parent
7bb14de42e
commit
2000e9fa12
9 changed files with 65 additions and 15 deletions
49
cmd/auth.go
49
cmd/auth.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -15,11 +16,19 @@ type loginTpl struct {
|
|||
Title string
|
||||
Description string
|
||||
|
||||
NextURI string
|
||||
Nonce string
|
||||
PasswordEnabled bool
|
||||
OIDCEnabled bool
|
||||
Error string
|
||||
NextURI string
|
||||
Nonce string
|
||||
PasswordEnabled bool
|
||||
OIDCProvider string
|
||||
OIDCProviderLogo string
|
||||
Error string
|
||||
}
|
||||
|
||||
var oidcProviders = map[string]bool{
|
||||
"google.com": true,
|
||||
"microsoftonline.com": true,
|
||||
"auth0.com": true,
|
||||
"github.com": true,
|
||||
}
|
||||
|
||||
// handleLoginPage renders the login page and handles the login form.
|
||||
|
@ -33,11 +42,33 @@ func handleLoginPage(c echo.Context) error {
|
|||
next = uriAdmin
|
||||
}
|
||||
|
||||
oidcProvider := ""
|
||||
oidcProviderLogo := ""
|
||||
if app.constants.Security.OIDC.Enabled {
|
||||
oidcProviderLogo = "oidc.png"
|
||||
u, err := url.Parse(app.constants.Security.OIDC.Provider)
|
||||
if err == nil {
|
||||
h := strings.Split(u.Hostname(), ".")
|
||||
|
||||
// Get the last two h for the root domain
|
||||
if len(h) >= 2 {
|
||||
oidcProvider = h[len(h)-2] + "." + h[len(h)-1]
|
||||
} else {
|
||||
oidcProvider = u.Hostname()
|
||||
}
|
||||
|
||||
if _, ok := oidcProviders[oidcProvider]; ok {
|
||||
oidcProviderLogo = oidcProvider + ".png"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out := loginTpl{
|
||||
Title: app.i18n.T("users.login"),
|
||||
PasswordEnabled: true,
|
||||
OIDCEnabled: true,
|
||||
NextURI: next,
|
||||
Title: app.i18n.T("users.login"),
|
||||
PasswordEnabled: true,
|
||||
OIDCProvider: oidcProvider,
|
||||
OIDCProviderLogo: oidcProviderLogo,
|
||||
NextURI: next,
|
||||
}
|
||||
|
||||
// Login request.
|
||||
|
|
|
@ -596,7 +596,7 @@
|
|||
"templates.rawHTML": "Raw HTML",
|
||||
"templates.subject": "Subject",
|
||||
"users.login": "Login",
|
||||
"users.loginOIDC": "Login with OIDC",
|
||||
"users.loginOIDC": "Login with {name}",
|
||||
"users.logout": "Logout",
|
||||
"users.profile": "Profile",
|
||||
"users.lastLogin": "Last login",
|
||||
|
|
BIN
static/public/static/auth/auth0.com.png
Normal file
BIN
static/public/static/auth/auth0.com.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
BIN
static/public/static/auth/github.com.png
Normal file
BIN
static/public/static/auth/github.com.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
static/public/static/auth/google.com.png
Normal file
BIN
static/public/static/auth/google.com.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
static/public/static/auth/microsoftonline.com.png
Normal file
BIN
static/public/static/auth/microsoftonline.com.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 199 B |
BIN
static/public/static/auth/oidc.png
Normal file
BIN
static/public/static/auth/oidc.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
|
@ -87,7 +87,8 @@ input[disabled] {
|
|||
color: #0055d4;
|
||||
}
|
||||
.button.button-outline:hover {
|
||||
background-color: #0055d4;
|
||||
border-color: #333;
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
|
@ -181,6 +182,21 @@ input[disabled] {
|
|||
font-weight: bold;
|
||||
}
|
||||
|
||||
.login .submit {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.login button {
|
||||
width: 100%;
|
||||
vertical-align: middle;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.login button img {
|
||||
max-width: 24px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
#btn-back {
|
||||
display: none;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{{ define "admin-login" }}
|
||||
{{ template "header" .}}
|
||||
|
||||
<section>
|
||||
<section class="login">
|
||||
<h2>{{ .L.T "users.login"}}</h2>
|
||||
{{ if .Data.PasswordEnabled }}
|
||||
<form method="post" action="" class="form">
|
||||
|
@ -19,16 +19,19 @@
|
|||
|
||||
{{ if .Data.Error }}<p><span class="error">{{ .Data.Error }}</span></p>{{ end }}
|
||||
|
||||
<p><button class="button" type="submit">{{ .L.T "users.login" }}</button></p>
|
||||
<p class="submit"><button class="button" type="submit">{{ .L.T "users.login" }}</button></p>
|
||||
</div>
|
||||
</form>
|
||||
{{ end }}
|
||||
|
||||
{{ if .Data.OIDCEnabled }}
|
||||
{{ if .Data.OIDCProvider }}
|
||||
<form method="post" action="/oidc/login">
|
||||
<div>
|
||||
<input type="hidden" name="nonce" value="{{ .Data.Nonce }}" />
|
||||
<p><button type="submit">{{ .L.T "users.loginOIDC" }}</button></p>
|
||||
<p><button class="button button-outline" type="submit">
|
||||
<img src="{{ .RootURL }}/public/static/auth/{{ .Data.OIDCProviderLogo }}" alt="" />
|
||||
{{ .L.Ts "users.loginOIDC" "name" .Data.OIDCProvider }}
|
||||
</button></p>
|
||||
</div>
|
||||
</form>
|
||||
{{ end }}
|
||||
|
|
Loading…
Reference in a new issue