Skip to content

Instantly share code, notes, and snippets.

@hissy hissy/login.php
Last active Jul 29, 2019

Embed
What would you like to do?
#concrete5 Force specific authentication type by environment
<?php
// Put this file on application/controllers/single_page/login.php
namespace Application\Controller\SinglePage;
use Concrete\Core\Routing\RedirectResponse;
use Concrete\Core\Support\Facade\Facade;
use Concrete\Core\Url\Resolver\Manager\ResolverManagerInterface;
class Login extends \Concrete\Controller\SinglePage\Login
{
/**
* The name of environment tha you want to force authentication type
*/
private static $forceEnvironment = 'production';
/**
* The handle of authentication type that you want to force users to use
*/
private static $forceAuthenticationType = 'google';
public function view($type = null, $element = 'form')
{
$response = $this->handleAuthenticationTypeByEnvironment($type);
if (is_object($response)) {
return $response;
}
return parent::view($type, $element);
}
/**
* Force "google" authentication type on the "production" environment
*
* @param $type
* @return RedirectResponse
*/
protected function handleAuthenticationTypeByEnvironment($type = '')
{
$app = Facade::getFacadeApplication();
$env = $app->environment();
/** @var ResolverManagerInterface $resolver */
$resolver = $app->make(ResolverManagerInterface::class);
if ($env == self::$forceEnvironment && $type != self::$forceAuthenticationType) {
return new RedirectResponse($resolver->resolve(['login', self::$forceAuthenticationType]));
}
}
public function authenticate($type = '')
{
$response = $this->handleAuthenticationTypeByEnvironment($type);
if (is_object($response)) {
return $response;
}
return parent::authenticate($type);
}
public function session_invalidated()
{
$this->flash('error', t('Your session has expired. Please sign in again.'));
return $this->handleAuthenticationTypeByEnvironment();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.