Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 1e7f746

Browse files
author
Jamie Snape
committed
Revise googleauth module configuration form and add install script
1 parent 411438a commit 1e7f746

File tree

15 files changed

+238
-148
lines changed

15 files changed

+238
-148
lines changed

modules/googleauth/Notification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function init()
4141
*/
4242
public function googleAuthLink()
4343
{
44-
$clientId = $this->Setting->getValueByName('client_id', $this->moduleName);
44+
$clientId = $this->Setting->getValueByName(GOOGLE_AUTH_CLIENT_ID_KEY, $this->moduleName);
4545
$scheme = (array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS']) ? 'https://' : 'http://';
4646
$fc = Zend_Controller_Front::getInstance();
4747
$csrfToken = UtilityComponent::generateRandomString(30);
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
; MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
2+
13
[global]
2-
version = 1.0.0
3-
fullname = "Google OAuth"
4-
description = "Allow users to log in using their Google account"
5-
category = Authentication
4+
fullname = "Google Account Authentication"
5+
description = "Authenticate users using Google accounts"
6+
category = "Authentication"
67
dependencies = api
8+
uuid = "1f331c86-b1ca-4b42-ba49-5102aed4965e"
9+
version = "1.1.0"

modules/googleauth/constant/module.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,12 @@
1818
limitations under the License.
1919
=========================================================================*/
2020

21+
22+
define('GOOGLE_AUTH_CLIENT_ID_KEY', 'client_id');
23+
define('GOOGLE_AUTH_CLIENT_ID_DEFAULT_VALUE', '');
24+
25+
define('GOOGLE_AUTH_CLIENT_SECRET_KEY', 'client_secret');
26+
define('GOOGLE_AUTH_CLIENT_SECRET_DEFAULT_VALUE', '');
27+
2128
define('GOOGLE_AUTH_OAUTH2_URL', 'https://accounts.google.com/o/oauth2/token');
2229
define('GOOGLE_AUTH_PLUS_URL', 'https://www.googleapis.com/plus/v1/people/me');
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Admin controller for the googleauth module. */
22+
class Googleauth_AdminController extends Googleauth_AppController
23+
{
24+
/** @var array */
25+
public $_models = array('Setting');
26+
27+
/** Index action */
28+
public function indexAction()
29+
{
30+
$this->requireAdminPrivileges();
31+
32+
$this->view->pageTitle = 'Google Auth Module Configuration';
33+
$form = new Googleauth_Form_Admin();
34+
35+
if ($this->getRequest()->isPost()) {
36+
$data = $this->getRequest()->getPost();
37+
38+
if ($form->isValid($data)) {
39+
$values = $form->getValues();
40+
41+
foreach ($values as $key => $value) {
42+
$this->Setting->setConfig($key, $value, $this->moduleName);
43+
}
44+
}
45+
46+
$form->populate($data);
47+
} else {
48+
$elements = $form->getElements();
49+
50+
foreach ($elements as $element) {
51+
$name = $element->getName();
52+
53+
if ($name !== 'csrf' && $name !== 'submit') {
54+
$value = $this->Setting->getValueByName($name, $this->moduleName);
55+
56+
if (!is_null($value)) {
57+
$form->setDefault($name, $value);
58+
}
59+
}
60+
}
61+
}
62+
63+
$this->view->form = $form;
64+
session_start();
65+
}
66+
}

modules/googleauth/controllers/CallbackController.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public function indexAction()
7373
*/
7474
protected function _getUserInfo($code)
7575
{
76-
$clientId = $this->Setting->getValueByName('client_id', $this->moduleName);
77-
$clientSecret = $this->Setting->getValueByName('client_secret', $this->moduleName);
76+
$clientId = $this->Setting->getValueByName(GOOGLE_AUTH_CLIENT_ID_KEY, $this->moduleName);
77+
$clientSecret = $this->Setting->getValueByName(GOOGLE_AUTH_CLIENT_SECRET_KEY, $this->moduleName);
7878
$scheme = (array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS']) ? 'https://' : 'http://';
7979
$redirectUri = $scheme.$_SERVER['HTTP_HOST'].Zend_Controller_Front::getInstance()->getBaseUrl(
8080
).'/'.$this->moduleName.'/callback';
@@ -169,10 +169,8 @@ protected function _createOrGetUser($info)
169169
$user = $this->User->getByEmail($info['email']);
170170
if (!$user) {
171171
// Only create new user this way if registration is not closed.
172-
if (isset(Zend_Registry::get('configGlobal')->closeregistration) && Zend_Registry::get(
173-
'configGlobal'
174-
)->closeregistration == "1"
175-
) {
172+
$closeRegistration = Zend_Registry::get('configGlobal')->closeregistration;
173+
if ($closeRegistration == '1') {
176174
throw new Zend_Exception(
177175
'Access to this instance is by invitation '.'only, please contact an administrator.'
178176
);

modules/googleauth/controllers/ConfigController.php

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
require_once BASE_PATH.'/modules/googleauth/constant/module.php';
22+
23+
/** Install the googleauth module. */
24+
class Googleauth_InstallScript extends MIDASModuleInstallScript
25+
{
26+
/** @var string */
27+
public $moduleName = 'googleauth';
28+
29+
/** Post database install. */
30+
public function postInstall()
31+
{
32+
/** @var SettingModel $settingModel */
33+
$settingModel = MidasLoader::loadModel('Setting');
34+
$settingModel->setConfig(GOOGLE_AUTH_CLIENT_ID_KEY, GOOGLE_AUTH_CLIENT_ID_DEFAULT_VALUE, $this->moduleName);
35+
$settingModel->setConfig(GOOGLE_AUTH_CLIENT_SECRET_KEY, GOOGLE_AUTH_CLIENT_SECRET_DEFAULT_VALUE, $this->moduleName);
36+
}
37+
}

modules/googleauth/database/mysql/1.0.0.sql renamed to modules/googleauth/database/mysql/1.1.0.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
22

3-
-- MySQL database for the googleauth module, version 1.0.0
3+
-- MySQL database for the googleauth module, version 1.1.0
44

55
CREATE TABLE IF NOT EXISTS `googleauth_user` (
66
`googleauth_user_id` bigint(20) NOT NULL AUTO_INCREMENT,

modules/googleauth/database/pgsql/1.0.0.sql renamed to modules/googleauth/database/pgsql/1.1.0.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
22

3-
-- PostgreSQL database for the googleauth module, version 1.0.0
3+
-- PostgreSQL database for the googleauth module, version 1.1.0
44

55
SET client_encoding = 'UTF8';
66
SET default_with_oids = FALSE;

modules/googleauth/database/sqlite/1.0.0.sql renamed to modules/googleauth/database/sqlite/1.1.0.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
22

3-
-- SQLite database for the googleauth module, version 1.0.0
3+
-- SQLite database for the googleauth module, version 1.1.0
44

55
CREATE TABLE IF NOT EXISTS "googleauth_user" (
66
"googleauth_user_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,

0 commit comments

Comments
 (0)