2323use PKP \form \validation \FormValidatorPost ;
2424use PKP \form \validation \FormValidatorCSRF ;
2525use PKP \form \validation \FormValidatorCustom ;
26+ use APP \plugins \generic \scieloScreening \classes \APIKeyEncryption ;
2627
2728class ScieloScreeningSettingsForm extends Form
2829{
@@ -31,15 +32,19 @@ class ScieloScreeningSettingsForm extends Form
3132 'orcidClientId ' => 'string ' ,
3233 'orcidClientSecret ' => 'string ' ,
3334 );
34-
3535 public $ contextId ;
3636 public $ plugin ;
37+ private $ encrypter ;
3738
3839 public function __construct ($ plugin , $ contextId )
3940 {
4041 $ this ->contextId = $ contextId ;
4142 $ this ->plugin = $ plugin ;
42- parent ::__construct ($ plugin ->getTemplateResource ('settingsForm.tpl ' ));
43+ $ this ->encrypter = new APIKeyEncryption ();
44+
45+ $ template = $ this ->encrypter ->secretConfigExists () ? 'settingsForm.tpl ' : 'settingsFormEmptySecret.tpl ' ;
46+ parent ::__construct ($ plugin ->getTemplateResource ($ template ));
47+
4348 $ this ->addCheck (new FormValidatorPost ($ this ));
4449 $ this ->addCheck (new FormValidatorCSRF ($ this ));
4550
@@ -59,8 +64,17 @@ public function initData()
5964 $ contextId = $ this ->contextId ;
6065 $ plugin = &$ this ->plugin ;
6166 $ this ->_data = array ();
67+
6268 foreach (self ::CONFIG_VARS as $ configVar => $ type ) {
63- $ this ->_data [$ configVar ] = $ plugin ->getSetting ($ contextId , $ configVar );
69+ $ settingValue = $ plugin ->getSetting ($ contextId , $ configVar );
70+
71+ if ($ configVar == 'orcidClientId ' || $ configVar == 'orcidClientSecret ' ) {
72+ if (!empty ($ settingValue ) && $ this ->encrypter ->textIsEncrypted ($ settingValue )) {
73+ $ settingValue = $ this ->encrypter ->decryptString ($ settingValue );
74+ }
75+ }
76+
77+ $ this ->_data [$ configVar ] = $ settingValue ;
6478 }
6579 }
6680
@@ -86,7 +100,8 @@ public function execute(...$functionArgs)
86100 if ($ configVar === 'orcidAPIPath ' ) {
87101 $ plugin ->updateSetting ($ contextId , $ configVar , trim ($ this ->getData ($ configVar ), "\"\'; " ), $ type );
88102 } else {
89- $ plugin ->updateSetting ($ contextId , $ configVar , $ this ->getData ($ configVar ), $ type );
103+ $ encryptedValue = $ this ->encrypter ->encryptString ($ this ->getData ($ configVar ));
104+ $ plugin ->updateSetting ($ contextId , $ configVar , $ encryptedValue , $ type );
90105 }
91106 }
92107
0 commit comments