Commit d8f42441 authored by Aster's avatar Aster Committed by waltermazza
Browse files

General Bug Fixes and Improvements

parent 49b4b93d
......@@ -11,13 +11,13 @@ Installation
Either run
```bash
composer require arter/amos-social-auth
composer require elitedivision/amos-social-auth
```
or add
```
"arter/amos-social-auth": "~1.0"
"elitedivision/amos-social-auth": "~1.0"
```
to the require section of your `composer.json` file.
......@@ -28,7 +28,7 @@ Installation
<?php
'modules' => [
'socialauth' => [
'class' => 'arter\amos\socialauth\Module'
'class' => 'elitedivision\amos\socialauth\Module'
],
],
```
......@@ -36,7 +36,7 @@ Installation
3. Apply migrations
```bash
php yii migrate/up --migrationPath=@vendor/arter/amos-social-auth/src/migrations
php yii migrate/up --migrationPath=@vendor/elitedivision/amos-social-auth/src/migrations
```
......@@ -49,7 +49,7 @@ Configuration
<?php
'modules' => [
'socialauth' => [
'class' => 'arter\amos\socialauth\Module',
'class' => 'elitedivision\amos\socialauth\Module',
'enableLogin' => true,
'enableLink' => false,
'enableRegister' => false,
......@@ -98,7 +98,7 @@ To enable social links check in admin configuraion the visibility for box social
```php
$modules['admin'] = [
'class' => 'arter\amos\admin\AmosAdmin',
'class' => 'elitedivision\amos\admin\AmosAdmin',
'enableRegister' => true,
'fieldsConfigurations' => [
'boxes' => [
......@@ -146,9 +146,8 @@ Providers configuration doc: https://hybridauth.github.io/hybridauth/userguide.h
In the Credentials tab, select the New credentials drop-down list, and choose **OAuth client ID**.
6. From the Application type list, choose the Web application.
7. Enter a name and provide this URLs as Authorized redirect URIs:
http://YourPlatformUrl/socialauth/social-auth/endpoint?action=done&provider=google
http://YourPlatformUrl/admin/user-profile/enable-google-service
https://YourPlatformUrl/socialauth/social-auth/endpoint?action=done&provider=google
https://YourPlatformUrl/socialauth/social-auth/sign-in?action=done&provider=google
https://YourPlatformUrl/socialauth/social-auth/sign-up?action=done&provider=google
https://YourPlatformUrl/admin/user-profile/enable-google-service
8. Once you have registered, copy and past the created application credentials (Client ID and Secret) into the HybridAuth config file.
......
{
"name": "arter/amos-social-auth",
"name": "elitedivision/amos-social-auth",
"description": "Social Auth",
"keywords": ["amos", "auth", "social", "yii2"],
"homepage": "https://bitbucket.org/arter/amos-social-auth",
"homepage": "https://bitbucket.org/elite_division/amos-social-auth",
"type": "component",
"require": {
"php": ">=5.4.0",
"arter/amos-admin":"^2.0.18",
"arter/amos-core":"^1.9.52",
"arter/amos-attachments":"^1.0",
"elitedivision/amos-admin":"^2.0.18",
"elitedivision/amos-core":"^1.9.52",
"elitedivision/amos-attachments":"^1.0",
"hybridauth/hybridauth": "~2.9",
"google/apiclient": "^2.0",
"yiisoft/yii2-authclient": "^2.1.0",
......@@ -16,7 +16,7 @@
},
"autoload": {
"psr-4": {
"arter\\amos\\socialauth\\": "src"
"elitedivision\\amos\\socialauth\\": "src"
}
}
}
\ No newline at end of file
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\socialauth
* @package elitedivision\amos\socialauth
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
namespace arter\amos\socialauth;
namespace elitedivision\amos\socialauth;
use arter\amos\admin\AmosAdmin;
use arter\amos\admin\models\UserProfile;
use arter\amos\core\module\AmosModule;
use arter\amos\socialauth\controllers\ShibbolethController;
use arter\amos\socialauth\models\SocialAuthServices;
use arter\amos\socialauth\utility\SocialAuthUtility;
use elitedivision\amos\admin\AmosAdmin;
use elitedivision\amos\admin\models\UserProfile;
use elitedivision\amos\core\module\AmosModule;
use elitedivision\amos\socialauth\controllers\ShibbolethController;
use elitedivision\amos\socialauth\models\SocialAuthServices;
use elitedivision\amos\socialauth\utility\SocialAuthUtility;
use Yii;
use yii\base\BootstrapInterface;
use yii\base\Event;
......@@ -28,7 +28,7 @@ use yii\helpers\ArrayHelper;
/**
* Class Module
* @package arter\amos\socialauth
* @package elitedivision\amos\socialauth
*/
class Module extends AmosModule implements BootstrapInterface
{
......@@ -94,7 +94,7 @@ class Module extends AmosModule implements BootstrapInterface
/**
* @inheritdoc
*/
public $controllerNamespace = 'arter\amos\socialauth\controllers';
public $controllerNamespace = 'elitedivision\amos\socialauth\controllers';
public $timeout = 180;
......@@ -112,6 +112,8 @@ class Module extends AmosModule implements BootstrapInterface
* @var bool $shibbolethAutoRegistration if true on shibboleth controller make automatic registration
*/
public $shibbolethAutoRegistration = false;
public $checkOnlyFiscalCode= false;
/**
* @inheritdoc
......@@ -119,7 +121,7 @@ class Module extends AmosModule implements BootstrapInterface
public function init()
{
parent::init(); // TODO: Change the autogenerated stub
\Yii::setAlias('@arter/amos/' . static::getModuleName() . '/controllers', __DIR__ . '/controllers');
\Yii::setAlias('@elitedivision/amos/' . static::getModuleName() . '/controllers', __DIR__ . '/controllers');
//Configuration
$config = require(__DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php');
......@@ -305,7 +307,7 @@ class Module extends AmosModule implements BootstrapInterface
//Init a new shibboleth controller to link user
$shibbolethController = new ShibbolethController('shibboleth', $this);
Event::on(AmosAdmin::instance()->model('UserProfile'), UserProfile::EVENT_AFTER_INSERT, ['arter\amos\socialauth\utility\SocialAuthUtility', 'createIdmUser']);
Event::on(AmosAdmin::instance()->model('UserProfile'), UserProfile::EVENT_AFTER_INSERT, ['elitedivision\amos\socialauth\utility\SocialAuthUtility', 'createIdmUser']);
//Get Session IDM datas (copy of headers)
$sessionIDM = \Yii::$app->session->get('IDM');
......@@ -317,4 +319,14 @@ class Module extends AmosModule implements BootstrapInterface
return $shibbolethController->tryIdmLink('spid', $sessionIDM, false, false);
}
}
/**
* This method find the association between the platform user and the social idm user (SPID).
* @param int $userId
* @return SocialIdmUser|null
*/
public function findSocialIdmByUserId($userId)
{
return SocialAuthUtility::findSocialIdmByUserId($userId);
}
}
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\socialauth
* @package elitedivision\amos\socialauth
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
namespace arter\amos\socialauth\components;
namespace elitedivision\amos\socialauth\components;
use arter\amos\core\icons\AmosIcons;
use arter\amos\socialauth\Module;
use elitedivision\amos\core\icons\AmosIcons;
use elitedivision\amos\socialauth\Module;
use Yii;
use yii\base\Component;
use yii\base\Widget;
......@@ -25,7 +25,7 @@ use yii\helpers\Html;
/**
* Class FileImport
* @package arter\amos\socialauth\components
* @package elitedivision\amos\socialauth\components
*/
class SocialAuthBar extends Widget
{
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\socialauth
* @package elitedivision\amos\socialauth
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
namespace arter\amos\socialauth\components;
namespace elitedivision\amos\socialauth\components;
use arter\amos\core\icons\AmosIcons;
use arter\amos\socialauth\models\SocialAuthUsers;
use arter\amos\socialauth\Module;
use elitedivision\amos\core\icons\AmosIcons;
use elitedivision\amos\socialauth\models\SocialAuthUsers;
use elitedivision\amos\socialauth\Module;
use Yii;
use yii\base\Component;
use yii\base\Widget;
......@@ -26,7 +26,7 @@ use yii\helpers\Html;
/**
* Class FileImport
* @package arter\amos\socialauth\components
* @package elitedivision\amos\socialauth\components
*/
class SocialLinkBar extends Widget
{
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\socialauth\components
* @package elitedivision\amos\socialauth\components
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
namespace arter\amos\socialauth\components;
namespace elitedivision\amos\socialauth\components;
use arter\amos\socialauth\Module;
use elitedivision\amos\socialauth\Module;
use Yii;
use yii\base\Widget;
/**
* Class SocialLinkTable
* @package arter\amos\socialauth\components
* @package elitedivision\amos\socialauth\components
*/
class SocialLinkTable extends Widget
{
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\socialauth
* @package elitedivision\amos\socialauth
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
namespace arter\amos\socialauth\components;
namespace elitedivision\amos\socialauth\components;
use arter\amos\core\icons\AmosIcons;
use arter\amos\socialauth\Module;
use elitedivision\amos\core\icons\AmosIcons;
use elitedivision\amos\socialauth\Module;
use Yii;
use yii\base\Component;
use yii\base\Widget;
......@@ -25,7 +25,7 @@ use yii\helpers\Html;
/**
* Class FileImport
* @package arter\amos\socialauth\components
* @package elitedivision\amos\socialauth\components
*/
class SocialSignUpBar extends Widget
{
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\socialauth
* @package elitedivision\amos\socialauth
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
use yii\helpers\Html;
use arter\amos\core\icons\AmosIcons;
use elitedivision\amos\core\icons\AmosIcons;
?>
<div class="social-auth-bar">
<?php
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\socialauth
* @package elitedivision\amos\socialauth
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
use yii\helpers\Html;
use arter\amos\core\icons\AmosIcons;
use arter\amos\socialauth\Module;
use elitedivision\amos\core\icons\AmosIcons;
use elitedivision\amos\socialauth\Module;
?>
<div class="social-auth-bar">
<?php
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\socialauth
* @package elitedivision\amos\socialauth
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
use yii\helpers\Html;
use arter\amos\core\icons\AmosIcons;
use elitedivision\amos\core\icons\AmosIcons;
?>
<div class="social-auth-bar">
<?php
......@@ -47,7 +47,7 @@ use arter\amos\core\icons\AmosIcons;
<button type="button" class="btn btn-social collega-social" data-type="<?= $lowCaseName ?>">
<span class="fa fa-<?= $lowCaseName ?>"></span>
<span>
<?= \arter\amos\socialauth\Module::t('amossocialauth', 'Collega il tuo profilo') ?>
<?= \elitedivision\amos\socialauth\Module::t('amossocialauth', 'Collega il tuo profilo') ?>
</span>
</button>
<?php endif; ?>
......@@ -72,14 +72,14 @@ use arter\amos\core\icons\AmosIcons;
</div>
<div class="field-media">
<label>Email</label>
<span>damian.gomez@arter.it</span>
<span>damian.gomez@elitedivision.it</span>
</div>
</div>
</div>
<?php else: ?>
<div class="validatore_container checkws">
<br>
<?= \arter\amos\socialauth\Module::t('amossocialauth', 'Nessun profilo collegato.') ?>
<?= \elitedivision\amos\socialauth\Module::t('amossocialauth', 'Nessun profilo collegato.') ?>
</div>
<?php endif; ?>
</div>
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\socialauth
* @package elitedivision\amos\socialauth
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
use yii\helpers\Html;
use arter\amos\core\icons\AmosIcons;
use elitedivision\amos\core\icons\AmosIcons;
?>
<div class="social-auth-bar">
<?php
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\socialauth
* @package elitedivision\amos\socialauth
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
return [
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\socialauth
* @package elitedivision\amos\socialauth
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
namespace arter\amos\socialauth\controllers;
namespace elitedivision\amos\socialauth\controllers;
use conquer\oauth2\models\Client;
use arter\amos\admin\models\LoginForm;
use arter\amos\admin\models\UserProfile;
use arter\amos\core\controllers\CrudController;
use arter\amos\core\helpers\Html;
use arter\amos\core\icons\AmosIcons;
use arter\amos\socialauth\models\search\ClientSearch;
use arter\amos\socialauth\Module;
use elitedivision\amos\admin\models\LoginForm;
use elitedivision\amos\admin\models\UserProfile;
use elitedivision\amos\core\controllers\CrudController;
use elitedivision\amos\core\helpers\Html;
use elitedivision\amos\core\icons\AmosIcons;
use elitedivision\amos\socialauth\models\search\ClientSearch;
use elitedivision\amos\socialauth\Module;
use Yii;
use yii\filters\AccessControl;
use yii\web\Response;
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
* Lombardia Informatica S.p.A.
* OPEN 2.0
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\socialauth
* @package elitedivision\amos\socialauth
* @category CategoryName
* @author Elite Division S.r.l.
* @author Lombardia Informatica S.p.A.
*/
namespace arter\amos\socialauth\controllers;
namespace elitedivision\amos\socialauth\controllers;
use arter\amos\admin\AmosAdmin;
use arter\amos\admin\models\UserProfile;
use arter\amos\core\controllers\BackendController;
use arter\amos\core\user\User;
use arter\amos\socialauth\models\SocialIdmUser;
use arter\amos\socialauth\Module;
use arter\amos\socialauth\utility\SocialAuthUtility;
use elitedivision\amos\admin\AmosAdmin;
use elitedivision\amos\admin\models\UserProfile;
use elitedivision\amos\core\controllers\BackendController;
use elitedivision\amos\core\user\User;
use elitedivision\amos\socialauth\models\SocialIdmUser;
use elitedivision\amos\socialauth\Module;
use elitedivision\amos\socialauth\utility\SocialAuthUtility;
use Yii;
use yii\base\Action;
use yii\filters\AccessControl;
......@@ -29,7 +29,7 @@ use yii\helpers\Url;
/**
* Class ShibbolethController
* @package arter\amos\socialauth\controllers
* @package elitedivision\amos\socialauth\controllers
*/
class ShibbolethController extends BackendController
{
......@@ -63,6 +63,13 @@ class ShibbolethController extends BackendController
'set-module-instance',
],
//'roles' => ['*']
],
[
'allow' => true,
'actions' => [
'remove-spid',
],
'roles' => ['@']
]
],
],
......@@ -107,7 +114,7 @@ class ShibbolethController extends BackendController
$result = $this->tryIdmLink(false, true, false);
if (is_array($result) && isset($result['status'])) {
$user = \arter\amos\mobile\bridge\modules\v1\models\User::findOne(Yii::$app->user->id);
$user = \elitedivision\amos\mobile\bridge\modules\v1\models\User::findOne(Yii::$app->user->id);
$user->refreshAccessToken('', '');
return $this->redirect(['/socialauth/social-auth/land', 'token' => $user->getAccessToken()]);
......@@ -183,11 +190,18 @@ class ShibbolethController extends BackendController
/** @var UserProfile|null $existsByFC */
$existsByFC = (($countUsersByCF == 1) ? reset($usersByCF) : null);
$existsByEmail = User::findOne(['email' => $userDatas['emailAddress']]);
/** @var Module $socialAuthModule */
$socialAuthModule = Module::instance();
$adminModule = AmosAdmin::getInstance();
$checkOnlyFiscalCode = $socialAuthModule->checkOnlyFiscalCode;
$existsByEmail = null;
if (!$checkOnlyFiscalCode) {
$existsByEmail = User::findOne([