From: Maxious Date: Mon, 22 Aug 2011 06:38:45 +0000 Subject: Add OpenID auth for editing pages X-Git-Url: https://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=dbf8c94b98fd5e5cb3c9844518d9076386e7e6e1 --- Add OpenID auth for editing pages --- --- /dev/null +++ b/.gitignore @@ -1,1 +1,8 @@ +/labs/tiles/12 +/labs/tiles/13 +/labs/tiles/14 +/labs/tiles/15 +/labs/tiles/16 +/labs/tiles/17 +/labs/tiles/19 --- a/aws/busuiphp.sh +++ b/aws/busuiphp.sh @@ -2,9 +2,15 @@ mkdir /var/www/lib/staticmaplite/cache chcon -h system_u:object_r:httpd_sys_content_t /var/www chcon -R -h root:object_r:httpd_sys_content_t /var/www/* + chcon -R -t httpd_sys_content_rw_t /var/www/lib/staticmaplite/cache chmod -R 777 /var/www/lib/staticmaplite/cache + chcon -R -t httpd_sys_content_rw_t /var/www/labs/tiles chmod -R 777 /var/www/labs/tiles + +chcon -R -t httpd_sys_content_rw_t /var/www/lib/openid-php/oid_store +chmod -R 777 /var/www/lib/openid-php/oid_store + wget http://s3-ap-southeast-1.amazonaws.com/busresources/cbrfeed.zip \ -O /var/www/cbrfeed.zip --- /dev/null +++ b/include/common-auth.inc.php @@ -1,1 +1,91 @@ + begin($oid_identifier); + + // Create attribute request object + // See http://code.google.com/apis/accounts/docs/OpenID.html#Parameters for parameters + // Usage: make($type_uri, $count=1, $required=false, $alias=null) + $attribute[] = Auth_OpenID_AX_AttrInfo :: make('http://axschema.org/contact/email', 2, 1, 'email'); + $attribute[] = Auth_OpenID_AX_AttrInfo :: make('http://axschema.org/namePerson/first', 1, 1, 'firstname'); + $attribute[] = Auth_OpenID_AX_AttrInfo :: make('http://axschema.org/namePerson/last', 1, 1, 'lastname'); + + // Create AX fetch request + $ax = new Auth_OpenID_AX_FetchRequest; + + // Add attributes to AX fetch request + foreach($attribute as $attr) { + $ax -> add($attr); + } + + // Add AX fetch request to authentication request + $auth -> addExtension($ax); + $_SESSION['returnURL'] = curPageURL(); + // Redirect to OpenID provider for authentication + $url = $auth -> redirectURL(getTrustRoot(), $_SESSION['returnURL']); + header('Location: ' . $url); + } + + +function auth() + +{ + if ($_SESSION['authed'] == true) return true; + + // Create file storage area for OpenID data + $store = new Auth_OpenID_FileStore('lib/openid-php/oid_store'); + // Create OpenID consumer + $consumer = new Auth_OpenID_Consumer($store); + // Create an authentication request to the OpenID provider + $response = $consumer -> complete($_SESSION['returnURL']); + + if ($response -> status == Auth_OpenID_SUCCESS) { + // Get registration informations + $ax = new Auth_OpenID_AX_FetchResponse(); + $obj = $ax -> fromSuccessResponse($response); + $email = $obj -> data['http://axschema.org/contact/email'][0]; + var_dump($email); + if ($email != "maxious@gmail.com") { + die("Access Denied"); + } else { + $_SESSION['authed'] = true; + } + } else { + login(); + } + } + if ($_REQUEST['janrain_nonce']) auth(); +?> --- a/include/common.inc.php +++ b/include/common.inc.php @@ -43,6 +43,7 @@ include_once ("common-request.inc.php"); include_once ("common-session.inc.php"); +include_once ("common-auth.inc.php"); include_once ("common-template.inc.php"); @@ -55,6 +56,7 @@ global $debugOkay; return in_array($debugReason, $debugOkay, false) && isDebugServer(); } + function debug($msg, $debugReason = "other") { if (isDebug($debugReason)) echo "\n\n"; @@ -187,5 +189,6 @@ } return implode( $glue, $retVal ); } + ?> --- a/include/db/trip-dao.inc.php +++ b/include/db/trip-dao.inc.php @@ -215,14 +215,14 @@ } return $query -> fetchAll(); } -function viaPoints($tripID, $stop_sequence = "") +function viaPoints($tripID, $stop_sequence = "", $timing_points_only = true) { global $conn; $query = "SELECT stops.stop_id, stop_name, arrival_time FROM stop_times join stops on stops.stop_id = stop_times.stop_id WHERE stop_times.trip_id = :tripID -" . ($stop_sequence != "" ? " AND stop_sequence > :stop_sequence " : "") . "AND substr(stop_code,1,2) != 'Wj' ORDER BY stop_sequence"; +" . ($stop_sequence != "" ? " AND stop_sequence > :stop_sequence " : "") . ($timing_points_only ? "AND substr(stop_code,1,2) != 'Wj' ": ""). " ORDER BY stop_sequence"; debug($query, "database"); $query = $conn -> prepare($query); if ($stop_sequence != "") $query -> bindParam(":stop_sequence", $stop_sequence); --- a/labs/index.php +++ b/labs/index.php @@ -1,6 +1,18 @@ +
  • Admin Features
  • +
  • myway_timeliness_calculate

    +

    myway_timeliness_calculate

  • +
  • myway_timeliness_reconcile

    +

    myway_timeliness_reconcile

  • +
  • servicealert_editor

    +

    servicealert_editor

  • + '; + } ?>