public static function createServiceProvider($useManyToMany) { self::$fileProcessor = new NullFileProcessor(); $app = self::createAppAndDB($useManyToMany); $crudServiceProvider = new ServiceProvider(); $dataFactory = new MySQLDataFactory($app['db']); $crudFile = __DIR__ . '/../' . ($useManyToMany ? 'crudManyToMany.yml' : 'crud.yml'); $crudServiceProvider->init($dataFactory, $crudFile, self::$fileProcessor, true, $app); $userSetup = new UserSetup(); $userSetup->addEvents($crudServiceProvider->getData('user')); return $crudServiceProvider; }
/** * Creates a password reset request. * * @param string $identifyingField * the identifying field to grab an user, likely the email * @param string $identifyingValue * the identifying value to grab an user, likely the email * * @return null|string * the token of the password reset instance ready to be send to the user via * a secondary channel like email; might be null if the user could not be * identified uniquly via the given parameters: either zero or more than one * users were found */ public function requestPasswordReset($identifyingField, $identifyingValue) { $users = $this->userData->listEntries([$identifyingField => $identifyingValue]); if (count($users) !== 1) { return null; } $user = $users[0]; $userSetup = new UserSetup(); do { $token = $userSetup->getSalt(32); $tokenFound = $this->passwordResetData->countBy($this->passwordResetData->getDefinition()->getTable(), ['token' => $token], ['token' => '='], true) === 0; } while (!$tokenFound); $passwordReset = $this->passwordResetData->createEmpty(); $passwordReset->set('user', $user->get('id')); $passwordReset->set('token', $token); $this->passwordResetData->create($passwordReset); return $token; }
public function testPossibleGenSalt() { $password = '******'; $user = $this->dataUser->createEmpty(); $user->set('username', 'user1'); $user->set('password', $password); $user->set('email', '*****@*****.**'); $this->dataUser->create($user); $userSetup = new UserSetup(); $salt = 'test'; $read = $userSetup->possibleGenSalt($salt, $user, 'salt'); $this->assertFalse($read); $salt = null; $read = $userSetup->possibleGenSalt($salt, $user, 'salt'); $this->assertTrue($read); $read = $user->get('salt'); $this->assertNotEmpty($read); }