11<?php
2+
23/*______________________________________________________
34 *======================================================
45 * File: edit_api_auth.php
56 * Author: George Ryall
6- * Description: Processes a edit API Authentication entity request. If the user
7- * hasn't POSTed any data we draw the new site
7+ * Description: Processes a edit API Authentication entity request.
8+ * If the user hasn't POSTed any data we draw the new site
89 * form. If they post data we assume they've posted it from
910 * the form and validate then insert it into the DB.
1011 *
2122 * See the License for the specific language governing permissions and
2223 * limitations under the License.
2324/*======================================================*/
24- require_once __DIR__ .'/../../../web_portal/components/Get_User_Principle.php ' ;
25- require_once __DIR__ .'/../utils.php ' ;
26- require_once __DIR__ .'/../../../../lib/Gocdb_Services/Factory.php ' ;
25+ require_once __DIR__
26+ . '/../../../web_portal/components/Get_User_Principle.php ' ;
27+ require_once __DIR__ . '/../utils.php ' ;
28+ require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php ' ;
29+
30+ use Exception ;
2731
2832/**
2933 * Controller to edit authentication entity request
30- * @global array $_POST only set if the browser has POSTed data
34+ *
35+ * @global array $_POST only set if the browser has posted data
36+ *
3137 * @return null
3238 */
33- function edit_entity () {
39+ function edit_entity ()
40+ {
3441 $ dn = Get_User_Principle ();
3542 $ user = \Factory::getUserService ()->getUserByPrinciple ($ dn );
3643
37- //Check the portal is not in read only mode, returns exception if it is and user is not an admin
44+ /**
45+ * Check the portal is not in read only mode,
46+ * returns exception if it is and user is not an admin
47+ */
3848 checkPortalIsNotReadOnlyOrUserIsAdmin ($ user );
3949
40- if (!isset ($ _REQUEST ['authentityid ' ]) || !is_numeric ($ _REQUEST ['authentityid ' ]) ){
41- throw new Exception ("A authentication entity id must be specified in the url " );
50+ if (
51+ !isset ($ _REQUEST ['authentityid ' ])
52+ || !is_numeric ($ _REQUEST ['authentityid ' ])
53+ ) {
54+ throw new Exception (
55+ "A authentication entity id must be specified in the url "
56+ );
4257 }
4358
4459 $ serv = \Factory::getSiteService ();
@@ -47,48 +62,67 @@ function edit_entity() {
4762
4863 // Validate the user has permission to edit properties
4964 if (!$ serv ->userCanEditSite ($ user , $ site )) {
50- throw new \Exception ("Permission denied: a site role is required to edit authentication entities at " . $ site ->getShortName ());
65+ throw new Exception (
66+ "Permission denied: a site role is required to edit "
67+ . "authentication entities at "
68+ . $ site ->getShortName ()
69+ );
5170 }
5271
53- if ($ _POST ) { // If we receive a POST request it's to edit an authentication entity
72+ // If we receive a POST request it's to edit an authentication entity
73+ if ($ _POST ) {
5474 submit ($ user , $ authEnt , $ site , $ serv );
55- } else { // If there is no post data, draw the edit authentication entity form
75+ } else {
76+ // If there is no post data, draw the edit authentication entity form
5677 draw ($ user , $ authEnt , $ site );
5778 }
5879}
5980
60- function draw (\User $ user = null , \APIAuthentication $ authEnt = null , \Site $ site = null ) {
61- if (is_null ($ user )){
62- throw new Exception ("Unregistered users can't edit authentication credentials " );
81+ function draw (
82+ \User $ user = null ,
83+ \APIAuthentication $ authEnt = null ,
84+ \Site $ site = null
85+ ) {
86+ if (is_null ($ user )) {
87+ throw new Exception (
88+ "Unregistered users can't edit authentication credentials "
89+ );
6390 }
6491
6592 $ params = array ();
6693 $ params ['site ' ] = $ site ;
6794 $ params ['authEnt ' ] = $ authEnt ;
6895 $ params ['authTypes ' ] = array ();
69- $ params ['authTypes ' ][]= 'X.509 ' ;
70- $ params ['authTypes ' ][]= 'OIDC Subject ' ;
96+ $ params ['authTypes ' ][] = 'X.509 ' ;
97+ $ params ['authTypes ' ][] = 'OIDC Subject ' ;
7198 $ params ['user ' ] = $ user ;
7299
73100 show_view ("site/edit_api_auth.php " , $ params );
101+
74102 die ();
75103}
76104
77- function submit (\User $ user , \APIAuthentication $ authEnt , \Site $ site , org \gocdb \services \Site $ serv ) {
105+ function submit (
106+ \User $ user ,
107+ \APIAuthentication $ authEnt ,
108+ \Site $ site ,
109+ org \gocdb \services \Site $ serv
110+ ) {
78111 $ newValues = getAPIAuthenticationFromWeb ();
79112
80113 try {
81114 $ authEnt = $ serv ->editAPIAuthEntity ($ authEnt , $ user , $ newValues );
82- } catch (Exception $ e ) {
115+ } catch (Exception $ e ) {
83116 show_view ('error.php ' , $ e ->getMessage ());
117+
84118 die ();
85119 }
86120
87121 $ params = array ();
88122 $ params ['apiAuthenticationEntity ' ] = $ authEnt ;
89123 $ params ['site ' ] = $ site ;
90- show_view ("site/edited_api_auth.php " , $ params );
91- die ();
92124
125+ show_view ("site/edited_api_auth.php " , $ params );
93126
127+ die ();
94128}
0 commit comments