-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserDataProcessor.php
More file actions
93 lines (83 loc) · 2.88 KB
/
UserDataProcessor.php
File metadata and controls
93 lines (83 loc) · 2.88 KB
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
<?php
namespace Fab\Formule\Processor;
/*
* This file is part of the Fab/Formule project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory;
use TYPO3\CMS\Core\Crypto\PasswordHashing\SaltedPasswordsUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
/**
* Class UserDataProcessor.
* Only an example class to be copy / pasted and adjusted!!!
*/
class UserDataProcessor extends AbstractProcessor
{
/**
* @param array $values
* @param string $insertOrUpdate
* @return array
*/
public function process(array $values, string $insertOrUpdate = ''): array
{
$values['name'] = $values['first_name'] . ' ' . $values['last_name'];
if ($insertOrUpdate === ProcessorInterface::INSERT) {
$values['username'] = $values['email'];
$values['password'] = $this->getSaltedPassword($values['password']);
#$values['token'] = $this->getUuid(); // fields to be created...
#$values['is_confirmed'] = 0;
#$values['is_subscribed'] = 1;
} else {
if (empty($values['password'])) {
unset($values['password']);
} else {
$values['password'] = $this->getSaltedPassword($values['password']);
}
}
return $values;
}
/**
* @return string
*/
protected function getSaltedPassword($password): string
{
$saltedPassword = $password;
if (ExtensionManagementUtility::isLoaded('saltedpasswords')) {
if (SaltedPasswordsUtility::isUsageEnabled('FE')) {
$objSalt = PasswordHashFactory::getSaltingInstance(NULL);
if (is_object($objSalt)) {
$saltedPassword = $objSalt->getHashedPassword($password);
}
}
}
return $saltedPassword;
}
/**
* @see http://php.net/manual/en/function.uniqid.php#94959
* @return string
*/
//protected function getUuid()
//{
// return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// // 32 bits for "time_low"
// mt_rand(0, 0xffff), mt_rand(0, 0xffff),
//
// // 16 bits for "time_mid"
// mt_rand(0, 0xffff),
//
// // 16 bits for "time_hi_and_version",
// // four most significant bits holds version number 4
// mt_rand(0, 0x0fff) | 0x4000,
//
// // 16 bits, 8 bits for "clk_seq_hi_res",
// // 8 bits for "clk_seq_low",
// // two most significant bits holds zero and one for variant DCE1.1
// mt_rand(0, 0x3fff) | 0x8000,
//
// // 48 bits for "node"
// mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
// );
//}
}