Skip to content

Commit

Permalink
PR review changes; new dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Shayna Atkinson committed Sep 8, 2023
1 parent c125936 commit 52c1f62
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @link http://www.internet2.edu/comanage COmanage Project
* @package registry-plugin
* @since COmanage Registry v4.3.0
* @since COmanage Registry v4.4.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

Expand All @@ -38,16 +38,28 @@ class PaperTokensController extends SAMController {
);

/**
* Add a Standard Object.
* Add action to be used when adding a PaperToke as part of an Enrollment Flow
*
* @since COmanage Registry v4.3.0
* @since COmanage Registry v4.4.0
*/

public function add() {
$this->setAction('generate');
}

/**
* Generate a Paper Token (backup codes)
*
* @since COmanage Registry v4.4.0
*/

public function generate() {
if($this->request->is('get')) {

if(!$this->request->is('get')) {
throw new MethodNotAllowedException();
} else {
parent::add();

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

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

if(!empty($tokenInfo['otps'])) {
$this->set('vv_otps', (array)$tokenInfo['otps']);
debug($vv_otps);
}
}
catch(Exception $e) {
Expand All @@ -83,7 +94,7 @@ public function generate() {
/**
* Callback before other controller methods are invoked or views are rendered.
*
* @since COmanage Registry v4.3.0
* @since COmanage Registry v4.4.0
*/

public function beforeFilter() {
Expand All @@ -100,7 +111,7 @@ public function beforeFilter() {
* This method is intended to be overridden by model-specific controllers.
* - postcondition: Session flash message updated (HTML) or HTTP status returned (REST)
*
* @since COmanage Registry v4.3.0
* @since COmanage Registry v4.4.0
* @param Array Current data
* @return boolean true if dependency checks succeed, false otherwise.
*/
Expand Down Expand Up @@ -131,7 +142,7 @@ function checkDeleteDependencies($curdata) {
* try{} block so that HistoryRecord->record() may be called without worrying
* about catching exceptions.
*
* @since COmanage Registry v4.3.0
* @since COmanage Registry v4.4.0
* @param String Controller action causing the change
* @param Array Data provided as part of the action (for add/edit)
* @param Array Previous data (for delete/edit)
Expand Down Expand Up @@ -172,7 +183,7 @@ public function generateHistory($action, $newdata, $olddata) {
* - precondition: Session.Auth holds data used for authz decisions
* - postcondition: $permissions set with calculated permissions
*
* @since COmanage Registry v4.3.0
* @since COmanage Registry v4.4.0
* @return Array Permissions
*/

Expand All @@ -195,4 +206,4 @@ function isAuthorized() {
$this->set('permissions', $p);
return($p[$this->action]);
}
}
}
5 changes: 4 additions & 1 deletion app/AvailablePlugin/PrivacyIdeaAuthenticator/Lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,8 @@
'pl.privacyideaauthenticator.totp.step2' => 'Then, enter the current code from the Google Authenticator app to confirm',
'pl.privacyideaauthenticator.paper.intro' => 'Use the backup codes in order, one after the other. Mark off used values.',
'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',
'pl.privacyideaauthenticator.paper.warning' => 'Before you leave this page, please confirm that you have copied your backup codes. YOU WILL NOT SEE THEM AGAIN.'
'pl.privacyideaauthenticator.paper.warning' => 'Before you leave this page, please confirm that you have copied your backup codes. YOU WILL NOT SEE THEM AGAIN.',
'pl.privacyideaauthenticator.paper.dialog' => 'Before you leave this page you must save your backup codes by copying or printing.',
'pl.privacyideaauthenticator.paper.dialog.btn' => 'I understand',
'pl.privacyideaauthenticator.paper.continue' => 'Once you have copied your backup codes, you must continue to the next step',
);
Original file line number Diff line number Diff line change
Expand Up @@ -204,25 +204,23 @@ public function createToken($privacyIdeaAuthenticator, $coPersonId) {
case PrivacyIDEATokenTypeEnum::TOTP:
$token['confirmed'] = false;
$TotpToken = new TotpToken();
$TotpToken->save($token);

if (!$TotpToken->save($token)) {
throw new RuntimeException(_txt('er.db.save-a', array('TotpToken')));
}
// We don't persist the QR Data, but we do need to return it for rendering
$token['qr_data'] = $jresponse->detail->googleurl->img;
break;

case PrivacyIDEATokenTypeEnum::Paper:
$PaperToken = new PaperToken();
$PaperToken->save($token);

if (!$PaperToken->save($token)) {
throw new RuntimeException(_txt('er.db.save-a', array('PaperToken')));
}
// We don't persist the codes themselves but need to present them to the user for copying/printing
$token['otps'] = (array)$jresponse->detail->otps;
break;
}

if(!$jresponse->result->status) {
throw new RuntimeException($jresponse->result->error->message);
}

return $token;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function current($id, $backendId, $coPersonId) {
$results = $this->TotpToken->find('all', $args);

if(empty($results)) {
unset($args);
$args = array();
$args['conditions']['PaperToken.co_person_id'] = $coPersonId;
$args['conditions']['PaperToken.privacy_idea_authenticator_id'] = $backendId;
$args['contain'] = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @link http://www.internet2.edu/comanage COmanage Project
* @package registry-plugin
* @since COmanage Registry v4.3.0
* @since COmanage Registry v4.4.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/
-->
Expand Down Expand Up @@ -55,6 +55,9 @@
<div class="co-info-topbox warn-level-a">
<em class="material-icons error">warning</em>
<?php print _txt('pl.privacyideaauthenticator.paper.warning'); ?>
<?php if(!empty($this->request->params['named']['onFinish'])): ?>
<?php print _txt('pl.privacyideaauthenticator.paper.continue'); ?>
<?php endif; ?>
</div>
<style>
#add_paper_token {
Expand All @@ -75,44 +78,67 @@
}
}
</style>
<div class="table-container">
<table id="<?php print $this->action; ?>_paper_token" class="common-table">
<thead>
<div class="table-container">
<table id="<?php print $this->action; ?>_paper_token" class="common-table">
<thead>
<tr>
<th>#</th>
<th>OTP</th>
</tr>
</thead>
<tbody>
<?php foreach($vv_token_info['otps'] as $i => $otp): ?>
<tr>
<td><?php print $i+1; ?></td>
<td><?php print $otp; ?></td>
</tr>
<?php endforeach; ?>

</tbody>
</table>
</div>
<button type="button" onclick="window.print();" id="cm-print-button" class="btn btn-primary btn-lg">print backup codes</button>
<th>#</th>
<th>OTP</th>
</tr>
</thead>
<tbody>
<?php foreach($vv_token_info['otps'] as $i => $otp): ?>
<tr>
<td><?php print $i+1; ?></td>
<td><?php print $otp; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php if(!empty($this->request->params['named']['onFinish'])): ?>
<?php
print $this->Html->link(_txt('op.cont'),
urldecode($this->request->params['named']['onFinish']),
array('class' => 'btn btn-primary btn-lg'));
?>
<button type="button" onclick="window.print();" id="cm-print-button" class="btn btn-default btn-lg">print backup codes</button>
<?php else: ?>
<button type="button" onclick="window.print();" id="cm-print-button" class="btn btn-primary btn-lg">print backup codes</button>
<?php endif; ?>
<div id="bc-dialog" role="alertdialog" class="ui-dialog-content ui-widget-content">
<p>
<span class="ui-icon ui-icon-alert co-alert"></span>
<span id="dialog-text"><?php print _txt('pl.privacyideaauthenticator.paper.dialog'); ?></span>
</p>
</div>
<?php elseif($this->action == 'view'): ?>
<ul id="<?php print $this->action; ?>_paper_token" class="fields form-list">
<li>
<div class="field-name">
<?php print _txt('pl.privacyideaauthenticator.fd.serial'); ?>
</div>
<div class="field-info">
<?php
print filter_var($paper_tokens[0]['PaperToken']['serial'],FILTER_SANITIZE_SPECIAL_CHARS);
?>
</div>
</li>
</ul>
<ul id="<?php print $this->action; ?>_paper_token" class="fields form-list">
<li>
<div class="field-name">
<?php print _txt('pl.privacyideaauthenticator.fd.serial'); ?>
</div>
<div class="field-info">
<?php
print filter_var($paper_tokens[0]['PaperToken']['serial'],FILTER_SANITIZE_SPECIAL_CHARS);
?>
</div>
</li>
</ul>
<?php endif; // vv_otps, view ?>

<script>
window.onbeforeunload = function(e) {
// A value must be returned in order to prompt the user, but for security reasons we cannot control the actual prompt
e.preventDefault();
e.returnValue = "Before you leave this page, please confirm that you've copied your backup codes. YOU WILL NOT SEE THEM AGAIN.";
}
$(function() {
$("#bc-dialog").dialog({
autoOpen: true,
resizable: false,
modal: true,
title: 'Notice',
buttons: {
'<?php print _txt('pl.privacyideaauthenticator.paper.dialog.btn'); ?>': function() {
$(this).dialog('close');
}
}
});
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @link http://www.internet2.edu/comanage COmanage Project
* @package registry-plugin
* @since COmanage Registry v4.3.0
* @since COmanage Registry v4.4.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

Expand Down
4 changes: 2 additions & 2 deletions app/Config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@
*/
App::uses('CakeLog', 'Log');
CakeLog::config('debug', array(
'engine' => 'FileLog',
'engine' => 'ConsoleLog',
'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'FileLog',
'engine' => 'ConsoleLog',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'error',
));
Expand Down

0 comments on commit 52c1f62

Please sign in to comment.