Skip to content

Commit

Permalink
mass dep fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Praesidiarius committed Mar 15, 2020
1 parent 5a94fd7 commit 988f08e
Show file tree
Hide file tree
Showing 9 changed files with 452 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "onePlace User Module",
"type": "oneplace-module",
"license": "BSD-3-Clause",
"version": "1.0.21",
"version": "1.0.22",
"keywords": [
"laminas",
"mvc",
Expand Down
9 changes: 6 additions & 3 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@
],
],
'denied' => [
'type' => Literal::class,
'type' => Segment::class,
'options' => [
'route' => '/denied',
'route' => '/denied[/:permission]',
'constraints' => [
'permission' => '[a-zA-Z0-9-_]*',
],
'defaults' => [
'controller' => Controller\AuthController::class,
'action' => 'denied',
Expand All @@ -77,7 +80,7 @@
'options' => [
'route' => '/reset-password[/:username[/:token]]',
'constraints' => [
'username' => '[a-zA-Z0-9]*',
'username' => '[a-zA-Z0-9-_]*',
'token' => '[a-zA-Z0-9]+',
],
'defaults' => [
Expand Down
12 changes: 12 additions & 0 deletions data/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ ALTER TABLE `user_search`
ALTER TABLE `user_search`
MODIFY `Search_ID` int(11) NOT NULL AUTO_INCREMENT;

CREATE TABLE `user_registration` (
`Registration_ID` int(11) NOT NULL,
`user_token` varchar(255) NOT NULL,
`created_date` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `user_registration`
ADD PRIMARY KEY (`Registration_ID`);

ALTER TABLE `user_registration`
MODIFY `Registration_ID` int(11) NOT NULL AUTO_INCREMENT;

--
-- Save
--
Expand Down
31 changes: 31 additions & 0 deletions src/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,35 @@ private function generateKey()

return $sKey;
}

public function finishsetupAction()
{
$this->layout('layout/json');

$sSystemName = $this->params()->fromRoute('systemkey', '');

$aResponse = ['state' => 'error', 'message' => 'unkown error'];
if($sSystemName != '') {
$oReqTbl = new TableGateway('user_instance_request', CoreController::$oDbAdapter);

$oRequest = $oReqTbl->select(['name' => $sSystemName]);
if(count($oRequest) > 0 ) {
$oRequest = $oRequest->current();
$bHasProtocol = stripos('https://',$oRequest->url);
if($bHasProtocol === false) {
$oRequest->url = 'https://'.$oRequest->url;
}
$sLog = '+++ Starting Installation<br/>+++ Request to License Server<br/>+++ Installing onePlace Modules<br/>+++ Done ! You can now login to <a target="_blank" href="'.$oRequest->url.'">your new onePlace</a><br/>Username: '.$sSystemName.'<br/>Password: <i>Your my.onep.lc Password</i>';
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/data/installer/'.$oRequest->Request_ID.'/status.log',$sLog);
$oReqTbl->delete(['Request_ID' => $oRequest->Request_ID]);
} else {
$aResponse = ['state' => 'error', 'message' => 'request not found'];
}
} else {
$aResponse = ['state' => 'error', 'message' => 'invalid system name'];
}

echo json_encode($aResponse);
return false;
}
}
20 changes: 19 additions & 1 deletion src/Controller/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ public function loginAction()
# Login Successful - redirect to Dashboard
CoreController::$oSession->oUser = $oUser;

# Check if it is first login
$oPermTbl = new TableGateway('user_permission', CoreController::$oDbAdapter);
$aPerms = $oPermTbl->select();
if(count($aPerms) == 0) {
$aBasePerms = CoreController::$aCoreTables['permission']->select([
'needs_globaladmin' => 0
]);
if(count($aBasePerms) > 0) {
foreach($aBasePerms as $oPerm) {
$oPermTbl->insert([
'user_idfs' => $oUser->getID(),
'permission' => $oPerm->permission_key,
'module' => $oPerm->module,
]);
}
}
}

# Add XP for successful login
$oUser->addXP('login');

Expand Down Expand Up @@ -138,7 +156,7 @@ public function deniedAction()
# Set Layout based on users theme
$this->setThemeBasedLayout('user');

$sPermission = $this->params()->fromRoute('id', 'Def');
$sPermission = $this->params()->fromRoute('permission', 'Def');

return new ViewModel([
'sPermission' => $sPermission,
Expand Down
8 changes: 5 additions & 3 deletions src/Model/UserTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,15 @@ public function saveSingle(User $user)
'lang' => $user->lang,
];

$iCreatorID = (isset(CoreController::$oSession->oUser)) ? CoreController::$oSession->oUser->getID() : 1;

$id = (int) $user->id;

if ($id === 0) {
# add dates
$data['created_by'] = CoreController::$oSession->oUser->getID();
$data['created_by'] = $iCreatorID;
$data['created_date'] = date('Y-m-d H:i:s', time());
$data['modified_by'] = CoreController::$oSession->oUser->getID();
$data['modified_by'] = $iCreatorID;
$data['modified_date'] = date('Y-m-d H:i:s', time());

$this->tableGateway->insert($data);
Expand All @@ -165,7 +167,7 @@ public function saveSingle(User $user)

# add modified date
if(isset($oSession->oUser)) {
$data['modified_by'] = CoreController::$oSession->oUser->getID();
$data['modified_by'] = $iCreatorID;
$data['modified_date'] = date('Y-m-d H:i:s', time());
}

Expand Down
5 changes: 3 additions & 2 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Module
*
* @since 1.0.0
*/
const VERSION = '1.0.21';
const VERSION = '1.0.22';

/**
* Load module config file
Expand Down Expand Up @@ -120,7 +120,7 @@ function ($e) {
$response->getHeaders()->addHeaderLine(
'Location',
$e->getRouter()->assemble(
['id' => $aRouteInfo['action']],
['permission' => $aRouteInfo['action'].'-'.str_replace(['\\'],['-'],$aRouteInfo['controller'])],
['name' => 'denied']
)
);
Expand Down Expand Up @@ -159,6 +159,7 @@ function ($e) {
'login' => [],
'reset-pw' => [],
'forgot-pw' => [],
'register' => [],
];

/**
Expand Down
Loading

0 comments on commit 988f08e

Please sign in to comment.