PM-3501 Move pmgmail authentication end point to the next branch 3.0.1.4
remove email fix in message response
This commit is contained in:
committed by
Enrique Ponce De Leon
parent
8b39e13166
commit
7c66b8c94b
@@ -103,6 +103,31 @@ class Users extends BaseUsers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function loadByEmail ($sUsrEmail)
|
||||||
|
{
|
||||||
|
$c = new Criteria( 'workflow' );
|
||||||
|
|
||||||
|
$c->clearSelectColumns();
|
||||||
|
$c->addSelectColumn( UsersPeer::USR_UID );
|
||||||
|
$c->addSelectColumn( UsersPeer::USR_USERNAME );
|
||||||
|
$c->addSelectColumn( UsersPeer::USR_STATUS );
|
||||||
|
$c->addSelectColumn( UsersPeer::USR_FIRSTNAME );
|
||||||
|
$c->addSelectColumn( UsersPeer::USR_LASTNAME );
|
||||||
|
|
||||||
|
$c->add( UsersPeer::USR_EMAIL, $sUsrEmail );
|
||||||
|
return $c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadByUserEmailInArray ($sUsrEmail)
|
||||||
|
{
|
||||||
|
$c = $this->loadByEmail( $sUsrEmail );
|
||||||
|
$rs = UsersPeer::doSelectRS( $c, Propel::getDbConnection('workflow_ro') );
|
||||||
|
$rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||||
|
$rs->next();
|
||||||
|
$row = $rs->getRow();
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
public function loadDetails ($UsrUid)
|
public function loadDetails ($UsrUid)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ProcessMaker\Services\Api\Google;
|
||||||
|
|
||||||
|
use \ProcessMaker\Services\Api;
|
||||||
|
use \Luracast\Restler\RestException;
|
||||||
|
|
||||||
|
class Authentication extends Api
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get token for user gmail
|
||||||
|
*
|
||||||
|
* @param array $request_data
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @url POST /gmail
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function doAuthenticationAccountGmail ($request_data) {
|
||||||
|
try{
|
||||||
|
$oGoogle = new \ProcessMaker\Services\Google\Authentication();
|
||||||
|
$response = $oGoogle->postTokenAccountGmail($request_data);
|
||||||
|
return $response;
|
||||||
|
} catch (\Exception $e){
|
||||||
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
namespace ProcessMaker\Services\Google;
|
||||||
|
|
||||||
|
class Authentication
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Post Token by user Gmail
|
||||||
|
*
|
||||||
|
* @param array $request_data
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function postTokenAccountGmail($request_data)
|
||||||
|
{
|
||||||
|
$responseToken = array('msg' => \G::LoadTranslation( 'ID_UPGRADE_ENTERPRISE' ));
|
||||||
|
|
||||||
|
/*----------------------------------********---------------------------------*/
|
||||||
|
|
||||||
|
//Lets verify the gmail token
|
||||||
|
$url = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token='.$request_data['token'];
|
||||||
|
|
||||||
|
// init curl object
|
||||||
|
$ch = curl_init();
|
||||||
|
// define options
|
||||||
|
$optArray = array(
|
||||||
|
CURLOPT_URL => $url,
|
||||||
|
CURLOPT_RETURNTRANSFER => true
|
||||||
|
);
|
||||||
|
// apply those options
|
||||||
|
curl_setopt_array($ch, $optArray);
|
||||||
|
// execute request and get response
|
||||||
|
$result = curl_exec($ch);
|
||||||
|
$response = (json_decode($result));
|
||||||
|
// Check if any error occurred
|
||||||
|
if(curl_errno($ch))
|
||||||
|
{
|
||||||
|
throw (new \Exception(\G::LoadTranslation( 'ID_TO_URL' )));
|
||||||
|
}
|
||||||
|
$info = curl_getinfo($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
//If there is response
|
||||||
|
if($info['http_code'] == 200 && isset($response->email)){
|
||||||
|
//If the usermail that was send in the end point es the same of the one in the response
|
||||||
|
if($request_data['mail'] == $response->email){
|
||||||
|
$oUsers = new \Users();
|
||||||
|
$userExist = $oUsers->loadByUserEmailInArray($request_data['mail']);
|
||||||
|
|
||||||
|
if($userExist['USR_STATUS'] == "ACTIVE"){
|
||||||
|
//User Active! lets create the token and register it in the DB for this user
|
||||||
|
$oauthServer = new \ProcessMaker\Services\OAuth2\Server;
|
||||||
|
$server = $oauthServer->getServer();
|
||||||
|
$config = array(
|
||||||
|
'allow_implicit' => $server->getConfig('allow_implicit'),
|
||||||
|
'access_lifetime' => $server->getConfig('access_lifetime')
|
||||||
|
);
|
||||||
|
$storage = $server->getStorages();
|
||||||
|
$accessToken = new \OAuth2\ResponseType\AccessToken($storage['access_token'],$storage['refresh_token'],$config);
|
||||||
|
$responseToken = $accessToken->createAccessToken($request_data['clientid'], $userExist['USR_UID'],$request_data['scope']);
|
||||||
|
}else {
|
||||||
|
throw (new \Exception(\G::LoadTranslation( 'ID_ACTIVE_USERS' )));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw (new \Exception(\G::LoadTranslation( 'ID_EMAIL_ENTER_VALID' )));
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
throw (new \Exception(\G::LoadTranslation( 'ID_PMGMAIL_VALID' )));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----------------------------------********---------------------------------*/
|
||||||
|
|
||||||
|
return $responseToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -114,3 +114,5 @@ debug = 1
|
|||||||
[alias: catalog]
|
[alias: catalog]
|
||||||
dashboard = "ProcessMaker\Services\Api\Catalog"
|
dashboard = "ProcessMaker\Services\Api\Catalog"
|
||||||
|
|
||||||
|
[alias: google]
|
||||||
|
authentication = "ProcessMaker\Services\Api\Google\Authentication"
|
||||||
|
|||||||
Reference in New Issue
Block a user