diff --git a/certificatelogin.libraries.yml b/certificatelogin.libraries.yml new file mode 100644 index 0000000..a229aa4 --- /dev/null +++ b/certificatelogin.libraries.yml @@ -0,0 +1,4 @@ +certificatelogin: + css: + theme: + css/certificatelogin.css: {} diff --git a/certificatelogin.links.menu.yml b/certificatelogin.links.menu.yml index 89b6aca..d0ab441 100644 --- a/certificatelogin.links.menu.yml +++ b/certificatelogin.links.menu.yml @@ -4,4 +4,7 @@ certificatelogin.settings: description: 'Configure functionality for logging into the site with a certificate.' parent: user.admin_index weight: 99 - +certificatelogin.logout: + description: 'Log in with client certificate.' + menu_name: account + class: Drupal\certificatelogin\Plugin\Menu\LoginLogoutMenuLink diff --git a/certificatelogin.module b/certificatelogin.module index 930b8d1..f47a3ab 100644 --- a/certificatelogin.module +++ b/certificatelogin.module @@ -33,6 +33,9 @@ function certificatelogin_theme() { 'certificatelogin' => [ 'render element' => 'children', ], + 'certificatelogin_block' => [ + 'variables' => [ 'links' => NULL ] + ], ]; } diff --git a/css/certificatelogin.css b/css/certificatelogin.css new file mode 100644 index 0000000..a83258f --- /dev/null +++ b/css/certificatelogin.css @@ -0,0 +1,31 @@ +.certificatelogin-links span { + padding: 1em; + margin: 1em; +} + +.certificatelogin-links span a { + box-shadow:inset 0px 1px 0px 0px #97c4fe; + background:linear-gradient(to bottom, #3d94f6 5%, #1e62d0 100%); + background-color:#3d94f6; + border-radius:6px; + border:1px solid #337fed; + display:inline-block; + cursor:pointer; + color:#ffffff; + font-family:Arial; + font-size:15px; + font-weight:bold; + padding:6px 24px; + text-decoration:none; + text-shadow:0px 1px 0px #1570cd; +} + +.certificatelogin-links span a:hover { + background:linear-gradient(to bottom, #1e62d0 5%, #3d94f6 100%); + background-color:#1e62d0; +} + +.certificatelogin-links span a:active { + position:relative; + top:1px; +} diff --git a/src/Plugin/Block/CertificateLoginBlock.php b/src/Plugin/Block/CertificateLoginBlock.php new file mode 100644 index 0000000..a707cfa --- /dev/null +++ b/src/Plugin/Block/CertificateLoginBlock.php @@ -0,0 +1,46 @@ + ['class' => ['certificatelogin-link']]); + $links = array( + 'useridlogin' => Link::fromTextAndUrl(t('Login with UserID'), Url::fromRoute('certificatelogin.initial', [], $options)), + 'certificatelogin' => Link::fromTextAndUrl(t('Login with Certificate'), Url::fromRoute('certificatelogin.login', [], $options)), + ); + + $block = array( + '#links' => $links, + '#theme' => 'certificatelogin_block', + '#attributes' => [ + 'class' => ['certificatelogin'], + 'id' => 'certificatelogin-block', + ], + '#attached' => [ + 'library' => [ + 'certificatelogin/certificatelogin', + ], + ], + ); + + return $block; + } +} diff --git a/src/Plugin/Menu/LoginLogoutMenuLink.php b/src/Plugin/Menu/LoginLogoutMenuLink.php new file mode 100644 index 0000000..44954b4 --- /dev/null +++ b/src/Plugin/Menu/LoginLogoutMenuLink.php @@ -0,0 +1,38 @@ +currentUser->isAuthenticated()) { + return $this->t('Log out'); + } + else { + return $this->t('Certificate Login'); + } + } + + /** + * {@inheritdoc} + */ + public function getRouteName() { + if ($this->currentUser->isAuthenticated()) { + return 'user.logout'; + } + else { + return 'certificatelogin.initial'; + } + } +} diff --git a/templates/certificatelogin-block.html.twig b/templates/certificatelogin-block.html.twig new file mode 100644 index 0000000..15ef980 --- /dev/null +++ b/templates/certificatelogin-block.html.twig @@ -0,0 +1,5 @@ +