[TASK] Clean up phpDoc comments in typo3/sysext/rsaauth
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / hooks / class.tx_rsaauth_usersetuphook.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Helmut Hummel <helmut.hummel@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * This class provides a hook to the login form to add extra javascript code
27 * and supply a proper form tag.
28 *
29 * @author Helmut Hummel <helmut.hummel@typo3.org>
30 * @package TYPO3
31 * @subpackage tx_rsaauth
32 */
33 class tx_rsaauth_usersetuphook {
34
35 /**
36 * Decrypt the password fields if they are filled.
37 *
38 * @param array $parameters Parameters to the script
39 * @return void
40 */
41 public function decryptPassword(array $parameters) {
42
43 if ($this->isRsaAvailable()) {
44 $be_user_data = &$parameters['be_user_data'];
45
46 if (substr($be_user_data['password'], 0, 4) === 'rsa:' && substr($be_user_data['password2'], 0, 4) === 'rsa:') {
47 $backend = tx_rsaauth_backendfactory::getBackend();
48 /** @var $storage tx_rsaauth_abstract_storage */
49 $storage = tx_rsaauth_storagefactory::getStorage();
50
51 $key = $storage->get();
52
53 $password = $backend->decrypt($key, substr($be_user_data['password'], 4));
54 $password2 = $backend->decrypt($key, substr($be_user_data['password2'], 4));
55
56 $be_user_data['password'] = $password ? $password : $be_user_data['password'];
57 $be_user_data['password2'] = $password2 ? $password2 : $be_user_data['password2'];
58 }
59 }
60 }
61
62
63 /**
64 * Provides form code and javascript for the user setup.
65 *
66 * @param array $parameters Parameters to the script
67 * @param SC_index $userSetupObject Calling object: user setup module
68 * @return string The code for the user setup
69 */
70 public function getLoginScripts(array $parameters, SC_mod_user_setup_index $userSetupObject) {
71 $content = '';
72 if ($this->isRsaAvailable()) {
73 // If we can get the backend, we can proceed
74 $backend = tx_rsaauth_backendfactory::getBackend();
75
76 $javascriptPath = t3lib_extMgm::siteRelPath('rsaauth') . 'resources/';
77 $files = array(
78 'jsbn/jsbn.js',
79 'jsbn/prng4.js',
80 'jsbn/rng.js',
81 'jsbn/rsa.js',
82 'jsbn/base64.js',
83 'rsaauth_min.js'
84 );
85
86 $content = '';
87 foreach ($files as $file) {
88 $content .= '<script type="text/javascript" src="' .
89 t3lib_div::getIndpEnv('TYPO3_SITE_URL') .
90 $javascriptPath . $file . '"></script>';
91 }
92 // Generate a new key pair
93 $keyPair = $backend->createNewKeyPair();
94
95 // Save private key
96 $storage = tx_rsaauth_storagefactory::getStorage();
97 /** @var $storage tx_rsaauth_abstract_storage */
98 $storage->put($keyPair->getPrivateKey());
99
100 // Add form tag
101 $form = '<form action="' . t3lib_BEfunc::getModuleUrl('user_setup') . '" method="post" name="usersetup" enctype="application/x-www-form-urlencoded" onsubmit="tx_rsaauth_encryptUserSetup();">';
102 // Add RSA hidden fields
103 $form .= '<input type="hidden" id="rsa_n" name="n" value="' . htmlspecialchars($keyPair->getPublicKeyModulus()) . '" />';
104 $form .= '<input type="hidden" id="rsa_e" name="e" value="' . sprintf('%x', $keyPair->getExponent()) . '" />';
105
106 $userSetupObject->doc->form = $form;
107 }
108 return $content;
109 }
110
111 /**
112 * Rsa is available if loginSecurityLevel is set and rsa backend is working.
113 *
114 * @return boolean
115 */
116 protected function isRsaAvailable() {
117 return (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) === 'rsa') && (tx_rsaauth_backendfactory::getBackend() !== NULL);
118 }
119 }
120 ?>