Add M365 Login plugin: Microsoft Entra ID sign-in for existing users
Adds a WordPress plugin that places a customisable "Sign in with Microsoft" button on wp-login.php and signs existing users in via the OpenID Connect authorization code flow with PKCE. Users are matched by e-mail address only; no accounts are created. Security: single-use state/nonce bound to an HttpOnly cookie, ID token signature verification against Microsoft's JWKS (RS256 only) with issuer/audience/tenant/expiry/nonce checks, optional tenant pinning, account binding to the Microsoft object ID, e-mail domain allow-list, client secret encrypted at rest (AES-256-GCM). Admin: settings screen with connection, button and security tabs, live button preview, colour presets, media-library icon picker, redirect URI copy button and tenant connectivity test. Packaging for WordPress.org: readme.txt with External services section, GPL-2.0 license, uninstall.php, POT + German translations, .distignore, build script, PHPCS config and CI running Plugin Check. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JJxAHYdMfKPoN4koRc4Ci2
This commit is contained in:
commit
3e3e87b399
35 changed files with 5413 additions and 0 deletions
578
assets/css/admin.css
Normal file
578
assets/css/admin.css
Normal file
|
|
@ -0,0 +1,578 @@
|
|||
/* M365 Login – settings screen */
|
||||
.m365-admin {
|
||||
--m365-accent: #0078d4;
|
||||
--m365-accent-dark: #106ebe;
|
||||
--m365-border: #dcdcde;
|
||||
--m365-muted: #646970;
|
||||
--m365-radius: 10px;
|
||||
max-width: 1180px;
|
||||
}
|
||||
|
||||
.m365-admin h1 {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
line-height: 1.2;
|
||||
margin: 0 0 4px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.m365-admin__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
margin: 12px 0 20px;
|
||||
}
|
||||
|
||||
.m365-admin__brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.m365-admin__brand p {
|
||||
margin: 0;
|
||||
color: var(--m365-muted);
|
||||
}
|
||||
|
||||
.m365-admin__logo {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
background: #fff;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.m365-admin__logo svg {
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
}
|
||||
|
||||
.m365-admin__status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 12px;
|
||||
border-radius: 999px;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
background: #fcf0e4;
|
||||
color: #8a4b00;
|
||||
}
|
||||
|
||||
.m365-admin__status.is-ok {
|
||||
background: #e6f4ea;
|
||||
color: #1e6b31;
|
||||
}
|
||||
|
||||
.m365-admin__status-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: currentColor;
|
||||
}
|
||||
|
||||
/* Tabs */
|
||||
.m365-admin__tabs {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
border-bottom: 1px solid var(--m365-border);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.m365-admin__tab {
|
||||
appearance: none;
|
||||
background: none;
|
||||
border: 0;
|
||||
border-bottom: 2px solid transparent;
|
||||
margin-bottom: -1px;
|
||||
padding: 10px 14px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--m365-muted);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.m365-admin__tab:hover {
|
||||
color: #1d2327;
|
||||
}
|
||||
|
||||
.m365-admin__tab.is-active {
|
||||
color: var(--m365-accent);
|
||||
border-bottom-color: var(--m365-accent);
|
||||
}
|
||||
|
||||
.m365-admin__tab:focus-visible {
|
||||
outline: 2px solid var(--m365-accent);
|
||||
outline-offset: -2px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.m365-admin__panel {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.m365-admin__panel.is-active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Layout */
|
||||
.m365-admin__layout {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 340px;
|
||||
gap: 20px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.m365-admin__layout {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.m365-admin__actions {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
/* Cards */
|
||||
.m365-card {
|
||||
background: #fff;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: var(--m365-radius);
|
||||
padding: 24px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
|
||||
}
|
||||
|
||||
.m365-card--accent {
|
||||
border-color: #b6d7f2;
|
||||
background: linear-gradient(180deg, #f3f9fe 0%, #fff 100%);
|
||||
}
|
||||
|
||||
.m365-card--muted {
|
||||
background: #f6f7f7;
|
||||
}
|
||||
|
||||
.m365-card__title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 6px;
|
||||
}
|
||||
|
||||
.m365-card__intro {
|
||||
margin: 0 0 20px;
|
||||
color: var(--m365-muted);
|
||||
}
|
||||
|
||||
/* Fields */
|
||||
.m365-field {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.m365-field:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.m365-field > label,
|
||||
.m365-field__label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.m365-field input[type="text"],
|
||||
.m365-field input[type="url"],
|
||||
.m365-field input[type="password"],
|
||||
.m365-field select,
|
||||
.m365-field textarea {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
border-radius: 6px;
|
||||
min-height: 36px;
|
||||
}
|
||||
|
||||
.m365-field .regular-text {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.m365-field__row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.m365-field__row > input {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
.m365-field__row .button {
|
||||
flex: 0 0 auto;
|
||||
min-height: 36px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.m365-field .description {
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.m365-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0 20px;
|
||||
}
|
||||
|
||||
.m365-grid--4 {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
@media (max-width: 782px) {
|
||||
.m365-grid,
|
||||
.m365-grid--4 {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.m365-check {
|
||||
display: inline-flex;
|
||||
gap: 8px;
|
||||
align-items: flex-start;
|
||||
margin: 8px 0 0;
|
||||
}
|
||||
|
||||
.m365-check--block {
|
||||
display: flex;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: 8px;
|
||||
margin: 0 0 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.m365-check--block:hover {
|
||||
border-color: #b6d7f2;
|
||||
background: #fbfdff;
|
||||
}
|
||||
|
||||
.m365-check--block input {
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
.m365-check--block strong {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.m365-check--block em {
|
||||
display: block;
|
||||
font-style: normal;
|
||||
color: var(--m365-muted);
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.m365-inline-result {
|
||||
margin-top: 10px;
|
||||
padding: 10px 12px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
background: #f0f6fc;
|
||||
border: 1px solid #c5d9ed;
|
||||
}
|
||||
|
||||
.m365-inline-result.is-success {
|
||||
background: #e6f4ea;
|
||||
border-color: #a6d8b2;
|
||||
}
|
||||
|
||||
.m365-inline-result.is-error {
|
||||
background: #fcf0f1;
|
||||
border-color: #f0b8bd;
|
||||
}
|
||||
|
||||
.m365-inline-result code {
|
||||
display: block;
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.m365-warning {
|
||||
margin: 12px 0 0;
|
||||
padding: 10px 12px;
|
||||
border-radius: 6px;
|
||||
background: #fcf0e4;
|
||||
color: #8a4b00;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.m365-toggle-secret .dashicons {
|
||||
line-height: 1;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.m365-link-danger {
|
||||
color: #b32d2e;
|
||||
}
|
||||
|
||||
/* Preview */
|
||||
.m365-preview {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.m365-preview__label {
|
||||
display: block;
|
||||
font-size: 11px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--m365-muted);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.m365-preview__stage {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 32px 24px;
|
||||
background: #f0f0f1 radial-gradient(circle at 1px 1px, #dcdcde 1px, transparent 0);
|
||||
background-size: 16px 16px;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.m365-login--preview {
|
||||
width: 272px;
|
||||
background: #fff;
|
||||
border: 1px solid #c3c4c7;
|
||||
padding: 24px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
|
||||
--m365-bg: #2f2f2f;
|
||||
--m365-bg-hover: #1a1a1a;
|
||||
--m365-color: #fff;
|
||||
--m365-border: #2f2f2f;
|
||||
--m365-radius: 4px;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__divider {
|
||||
position: relative;
|
||||
text-align: center;
|
||||
margin: 0 0 22px;
|
||||
color: #646970;
|
||||
font-size: 13px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__divider::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 50%;
|
||||
height: 1px;
|
||||
background: #dcdcde;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__divider span {
|
||||
position: relative;
|
||||
background: #fff;
|
||||
padding: 0 12px;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__divider.is-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 44px;
|
||||
padding: 10px 16px;
|
||||
background: var(--m365-bg);
|
||||
color: var(--m365-color);
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: var(--m365-radius);
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
line-height: 1.3;
|
||||
text-decoration: none;
|
||||
transition: background-color 0.15s ease;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__button:hover {
|
||||
background: var(--m365-bg-hover);
|
||||
color: var(--m365-color);
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__button:focus {
|
||||
box-shadow: none;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__icon,
|
||||
.m365-login--preview #m365-preview-icon img,
|
||||
.m365-login--preview #m365-preview-icon svg {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
display: block;
|
||||
background: #fff;
|
||||
padding: 3px;
|
||||
box-sizing: content-box;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.m365-login--preview #m365-preview-icon.is-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__label {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* Icon picker */
|
||||
.m365-icon-picker {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
align-items: flex-start;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.m365-icon-picker__thumb {
|
||||
flex: 0 0 64px;
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #fff;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.m365-icon-picker__thumb img,
|
||||
.m365-icon-picker__thumb svg {
|
||||
max-width: 36px;
|
||||
max-height: 36px;
|
||||
}
|
||||
|
||||
.m365-icon-picker__controls {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
.m365-icon-picker__controls .m365-field__row {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
/* Colour pickers */
|
||||
.m365-field .wp-picker-container {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.m365-field .wp-picker-container .wp-color-result.button {
|
||||
margin: 0;
|
||||
min-height: 36px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.m365-range-value {
|
||||
font-weight: 400;
|
||||
color: var(--m365-muted);
|
||||
margin-left: 6px;
|
||||
}
|
||||
|
||||
.m365-field input[type="range"] {
|
||||
width: 100%;
|
||||
margin-top: 10px;
|
||||
accent-color: var(--m365-accent);
|
||||
}
|
||||
|
||||
/* Presets */
|
||||
.m365-presets {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.m365-presets .m365-field__label {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.m365-preset {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 12px 6px 8px;
|
||||
background: #fff;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.m365-preset:hover {
|
||||
border-color: var(--m365-accent);
|
||||
}
|
||||
|
||||
.m365-preset span {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
/* Sidebar */
|
||||
.m365-copy {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.m365-copy code {
|
||||
flex: 1 1 auto;
|
||||
padding: 8px 10px;
|
||||
font-size: 12px;
|
||||
background: #fff;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: 6px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.m365-copy__button {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.m365-steps {
|
||||
margin: 0;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.m365-steps li {
|
||||
margin-bottom: 8px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.m365-list {
|
||||
margin: 8px 0 0;
|
||||
padding-left: 18px;
|
||||
list-style: disc;
|
||||
}
|
||||
|
||||
.m365-list li {
|
||||
margin-bottom: 6px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.m365-card code {
|
||||
font-size: 12px;
|
||||
}
|
||||
122
assets/css/login.css
Normal file
122
assets/css/login.css
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/* M365 Login – login screen button */
|
||||
.m365-login {
|
||||
--m365-bg: #2f2f2f;
|
||||
--m365-bg-hover: #1a1a1a;
|
||||
--m365-color: #ffffff;
|
||||
--m365-border: #2f2f2f;
|
||||
--m365-radius: 4px;
|
||||
margin: 0 0 16px;
|
||||
}
|
||||
|
||||
.m365-login--below {
|
||||
background: #fff;
|
||||
padding: 0 24px 26px;
|
||||
margin: -1px 0 0;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
|
||||
border: 1px solid #c3c4c7;
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
body.m365-login-attached #loginform {
|
||||
border-bottom: 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.m365-login--above {
|
||||
background: #fff;
|
||||
padding: 24px;
|
||||
margin: 20px 0 0;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
|
||||
border: 1px solid #c3c4c7;
|
||||
}
|
||||
|
||||
.m365-login--above .m365-login__divider {
|
||||
margin: 22px 0 0;
|
||||
}
|
||||
|
||||
.m365-login__divider {
|
||||
position: relative;
|
||||
text-align: center;
|
||||
margin: 0 0 22px;
|
||||
color: #646970;
|
||||
font-size: 13px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.m365-login__divider::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 50%;
|
||||
height: 1px;
|
||||
background: #dcdcde;
|
||||
}
|
||||
|
||||
.m365-login__divider span {
|
||||
position: relative;
|
||||
background: #fff;
|
||||
padding: 0 12px;
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
.m365-login__button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 44px;
|
||||
padding: 10px 16px;
|
||||
background: var(--m365-bg);
|
||||
color: var(--m365-color);
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: var(--m365-radius);
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
line-height: 1.3;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
|
||||
}
|
||||
|
||||
.m365-login__button:hover,
|
||||
.m365-login__button:focus {
|
||||
background: var(--m365-bg-hover);
|
||||
color: var(--m365-color);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.m365-login__button:focus {
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--m365-bg-hover);
|
||||
}
|
||||
|
||||
.m365-login__button:active {
|
||||
transform: translateY(1px);
|
||||
}
|
||||
|
||||
.m365-login__icon {
|
||||
flex: 0 0 auto;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
display: block;
|
||||
background: #fff;
|
||||
padding: 3px;
|
||||
box-sizing: content-box;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.m365-login__label {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.m365-login--shortcode {
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
max-width: 360px;
|
||||
}
|
||||
189
assets/js/admin.js
Normal file
189
assets/js/admin.js
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
/* global jQuery, wp, m365LoginAdmin */
|
||||
( function ( $ ) {
|
||||
'use strict';
|
||||
|
||||
var cfg = window.m365LoginAdmin || {};
|
||||
var i18n = cfg.i18n || {};
|
||||
|
||||
$( function () {
|
||||
var $preview = $( '#m365-preview' );
|
||||
|
||||
/* ---------------- Tabs ---------------- */
|
||||
var $tabs = $( '.m365-admin__tab' );
|
||||
var $panels = $( '.m365-admin__panel' );
|
||||
|
||||
function activate( name ) {
|
||||
$tabs.removeClass( 'is-active' ).attr( 'aria-selected', 'false' ).filter( '[data-tab="' + name + '"]' ).addClass( 'is-active' ).attr( 'aria-selected', 'true' );
|
||||
$panels.removeClass( 'is-active' ).filter( '[data-panel="' + name + '"]' ).addClass( 'is-active' );
|
||||
try {
|
||||
window.localStorage.setItem( 'm365LoginTab', name );
|
||||
} catch ( e ) {}
|
||||
}
|
||||
|
||||
$tabs.on( 'click', function () {
|
||||
activate( $( this ).data( 'tab' ) );
|
||||
} );
|
||||
|
||||
try {
|
||||
var saved = window.localStorage.getItem( 'm365LoginTab' );
|
||||
if ( saved && $tabs.filter( '[data-tab="' + saved + '"]' ).length ) {
|
||||
activate( saved );
|
||||
}
|
||||
} catch ( e ) {}
|
||||
|
||||
// Jump to the tab that contains a validation error.
|
||||
var $error = $( '.settings-error' ).first();
|
||||
if ( $error.length && $error.text().toLowerCase().indexOf( 'tenant' ) !== -1 ) {
|
||||
activate( 'connection' );
|
||||
}
|
||||
|
||||
/* ---------------- Live preview ---------------- */
|
||||
function setVar( name, value ) {
|
||||
$preview[ 0 ].style.setProperty( '--m365-' + name, value );
|
||||
}
|
||||
|
||||
function updateIcon() {
|
||||
var show = $( '[data-preview="show-icon"]' ).is( ':checked' );
|
||||
var url = $.trim( $( '#m365-icon-url' ).val() );
|
||||
var $icon = $( '#m365-preview-icon' );
|
||||
var $thumb = $( '#m365-icon-thumb' );
|
||||
|
||||
$icon.toggleClass( 'is-hidden', ! show );
|
||||
|
||||
if ( url ) {
|
||||
var $img = $( '<img>', { src: url, alt: '' } );
|
||||
$icon.empty().append( $img );
|
||||
$thumb.empty().append( $img.clone() );
|
||||
} else {
|
||||
$icon.html( cfg.defaultLogo || '' );
|
||||
$thumb.html( cfg.defaultLogo || '' );
|
||||
}
|
||||
}
|
||||
|
||||
$( '[data-preview="text"]' ).on( 'input', function () {
|
||||
$( '#m365-preview-text' ).text( $( this ).val() );
|
||||
} );
|
||||
|
||||
$( '[data-preview="divider"]' ).on( 'input', function () {
|
||||
var val = $.trim( $( this ).val() );
|
||||
$( '#m365-preview-divider' ).text( val ).closest( '.m365-login__divider' ).toggleClass( 'is-hidden', ! val );
|
||||
} ).trigger( 'input' );
|
||||
|
||||
$( '[data-preview="show-icon"], #m365-icon-url' ).on( 'change input', updateIcon );
|
||||
|
||||
$( '[data-preview="radius"]' ).on( 'input change', function () {
|
||||
setVar( 'radius', $( this ).val() + 'px' );
|
||||
$( '#m365-radius-value' ).text( $( this ).val() + ' px' );
|
||||
} );
|
||||
|
||||
$( '.m365-color' ).wpColorPicker( {
|
||||
change: function ( event, ui ) {
|
||||
var key = $( event.target ).data( 'preview' );
|
||||
var color = ui.color.toString();
|
||||
setVar( key.replace( '_', '-' ), color );
|
||||
},
|
||||
clear: function ( event ) {
|
||||
var $input = $( event.target ).closest( '.wp-picker-container' ).find( '.m365-color' );
|
||||
setVar( $input.data( 'preview' ).replace( '_', '-' ), $input.data( 'default-color' ) );
|
||||
}
|
||||
} );
|
||||
|
||||
$( '.m365-preset' ).on( 'click', function () {
|
||||
var preset = $( this ).data( 'preset' );
|
||||
if ( ! preset ) {
|
||||
return;
|
||||
}
|
||||
$.each( preset, function ( key, value ) {
|
||||
$( '#m365-button_' + key ).wpColorPicker( 'color', value );
|
||||
} );
|
||||
} );
|
||||
|
||||
/* ---------------- Media library ---------------- */
|
||||
var frame;
|
||||
$( '#m365-icon-choose' ).on( 'click', function ( e ) {
|
||||
e.preventDefault();
|
||||
if ( ! window.wp || ! wp.media ) {
|
||||
return;
|
||||
}
|
||||
if ( ! frame ) {
|
||||
frame = wp.media( {
|
||||
title: i18n.chooseIcon || '',
|
||||
button: { text: i18n.useIcon || '' },
|
||||
library: { type: 'image' },
|
||||
multiple: false
|
||||
} );
|
||||
frame.on( 'select', function () {
|
||||
var attachment = frame.state().get( 'selection' ).first().toJSON();
|
||||
var url = attachment.url;
|
||||
if ( attachment.sizes && attachment.sizes.thumbnail && attachment.mime !== 'image/svg+xml' ) {
|
||||
url = attachment.sizes.thumbnail.url;
|
||||
}
|
||||
$( '#m365-icon-url' ).val( url ).trigger( 'input' );
|
||||
} );
|
||||
}
|
||||
frame.open();
|
||||
} );
|
||||
|
||||
$( '#m365-icon-reset' ).on( 'click', function ( e ) {
|
||||
e.preventDefault();
|
||||
$( '#m365-icon-url' ).val( '' ).trigger( 'input' );
|
||||
} );
|
||||
|
||||
/* ---------------- Secret visibility ---------------- */
|
||||
$( '.m365-toggle-secret' ).on( 'click', function () {
|
||||
var $input = $( '#m365-client-secret' );
|
||||
var show = 'password' === $input.attr( 'type' );
|
||||
$input.attr( 'type', show ? 'text' : 'password' );
|
||||
$( this ).find( '.dashicons' ).toggleClass( 'dashicons-visibility', ! show ).toggleClass( 'dashicons-hidden', show );
|
||||
} );
|
||||
|
||||
/* ---------------- Copy redirect URI ---------------- */
|
||||
$( '.m365-copy__button' ).on( 'click', function () {
|
||||
var $btn = $( this );
|
||||
var text = $( '#' + $btn.data( 'copy' ) ).text();
|
||||
var done = function () {
|
||||
$btn.text( i18n.copied || 'Copied!' );
|
||||
window.setTimeout( function () {
|
||||
$btn.text( i18n.copy || 'Copy' );
|
||||
}, 1500 );
|
||||
};
|
||||
if ( navigator.clipboard && navigator.clipboard.writeText ) {
|
||||
navigator.clipboard.writeText( text ).then( done );
|
||||
} else {
|
||||
var $tmp = $( '<textarea>' ).val( text ).appendTo( 'body' ).select();
|
||||
try {
|
||||
document.execCommand( 'copy' );
|
||||
} catch ( e ) {}
|
||||
$tmp.remove();
|
||||
done();
|
||||
}
|
||||
} );
|
||||
|
||||
/* ---------------- Test tenant ---------------- */
|
||||
$( '#m365-test' ).on( 'click', function () {
|
||||
var $btn = $( this );
|
||||
var $out = $( '#m365-test-result' );
|
||||
var label = $btn.text();
|
||||
|
||||
$btn.prop( 'disabled', true ).text( i18n.testing || '…' );
|
||||
$out.removeClass( 'is-success is-error' ).prop( 'hidden', true ).empty();
|
||||
|
||||
$.post( cfg.ajaxUrl, {
|
||||
action: cfg.action,
|
||||
nonce: cfg.nonce,
|
||||
tenant: $( '#m365-tenant' ).val()
|
||||
} ).done( function ( res ) {
|
||||
if ( res && res.success ) {
|
||||
$out.addClass( 'is-success' ).text( res.data.message ).append( $( '<code>' ).text( res.data.issuer ) );
|
||||
} else {
|
||||
$out.addClass( 'is-error' ).text( ( res && res.data && res.data.message ) || i18n.testFailed || '' );
|
||||
}
|
||||
} ).fail( function () {
|
||||
$out.addClass( 'is-error' ).text( i18n.testFailed || '' );
|
||||
} ).always( function () {
|
||||
$btn.prop( 'disabled', false ).text( label );
|
||||
$out.prop( 'hidden', false );
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
}( jQuery ) );
|
||||
20
assets/js/login.js
Normal file
20
assets/js/login.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* M365 Login – moves the button block directly below the login form. */
|
||||
( function () {
|
||||
'use strict';
|
||||
|
||||
function place() {
|
||||
var block = document.getElementById( 'm365-login-block' );
|
||||
var form = document.getElementById( 'loginform' );
|
||||
if ( ! block || ! form || ! form.parentNode ) {
|
||||
return;
|
||||
}
|
||||
form.parentNode.insertBefore( block, form.nextSibling );
|
||||
document.body.classList.add( 'm365-login-attached' );
|
||||
}
|
||||
|
||||
if ( 'loading' === document.readyState ) {
|
||||
document.addEventListener( 'DOMContentLoaded', place );
|
||||
} else {
|
||||
place();
|
||||
}
|
||||
}() );
|
||||
Loading…
Add table
Add a link
Reference in a new issue