-
Notifications
You must be signed in to change notification settings - Fork 2
/
ReviewerCreditsSettingsForm.inc.php
141 lines (122 loc) · 4.13 KB
/
ReviewerCreditsSettingsForm.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* @file plugins/generic/reviewerCredits/ReviewerCreditsSettingsForm.inc.php
*
* Copyright (c) 2015-2018 University of Pittsburgh
* Copyright (c) 2014-2018 Simon Fraser University
* Copyright (c) 2003-2018 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class ReviewerCreditsSettingsForm
* @ingroup plugins_generic_reviewerCredits
*
* @brief Form for site admins to modify ReviewerCredits plugin settings
*/
import('lib.pkp.classes.form.Form');
class ReviewerCreditsSettingsForm extends Form {
/** @var $contextId int */
var $contextId;
/** @var $plugin object */
var $plugin;
/** @var $passwdPlaceholder string */
var $passwdPlaceholder = '****************';
/**
* Constructor
* @param $plugin object
* @param $contextId int
*/
public function __construct($plugin, $contextId) {
$this->contextId = $contextId;
$this->plugin = $plugin;
if(method_exists($this->plugin, 'getTemplateResource')){
$constructArgument = $this->plugin->getTemplateResource('settingsForm.tpl');
}else{
$constructArgument = $this->plugin->getTemplateResourceName().':templates/settingsForm.tpl';
}
parent::__construct($constructArgument);
$this->addCheck(new FormValidator($this, 'reviewerCreditsJournalLogin', 'required', 'plugins.generic.reviewerCredits.manager.settings.rcLoginRequired'));
$this->addCheck(new FormValidator($this, 'reviewerCreditsJournalPassword', 'required', 'plugins.generic.reviewerCredits.manager.settings.rcPasswordRequired'));
$this->addCheck(new FormValidatorCustom(
$this, 'reviewerCreditsJournalLogin',
'required',
'plugins.generic.reviewerCredits.manager.settings.invalid',
Array($this, 'customValidator')
));
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
}
/**
* Initialize form data.
*/
public function initData() {
$contextId = $this->contextId;
$plugin =& $this->plugin;
$oldPasswd = $plugin->getSetting($contextId, 'reviewerCreditsJournalPassword');
if(empty($oldPasswd)){
$password = '';
}else{
$password = $this->passwdPlaceholder;
}
$this->_data = array(
'reviewerCreditsJournalLogin' => $plugin->getSetting($contextId, 'reviewerCreditsJournalLogin'),
'reviewerCreditsJournalPassword' => $password,
);
}
/**
* Assign form data to user-submitted data.
*/
public function readInputData() {
$this->readUserVars(array('reviewerCreditsJournalLogin'));
$this->readUserVars(array('reviewerCreditsJournalPassword'));
}
/**
* Fetch the form.
* @copydoc Form::fetch()
*/
public function fetch($request, $template = null, $display = false) {
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('pluginName', $this->plugin->getName());
return parent::fetch($request);
}
/**
* Save settings.
*/
public function execute() {
$plugin =& $this->plugin;
$contextId = $this->contextId;
$oldPasswd = $plugin->getSetting($contextId, 'reviewerCreditsJournalPassword');
$newPasswd = $this->getData('reviewerCreditsJournalPassword');
$plugin->updateSetting($contextId, 'reviewerCreditsJournalLogin', $this->getData('reviewerCreditsJournalLogin'), 'string');
if($newPasswd != $this->passwdPlaceholder && $newPasswd != $oldPasswd){
$plugin->updateSetting($contextId, 'reviewerCreditsJournalPassword', $this->getData('reviewerCreditsJournalPassword'), 'string');
}
}
/**
* Check credentials.
*/
public function customValidator($args){
$username = trim($args);
$plugin =& $this->plugin;
$contextId = $this->contextId;
$oldPasswd = $plugin->getSetting($contextId, 'reviewerCreditsJournalPassword');
$newPasswd = $this->getData('reviewerCreditsJournalPassword');
if(empty($username) || empty($newPasswd)){
$output = FALSE;
}else{
if($newPasswd != $this->passwdPlaceholder){
$password = $newPasswd;
}else{
$password = $oldPasswd;
}
$output = $plugin->verifyCredentials($username, $password);
}
if(!$output){
if(empty($oldPasswd)){
$this->_data['reviewerCreditsJournalPassword'] = '';
}else{
$this->_data['reviewerCreditsJournalPassword'] = $this->passwdPlaceholder;
}
}
return $output;
}
}