Skip to content

Commit 52c1f62

Browse files
committed
PR review changes; new dialog
1 parent c125936 commit 52c1f62

7 files changed

Lines changed: 99 additions & 61 deletions

File tree

app/AvailablePlugin/PrivacyIdeaAuthenticator/Controller/PaperTokensController.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @link http://www.internet2.edu/comanage COmanage Project
2323
* @package registry-plugin
24-
* @since COmanage Registry v4.3.0
24+
* @since COmanage Registry v4.4.0
2525
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
2626
*/
2727

@@ -38,16 +38,28 @@ class PaperTokensController extends SAMController {
3838
);
3939

4040
/**
41-
* Add a Standard Object.
41+
* Add action to be used when adding a PaperToke as part of an Enrollment Flow
4242
*
43-
* @since COmanage Registry v4.3.0
43+
* @since COmanage Registry v4.4.0
44+
*/
45+
46+
public function add() {
47+
$this->setAction('generate');
48+
}
49+
50+
/**
51+
* Generate a Paper Token (backup codes)
52+
*
53+
* @since COmanage Registry v4.4.0
4454
*/
4555

4656
public function generate() {
47-
if($this->request->is('get')) {
57+
58+
if(!$this->request->is('get')) {
59+
throw new MethodNotAllowedException();
60+
} else {
4861
parent::add();
4962

50-
//$this->set('title_for_layout', 'Generated '.$this->viewVars['vv_authenticator']['Authenticator']['description']);
5163
$this->set('title_for_layout', 'Generated Backup Codes');
5264

5365
if(!empty($this->request->params['named']['onFinish'])) {
@@ -71,7 +83,6 @@ public function generate() {
7183

7284
if(!empty($tokenInfo['otps'])) {
7385
$this->set('vv_otps', (array)$tokenInfo['otps']);
74-
debug($vv_otps);
7586
}
7687
}
7788
catch(Exception $e) {
@@ -83,7 +94,7 @@ public function generate() {
8394
/**
8495
* Callback before other controller methods are invoked or views are rendered.
8596
*
86-
* @since COmanage Registry v4.3.0
97+
* @since COmanage Registry v4.4.0
8798
*/
8899

89100
public function beforeFilter() {
@@ -100,7 +111,7 @@ public function beforeFilter() {
100111
* This method is intended to be overridden by model-specific controllers.
101112
* - postcondition: Session flash message updated (HTML) or HTTP status returned (REST)
102113
*
103-
* @since COmanage Registry v4.3.0
114+
* @since COmanage Registry v4.4.0
104115
* @param Array Current data
105116
* @return boolean true if dependency checks succeed, false otherwise.
106117
*/
@@ -131,7 +142,7 @@ function checkDeleteDependencies($curdata) {
131142
* try{} block so that HistoryRecord->record() may be called without worrying
132143
* about catching exceptions.
133144
*
134-
* @since COmanage Registry v4.3.0
145+
* @since COmanage Registry v4.4.0
135146
* @param String Controller action causing the change
136147
* @param Array Data provided as part of the action (for add/edit)
137148
* @param Array Previous data (for delete/edit)
@@ -172,7 +183,7 @@ public function generateHistory($action, $newdata, $olddata) {
172183
* - precondition: Session.Auth holds data used for authz decisions
173184
* - postcondition: $permissions set with calculated permissions
174185
*
175-
* @since COmanage Registry v4.3.0
186+
* @since COmanage Registry v4.4.0
176187
* @return Array Permissions
177188
*/
178189

@@ -195,4 +206,4 @@ function isAuthorized() {
195206
$this->set('permissions', $p);
196207
return($p[$this->action]);
197208
}
198-
}
209+
}

app/AvailablePlugin/PrivacyIdeaAuthenticator/Lib/lang.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,8 @@
7474
'pl.privacyideaauthenticator.totp.step2' => 'Then, enter the current code from the Google Authenticator app to confirm',
7575
'pl.privacyideaauthenticator.paper.intro' => 'Use the backup codes in order, one after the other. Mark off used values.',
7676
'pl.privacyideaauthenticator.paper.caution' => 'Backup codes are a weak second factor. Please assure no one has access to these values. Store them in a safe location',
77-
'pl.privacyideaauthenticator.paper.warning' => 'Before you leave this page, please confirm that you have copied your backup codes. YOU WILL NOT SEE THEM AGAIN.'
77+
'pl.privacyideaauthenticator.paper.warning' => 'Before you leave this page, please confirm that you have copied your backup codes. YOU WILL NOT SEE THEM AGAIN.',
78+
'pl.privacyideaauthenticator.paper.dialog' => 'Before you leave this page you must save your backup codes by copying or printing.',
79+
'pl.privacyideaauthenticator.paper.dialog.btn' => 'I understand',
80+
'pl.privacyideaauthenticator.paper.continue' => 'Once you have copied your backup codes, you must continue to the next step',
7881
);

app/AvailablePlugin/PrivacyIdeaAuthenticator/Model/PrivacyIdea.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,23 @@ public function createToken($privacyIdeaAuthenticator, $coPersonId) {
204204
case PrivacyIDEATokenTypeEnum::TOTP:
205205
$token['confirmed'] = false;
206206
$TotpToken = new TotpToken();
207-
$TotpToken->save($token);
208-
207+
if (!$TotpToken->save($token)) {
208+
throw new RuntimeException(_txt('er.db.save-a', array('TotpToken')));
209+
}
209210
// We don't persist the QR Data, but we do need to return it for rendering
210211
$token['qr_data'] = $jresponse->detail->googleurl->img;
211212
break;
212213

213214
case PrivacyIDEATokenTypeEnum::Paper:
214215
$PaperToken = new PaperToken();
215-
$PaperToken->save($token);
216-
216+
if (!$PaperToken->save($token)) {
217+
throw new RuntimeException(_txt('er.db.save-a', array('PaperToken')));
218+
}
217219
// We don't persist the codes themselves but need to present them to the user for copying/printing
218220
$token['otps'] = (array)$jresponse->detail->otps;
219221
break;
220222
}
221223

222-
if(!$jresponse->result->status) {
223-
throw new RuntimeException($jresponse->result->error->message);
224-
}
225-
226224
return $token;
227225
}
228226

app/AvailablePlugin/PrivacyIdeaAuthenticator/Model/PrivacyIdeaAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function current($id, $backendId, $coPersonId) {
147147
$results = $this->TotpToken->find('all', $args);
148148

149149
if(empty($results)) {
150-
unset($args);
150+
$args = array();
151151
$args['conditions']['PaperToken.co_person_id'] = $coPersonId;
152152
$args['conditions']['PaperToken.privacy_idea_authenticator_id'] = $backendId;
153153
$args['contain'] = false;

app/AvailablePlugin/PrivacyIdeaAuthenticator/View/PaperTokens/generate.ctp

Lines changed: 63 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @link http://www.internet2.edu/comanage COmanage Project
2323
* @package registry-plugin
24-
* @since COmanage Registry v4.3.0
24+
* @since COmanage Registry v4.4.0
2525
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
2626
*/
2727
-->
@@ -55,6 +55,9 @@
5555
<div class="co-info-topbox warn-level-a">
5656
<em class="material-icons error">warning</em>
5757
<?php print _txt('pl.privacyideaauthenticator.paper.warning'); ?>
58+
<?php if(!empty($this->request->params['named']['onFinish'])): ?>
59+
<?php print _txt('pl.privacyideaauthenticator.paper.continue'); ?>
60+
<?php endif; ?>
5861
</div>
5962
<style>
6063
#add_paper_token {
@@ -75,44 +78,67 @@
7578
}
7679
}
7780
</style>
78-
<div class="table-container">
79-
<table id="<?php print $this->action; ?>_paper_token" class="common-table">
80-
<thead>
81+
<div class="table-container">
82+
<table id="<?php print $this->action; ?>_paper_token" class="common-table">
83+
<thead>
8184
<tr>
82-
<th>#</th>
83-
<th>OTP</th>
84-
</tr>
85-
</thead>
86-
<tbody>
87-
<?php foreach($vv_token_info['otps'] as $i => $otp): ?>
88-
<tr>
89-
<td><?php print $i+1; ?></td>
90-
<td><?php print $otp; ?></td>
91-
</tr>
92-
<?php endforeach; ?>
93-
94-
</tbody>
95-
</table>
96-
</div>
97-
<button type="button" onclick="window.print();" id="cm-print-button" class="btn btn-primary btn-lg">print backup codes</button>
85+
<th>#</th>
86+
<th>OTP</th>
87+
</tr>
88+
</thead>
89+
<tbody>
90+
<?php foreach($vv_token_info['otps'] as $i => $otp): ?>
91+
<tr>
92+
<td><?php print $i+1; ?></td>
93+
<td><?php print $otp; ?></td>
94+
</tr>
95+
<?php endforeach; ?>
96+
</tbody>
97+
</table>
98+
</div>
99+
<?php if(!empty($this->request->params['named']['onFinish'])): ?>
100+
<?php
101+
print $this->Html->link(_txt('op.cont'),
102+
urldecode($this->request->params['named']['onFinish']),
103+
array('class' => 'btn btn-primary btn-lg'));
104+
?>
105+
<button type="button" onclick="window.print();" id="cm-print-button" class="btn btn-default btn-lg">print backup codes</button>
106+
<?php else: ?>
107+
<button type="button" onclick="window.print();" id="cm-print-button" class="btn btn-primary btn-lg">print backup codes</button>
108+
<?php endif; ?>
109+
<div id="bc-dialog" role="alertdialog" class="ui-dialog-content ui-widget-content">
110+
<p>
111+
<span class="ui-icon ui-icon-alert co-alert"></span>
112+
<span id="dialog-text"><?php print _txt('pl.privacyideaauthenticator.paper.dialog'); ?></span>
113+
</p>
114+
</div>
98115
<?php elseif($this->action == 'view'): ?>
99-
<ul id="<?php print $this->action; ?>_paper_token" class="fields form-list">
100-
<li>
101-
<div class="field-name">
102-
<?php print _txt('pl.privacyideaauthenticator.fd.serial'); ?>
103-
</div>
104-
<div class="field-info">
105-
<?php
106-
print filter_var($paper_tokens[0]['PaperToken']['serial'],FILTER_SANITIZE_SPECIAL_CHARS);
107-
?>
108-
</div>
109-
</li>
110-
</ul>
116+
<ul id="<?php print $this->action; ?>_paper_token" class="fields form-list">
117+
<li>
118+
<div class="field-name">
119+
<?php print _txt('pl.privacyideaauthenticator.fd.serial'); ?>
120+
</div>
121+
<div class="field-info">
122+
<?php
123+
print filter_var($paper_tokens[0]['PaperToken']['serial'],FILTER_SANITIZE_SPECIAL_CHARS);
124+
?>
125+
</div>
126+
</li>
127+
</ul>
111128
<?php endif; // vv_otps, view ?>
129+
112130
<script>
113-
window.onbeforeunload = function(e) {
114-
// A value must be returned in order to prompt the user, but for security reasons we cannot control the actual prompt
115-
e.preventDefault();
116-
e.returnValue = "Before you leave this page, please confirm that you've copied your backup codes. YOU WILL NOT SEE THEM AGAIN.";
117-
}
131+
$(function() {
132+
$("#bc-dialog").dialog({
133+
autoOpen: true,
134+
resizable: false,
135+
modal: true,
136+
title: 'Notice',
137+
buttons: {
138+
'<?php print _txt('pl.privacyideaauthenticator.paper.dialog.btn'); ?>': function() {
139+
$(this).dialog('close');
140+
}
141+
}
142+
});
143+
});
118144
</script>

app/AvailablePlugin/PrivacyIdeaAuthenticator/View/PaperTokens/index.ctp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @link http://www.internet2.edu/comanage COmanage Project
2323
* @package registry-plugin
24-
* @since COmanage Registry v4.3.0
24+
* @since COmanage Registry v4.4.0
2525
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
2626
*/
2727

app/Config/bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@
128128
*/
129129
App::uses('CakeLog', 'Log');
130130
CakeLog::config('debug', array(
131-
'engine' => 'FileLog',
131+
'engine' => 'ConsoleLog',
132132
'types' => array('notice', 'info', 'debug'),
133133
'file' => 'debug',
134134
));
135135
CakeLog::config('error', array(
136-
'engine' => 'FileLog',
136+
'engine' => 'ConsoleLog',
137137
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
138138
'file' => 'error',
139139
));

0 commit comments

Comments
 (0)