This repository was archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/connection tab #52
Open
AymLaf
wants to merge
70
commits into
glpi-project:develop
Choose a base branch
from
AymLaf:feature/ConnectionTab
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,483
−326
Open
Changes from 21 commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
3d43a64
feat:add connexion tab
2dd22a7
add tuupola/slim-basic-auth: PSR-7 and PSR-15 HTTP Basic
8345d27
add db migration for user
4f1a4e0
add button for connection
2645b72
WIP implement register
8362e68
Login - Logoff - Register
883bd59
Login is mandatory to add reference - State management
9302130
define routes and globals
74b5253
Profile page
dd541b0
Admin view
a446a56
Connection form warn - Table td overflow management
e81b8e1
New links to login-logoff-register-profile-admin
c45a74e
migration file for the features
d03354f
Refactor code to update profile
8376edb
migration for features
ff80d85
factorizing code
a0dedf7
added constants for status
c990555
empty lines dropped
fc3b603
configuration parameters simplifyer
7d4e6c1
uncommented recaptcha line
f0eb5b7
jquery metgods used - password conditions refactor
e766738
factorizing code to load filters and references
edb11ce
cs
abd9ce0
create navbar on admin page
266e1ab
cs + phpdoc
9df75c4
method visibility fix
97c96da
Route management on adminNavBar
64ce95f
admin users's table
4be7287
keep datas in database on migration
ef71733
delete welcome msg
cfd78e6
redesign main navbar with dropdown
8003bf3
connection dropdown in navbar
dfd2cf3
add title attribute on status img
e434dd2
admin form on action, email not mandatory
bebee8b
cs
8f5820d
Fix undefined index
trasher a973444
Do not duplicate template and route
trasher f22fc7e
Do not load login form until required, "better" display
trasher d3e97a7
Add missing method and action
trasher cbd8dfe
Fix CSRF and some html issues
trasher 0124e5a
Fix csrf on standlone login page
trasher cbaeea8
variable name fixed
cce54c7
reference count on admin tab user's management
3bc7785
fix merge
6b8ebad
Other fix merge
dbe9de5
two differents views: refs and users management
2d730e9
right encoding
ad9139d
refactor code to factorize again query requests
a0b5d85
refactor to adapt it with customs filters
1046197
refactor to adapt with customs filters to launch query requests
bcd331f
function to catch username from ref_id
60e6cfa
convert function
c6b1106
better request
bc3d706
references management view improve for mass actions and filters
d9c7b26
users management view improve for mass actions and filters
31517be
profile view improve for mass actions and filters
c241a74
refactor code for filters
5e0725b
refactor code for filters
10ec17f
refactor code for filters
e05f05f
refactor routes
a913157
refactor mailing action
bccd5d2
some functions for mass actions
80e14df
remove this function from this file to globalize it
b6dcfb4
Filters class and filters table
4c93ee6
delete die;
df4fa84
uncomment recaptcha
155bfef
Fix sur un affichage de debug
13cdc67
better display for the connection dropdown
03e7bf9
recaptcha for contact page
abafe4c
fix massive action string display
AymLaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
<?php namespace GLPI\Telemetry\Controllers; | ||
|
||
use GLPI\Telemetry\Controllers\ControllerAbstract; | ||
use GLPI\Telemetry\Models\Reference as ReferenceModel; | ||
use Slim\Http\Request; | ||
use Slim\Http\Response; | ||
|
||
class Admin extends ControllerAbstract | ||
{ | ||
public function view(Request $req, Response $res, array $args) | ||
{ | ||
$get = $req->getQueryParams(); | ||
|
||
$diff_filters = ReferenceModel::setDifferentsFilters($get, $args, $_SESSION['reference'], __CLASS__); | ||
$_SESSION['reference'] = $diff_filters; | ||
|
||
//check for refences presence | ||
$dyn_refs = $this->container->project->getDynamicReferences(); | ||
if (false === $dyn_refs) { | ||
// retrieve data from model | ||
$references = ReferenceModel::active()->orderBy( | ||
$_SESSION['reference']['orderby'], | ||
$_SESSION['reference']['sort'] | ||
)->paginate($_SESSION['reference']['pagination']); | ||
} else { | ||
try { | ||
$join_table = $this->container->project->getSlug() . '_reference'; | ||
$order_field = $_SESSION['reference']['orderby']; | ||
$order_table = (isset($dyn_refs[$order_field]) ? $join_table : 'reference'); | ||
// retrieve data from model | ||
$ref = new ReferenceModel(); | ||
$model = $ref->newInstance(); | ||
$model = call_user_func_array( | ||
[ | ||
$model, | ||
'select' | ||
], | ||
array_merge( | ||
['reference.*'], | ||
array_map( | ||
function ($key) use ($join_table) { | ||
return $join_table . '.' . $key; | ||
}, | ||
array_keys($dyn_refs) | ||
) | ||
) | ||
); | ||
$model->where('status', '=', $_SESSION['reference'][__CLASS__]); | ||
$model->orderBy( | ||
$order_table . '.' . $order_field, | ||
$_SESSION['reference']['sort'] | ||
) | ||
->leftJoin($join_table, 'reference.id', '=', $join_table . '.reference_id') | ||
; | ||
$references = $model->paginate($_SESSION['reference']['pagination']); | ||
//var_dump($_SESSION['reference']);die; | ||
} catch (\Illuminate\Database\QueryException $e) { | ||
if ($e->getCode() == '42P01') { | ||
//relation does not exists | ||
throw new \RuntimeException( | ||
'You have configured dynamic references for your project; but table ' . | ||
$join_table . ' is missing!', | ||
0, | ||
$e | ||
); | ||
} | ||
throw $e; | ||
} | ||
} | ||
|
||
$ref_ref = new ReferenceModel; | ||
$ref = $ref_ref->newInstance(); | ||
foreach ($references as $reference) { | ||
$mails = $ref->findMails($reference['attributes']['id']); | ||
if($mails !== false){ | ||
$ref_user_mails[$reference['attributes']['id']] = $mails; | ||
}else{ | ||
$ref_user_mails[$reference['attributes']['id']] = null; | ||
} | ||
} | ||
|
||
|
||
|
||
$references->setPath($this->container->router->pathFor('admin')); | ||
|
||
// render in twig view | ||
$this->render($this->container->project->pathFor('admin.html.twig'), [ | ||
'class' => 'admin', | ||
'showmodal' => isset($get['showmodal']), | ||
'uuid' => isset($get['uuid']) ? $get['uuid'] : '', | ||
'references' => $references, | ||
'pagination' => $references->appends($_GET)->render(), | ||
'orderby' => $_SESSION['reference']['orderby'], | ||
'sort' => $_SESSION['reference']['sort'], | ||
'dyn_refs' => $dyn_refs, | ||
'user_session' => $_SESSION['user'], | ||
'status_page' => $_SESSION['reference'][__CLASS__], | ||
'ref_user_mails'=> json_encode($ref_user_mails) | ||
]); | ||
} | ||
|
||
public function filter(Request $req, Response $res, array $args) | ||
{ | ||
$get = $req->getQueryParams(); | ||
|
||
// manage sorting | ||
if (isset($args['orderby'])) { | ||
if ($_SESSION['reference']['orderby'] == $args['orderby']) { | ||
// toggle sort if orderby requested on the same column | ||
$_SESSION['reference']['sort'] = ($_SESSION['reference']['sort'] == "desc" | ||
? "asc" | ||
: "desc"); | ||
} | ||
$_SESSION['reference']['orderby'] = $args['orderby']; | ||
} | ||
|
||
return $res->withRedirect($this->container->router->pathFor('admin')); | ||
} | ||
|
||
public function ActionReferencePost(Request $req, Response $res) | ||
{ | ||
$post = $req->getParsedBody(); | ||
$tmp = []; | ||
if(isset($post['checkboxAdminActionForm1'])){ | ||
$tmp[] = $post['checkboxAdminActionForm1']; | ||
} | ||
if(isset($post['checkboxAdminActionForm2'])){ | ||
$tmp[] = $post['checkboxAdminActionForm2']; | ||
} | ||
if(isset($post['inputrow3col2'])){ | ||
$tmp[] = $post['inputrow3col2']; | ||
} | ||
|
||
return $this->ActionReference($req, $res, | ||
[ | ||
'ref_id' => $post['ref_id_input'], | ||
'status' => $post['status_input'], | ||
'comment' => $post['comment'], | ||
'mails' => $tmp | ||
] | ||
); | ||
} | ||
|
||
public function ActionReference(Request $req, Response $res, array $args) | ||
{ | ||
$get = $req->getQueryParams(); | ||
$ref_ref = new ReferenceModel; | ||
$ref = $ref_ref->newInstance(); | ||
|
||
$ref_status_before_update_res = $ref->where("id", "=", $args['ref_id'])->firstOrFail(); | ||
$ref_status_before_update = $ref_status_before_update_res['attributes']['status']; | ||
|
||
$res_update = $ref->updateStatus($args['ref_id'], $args['status']); | ||
|
||
if($res_update == 1){ | ||
$type = "success"; | ||
$msg_text = "Action done"; | ||
foreach ($args['mails'] as $key => $mail_to) { | ||
$this->sendMail($req, $res, $args, $ref_status_before_update, $mail_to); | ||
} | ||
}else{ | ||
$type = "error"; | ||
$msg_text = "An error happened, bad insert, $res_update rows were updated, 1 row to update was expected"; | ||
} | ||
|
||
$this->container->flash->addMessage( | ||
$type, | ||
$msg_text | ||
); | ||
|
||
return $res->withRedirect($this->container->router->pathFor('sorterAdmin', ['status'=>$ref_status_before_update])); | ||
} | ||
|
||
public function sendMail(Request $req, Response $res, array $args, $status_from, $mail_to) | ||
{ | ||
|
||
$ref = new ReferenceModel(); | ||
$ref_model = $ref->newInstance(); | ||
|
||
$status_from = $ref_model->statusIntToText($status_from); | ||
$status_to = $ref_model->statusIntToText($args['status']); | ||
|
||
$join_table = $this->container->project->getSlug() . '_reference'; | ||
|
||
$res_ref = $ref_model->where("reference.id", "=", $args['ref_id']) | ||
->leftJoin($join_table, $join_table.'.reference_id', '=', 'reference.id') | ||
->firstOrFail(); | ||
|
||
if(isset($args['comment']) && !empty($args['comment'])){ | ||
$admin_msg = "Administrator's message :\n".$args['comment']; | ||
}else{ | ||
$admin_msg = ""; | ||
} | ||
|
||
$msg_ref = | ||
" | ||
Name : " . $res_ref['attributes']['name'] ."\n | ||
Country : " . $res_ref['attributes']['country'] ."\n | ||
Assets : " . $res_ref['attributes']['num_assets'] ."\n | ||
Helpdesk : " . $res_ref['attributes']['num_helpdesk'] ."\n | ||
Registration date : " . date("d M Y, h:i a",strtotime($res_ref['attributes']['created_at'])) ."\n | ||
Comment : " . $res_ref['attributes']['comment']."\n"; | ||
|
||
$msg = "The status of your reference below has been changed by the admin from $status_from to $status_to :\n$msg_ref\n$admin_msg"; | ||
|
||
// prepare mail | ||
$mail = new \PHPMailer; | ||
$mail->setFrom($this->container['settings']['mail_admin']); | ||
$mail->addAddress($mail_to); | ||
$mail->Subject = "A new message from telemetry site : Reference status changed"; | ||
$mail->Body = $msg; | ||
$send_ok = $mail->send(); | ||
|
||
if($send_ok === false){ | ||
$this->container->flash->addMessage( | ||
"error", | ||
"Error sending the mail to $mail_to.\n".$mail->ErrorInfo | ||
); | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php namespace GLPI\Telemetry\Controllers; | ||
|
||
use GLPI\Telemetry\Controllers\ControllerAbstract; | ||
use Slim\Http\Request; | ||
use Slim\Http\Response; | ||
use GLPI\Telemetry\Models\Authentication as AuthenticationModel; | ||
|
||
class Connection extends ControllerAbstract | ||
{ | ||
public function view() | ||
{ | ||
$this->render($this->container->project->pathFor('connection.html.twig'), [ | ||
'class' => 'connection' | ||
]); | ||
} | ||
|
||
public function send(Request $req, Response $res, $redirect='telemetry') | ||
{ | ||
$post = $req->getParsedBody(); | ||
|
||
$auth_ref = new AuthenticationModel; | ||
$auth = $auth_ref->newInstance(); | ||
|
||
if($auth->Authenticate($post)) { | ||
// store a message for user (displayed after redirect) | ||
$msg_text = "You are now connected !"; | ||
$this->container->flash->addMessage( | ||
'success', | ||
$msg_text | ||
); | ||
$this->container->flash->addMessage( | ||
'success', | ||
'Welcome '.$post['user'] | ||
); | ||
|
||
$_SESSION['user'] = $auth->getUser()['attributes']; | ||
|
||
//redirect | ||
return $res->withRedirect($this->container->router->pathFor($redirect)); | ||
|
||
} else { | ||
// store a message for user (displayed after redirect) | ||
$this->container->flash->addMessage( | ||
'warn', | ||
'Wrong username or password' | ||
); | ||
//redirect | ||
return $res->withRedirect($this->container->router->pathFor('connection')); | ||
|
||
} | ||
|
||
} | ||
|
||
public function disconnect(Request $req, Response $res) | ||
{ | ||
unset($_SESSION['user']); | ||
return $res->withRedirect($this->container->router->pathFor('telemetry')); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole part is now repeated several times; this should be factorized