Skip to content

Commit

Permalink
Merge pull request #1 from flipboxfactory/develop
Browse files Browse the repository at this point in the history
Clean up of the login service.
  • Loading branch information
dsmrt committed Apr 10, 2018
2 parents 524cffe + 2034807 commit dc4813c
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 201 deletions.
8 changes: 4 additions & 4 deletions composer.json
@@ -1,7 +1,7 @@
{
"name": "flipboxfactory/saml-sp",
"description": "SAML SSO Service Provider",
"version": "1.0.0-beta.6",
"version": "1.0.0-beta.7",
"type": "craft-plugin",
"keywords": [
"cms",
Expand All @@ -16,7 +16,7 @@
"minimum-stability":"beta",
"require": {
"craftcms/cms": "^3.0.0",
"flipboxfactory/saml-core": "^1.0.0-beta.6"
"flipboxfactory/saml-core": "^1.0.0-beta.8"
},
"require-dev": {
"phpunit/phpunit": "^5.0",
Expand All @@ -41,8 +41,8 @@
},
"extra": {
"name": "SAML SSO Service Provider",
"version":"1.0.0-beta.6",
"schemaVersion":"1.0.0-beta.6",
"version":"1.0.0-beta.7",
"schemaVersion":"1.0.0-beta.7",
"handle": "saml-sp",
"class": "flipbox\\saml\\sp\\Saml",
"developer": "Flipbox Digital",
Expand Down
6 changes: 4 additions & 2 deletions src/controllers/LoginController.php
Expand Up @@ -87,7 +87,9 @@ public function actionIndex()


/**
* @throws \flipbox\saml\core\exceptions\InvalidMetadata
* @throws InvalidMetadata
* @throws \yii\base\ExitException
* @throws \yii\base\InvalidConfigException
*/
public function actionRequest()
{
Expand Down Expand Up @@ -115,7 +117,7 @@ public function actionRequest()

Factory::send($authnRequest, $idp);

exit;
Craft::$app->end();
}

}
3 changes: 2 additions & 1 deletion src/controllers/LogoutController.php
Expand Up @@ -44,11 +44,12 @@ protected function getRemoteProvider(): ProviderInterface
* @param SamlMessage $samlMessage
* @param ProviderInterface $provider
* @throws \flipbox\saml\core\exceptions\InvalidMetadata
* @throws \yii\base\ExitException
*/
protected function send(SamlMessage $samlMessage, ProviderInterface $provider)
{
Factory::send($samlMessage, $provider);
exit;
\Craft::$app->end();
}

/**
Expand Down
50 changes: 0 additions & 50 deletions src/events/RegisterAttributesTransformer.php

This file was deleted.

93 changes: 93 additions & 0 deletions src/helpers/UserHelper.php
@@ -0,0 +1,93 @@
<?php

/**
* @copyright Copyright (c) Flipbox Digital Limited
*/

namespace flipbox\saml\sp\helpers;

use craft\elements\User as UserElement;

/**
* Class UserHelper
* @package flipbox\saml\sp\helpers
*/
class UserHelper
{
/**
* @param UserElement $user
* @throws \Throwable
*/
public static function enableUser(UserElement $user)
{
if (static::isUserSuspended($user)) {
\Craft::$app->getUsers()->unsuspendUser($user);
}

if (static::isUserLocked($user)) {
\Craft::$app->getUsers()->unlockUser($user);
}

if (! $user->enabled) {
$user->enabled = true;
}

if ($user->archived) {
$user->archived = false;
}

if (! static::isUserActive($user)) {
\Craft::$app->getUsers()->activateUser($user);
}
}

/**
* @param UserElement $user
* @return bool
*/
public static function isUserPending(UserElement $user)
{
return false === static::isUserActive($user) &&
$user->getStatus() === UserElement::STATUS_PENDING;
}

/**
* @param UserElement $user
* @return bool
*/
public static function isUserArchived(UserElement $user)
{
return false === static::isUserActive($user) &&
$user->getStatus() === UserElement::STATUS_ARCHIVED;
}

/**
* @param UserElement $user
* @return bool
*/
public static function isUserLocked(UserElement $user)
{
return false === static::isUserActive($user) &&
$user->getStatus() === UserElement::STATUS_LOCKED;
}

/**
* @param UserElement $user
* @return bool
*/
public static function isUserSuspended(UserElement $user)
{
return false === static::isUserActive($user) &&
$user->getStatus() === UserElement::STATUS_SUSPENDED;
}

/**
* @param UserElement $user
* @return bool
*/
public static function isUserActive(UserElement $user)
{
return $user->getStatus() === UserElement::STATUS_ACTIVE;
}

}

0 comments on commit dc4813c

Please sign in to comment.