本文整理汇总了PHP中Nette\Utils\Random::generate方法的典型用法代码示例。如果您正苦于以下问题:PHP Random::generate方法的具体用法?PHP Random::generate怎么用?PHP Random::generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\Random
的用法示例。
在下文中一共展示了Random::generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateToken
/**
* @return string
*/
private function generateToken($random = NULL)
{
if ($random === NULL) {
$random = Nette\Utils\Random::generate(10);
}
return $random . base64_encode(sha1($this->getToken() . $random, TRUE));
}
示例2: create
public function create(Product $product, FileUpload $fileUpload)
{
switch ($fileUpload->getContentType()) {
case 'image/jpeg':
$suffix = 'jpg';
break;
case 'image/png':
$suffix = 'png';
break;
case 'image/gif':
$suffix = 'gif';
break;
default:
throw new EntityInvalidArgumentException(sprintf('File is of an unknown type %s.', $fileUpload->getContentType()));
}
$baseName = sprintf('%s-%%s.%s', Strings::webalize($product->getName()), $suffix);
do {
$fileName = sprintf($baseName, Random::generate(5, '0-9a-zA-Z'));
$path = sprintf('%s/%s', $this->imagesDir, $fileName);
} while (file_exists($path));
$fileUpload->move($path);
$image = new ProductImage($product, $fileName);
$this->createEntity($image);
$product->addImage($image);
return $image;
}
示例3: formSucceeded
/**
* Callback for ForgottenPasswordForm onSuccess event.
* @param Form $form
* @param ArrayHash $values
*/
public function formSucceeded(Form $form, $values)
{
$user = $this->userManager->findByEmail($values->email);
if (!$user) {
$form->addError('No user with given email found');
return;
}
$password = Nette\Utils\Random::generate(10);
$this->userManager->setNewPassword($user->id, $password);
try {
// !!! Never send passwords through email !!!
// This is only for demonstration purposes of Notejam.
// Ideally, you can create a unique link where user can change his password
// himself for limited amount of time, and then send the link.
$mail = new Nette\Mail\Message();
$mail->setFrom('noreply@notejamapp.com', 'Notejamapp');
$mail->addTo($user->email);
$mail->setSubject('New notejam password');
$mail->setBody(sprintf('Your new password: %s', $password));
$this->mailer->send($mail);
} catch (Nette\Mail\SendException $e) {
Debugger::log($e, Debugger::EXCEPTION);
$form->addError('Could not send email with new password');
}
}
示例4: sendFormSucceeded
function sendFormSucceeded(\Nette\Forms\BootstrapUIForm $form)
{
$email = $form->getValues()->email;
if ($form->values->layer == 'admin') {
$lostPass = $this->database->table("helpdesk_emails")->where("template", "lostpass-admin")->fetch();
} else {
$lostPass = $this->database->table("helpdesk_emails")->where("template", "lostpass-member")->fetch();
}
if (!\Nette\Utils\Validators::isEmail($email)) {
$this->presenter->flashMessage("Adresa je neplatná");
$this->presenter->redirect(":Front:Sign:lostpass");
}
$passwordGenerate = \Nette\Utils\Random::generate(12, "987654321zyxwvutsrqponmlkjihgfedcba");
if ($this->database->table('users')->where(array('email' => $email))->count() == 0) {
$this->flashMessage("E-mail nenalezen");
$this->presenter->redirect(":Front:Sign:lostpass");
}
$member = new \App\Model\MemberModel($this->database);
$member->setActivation($email, $passwordGenerate);
$latte = new \Latte\Engine();
$latte->setLoader(new \Latte\Loaders\StringLoader());
$params = array('code' => $passwordGenerate, 'email' => $email, 'settings' => $this->presenter->template->settings);
$mail = new \Nette\Mail\Message();
$mail->setFrom($this->presenter->template->settings['contacts:email:hq'])->addTo($email)->setSubject("Informace o novém hesle")->setHTMLBody($latte->renderToString($lostPass->body, $params));
$mailer = new \Nette\Mail\SendmailMailer();
$mailer->send($mail);
$this->presenter->flashMessage('Informace o zapomenutém hesle odeslány', 'success');
$this->presenter->redirect(this);
}
示例5: authenticate
/**
* @param array $credentials
* @return Identity
* @throws AuthenticationException
*/
public function authenticate(array $credentials)
{
$email = $credentials[0]['email'];
$user = $this->users->getUser($email);
if ($user === NULL && $this->autoRegister === FALSE || $user instanceof UserEntity && $user->getActive() == 0) {
throw new AuthenticationException("User '{$email}' not found.", self::IDENTITY_NOT_FOUND);
} else {
if ($user === NULL && $this->autoRegister === TRUE) {
$result = $this->users->register(array("login" => $email, "password" => Random::generate(), "name" => $credentials[0]['firstName'] . " " . $credentials[0]['lastName'], "firstname" => $credentials[0]['firstName'], "lastname" => $credentials[0]['lastName'], "lastLogged" => new DateTime(), "ip" => $_SERVER['REMOTE_ADDR']));
if ($result instanceof ContactEntity) {
return new Identity($result->getUserID(), $result->getUser()->getRole()->getName(), $result->getUser()->toArray());
} else {
throw new AuthenticationException("User '{$email}' cannot be registered.", self::IDENTITY_NOT_FOUND);
}
} else {
if ($user instanceof UserEntity) {
$user->setLastLogged(new DateTime());
$user->setIp($_SERVER['REMOTE_ADDR']);
$this->users->updateUser($user);
$data = $user->toArray();
unset($data['password']);
return new Identity($user->getUserID(), $user->getRole()->getName(), $data);
} else {
throw new AuthenticationException("User '{$email}' cannot be connected.", self::IDENTITY_NOT_FOUND);
}
}
}
}
示例6: generateHash
protected function generateHash()
{
do {
$hash = Nette\Utils\Random::generate(32);
} while ($this->getTable()->where([$this->tables['identityHash']['hash'] => $hash])->fetch());
return $hash;
}
示例7: generate
public function generate($length = self::DEFAULT_LENGTH, $charlist = self::DEFAULT_CHARLIST)
{
Validators::assert($length, 'integer', 'length');
if ($length < 1) {
throw new InvalidArgumentException("Length must be greater or equal 1, value '{$length}' given.");
}
return Random::generate($length, $charlist);
}
示例8: save
/**
* Save past text into database
* Return generated hash
* @param array $data
* @return string
*/
public function save($data)
{
$data->hash = Random::generate(6, '0-9a-zA-Z');
$data->inserted = $this->dateTime->getTimestamp();
$data->id_user = '';
$this->dtb->table('pastes')->insert($data);
return $data->hash;
}
示例9: nodeOpened
/**
* New node is found.
* @return bool
*/
public function nodeOpened(Latte\MacroNode $node)
{
$this->used = TRUE;
$node->isEmpty = FALSE;
$node->openingCode = Latte\PhpWriter::using($node)
->write('<?php if (Nette\Bridges\CacheLatte\CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>',
Nette\Utils\Random::generate()
);
}
示例10: macroVersion
/**
* generates random number for front assets versing
*/
public function macroVersion(MacroNode $node, PhpWriter $writer)
{
$length = 10;
$word = $node->tokenizer->fetchWord();
if (is_numeric($word)) {
$length = (int) $word;
}
return $writer->write(' ?>?' . Random::generate($length) . '<?php ');
}
示例11: nodeOpened
/**
* New node is found.
* @return bool
*/
public function nodeOpened(Latte\MacroNode $node)
{
if ($node->modifiers) {
throw new Latte\CompileException('Modifiers are not allowed in ' . $node->getNotation());
}
$this->used = TRUE;
$node->empty = FALSE;
$node->openingCode = Latte\PhpWriter::using($node)->write('<?php if (Nette\\Bridges\\CacheLatte\\CacheMacro::createCache($this->global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) { ?>', Nette\Utils\Random::generate());
}
示例12: nodeOpened
/**
* New node is found.
* @return bool
*/
public function nodeOpened(Latte\MacroNode $node)
{
if ($node->modifiers) {
trigger_error("Modifiers are not allowed in {{$node->name}}", E_USER_WARNING);
}
$this->used = TRUE;
$node->isEmpty = FALSE;
$node->openingCode = Latte\PhpWriter::using($node)->write('<?php if (Nette\\Bridges\\CacheLatte\\CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>', Nette\Utils\Random::generate());
}
示例13: createWorker
/**
* @return \Venne\Queue\Worker
*/
public function createWorker()
{
$id = Random::generate(20);
$this->configManager->lock();
$data = $this->configManager->loadConfigFile();
$data['worker'][$id] = array('id' => $id, 'state' => self::STATE_PAUSED, 'lastCheck' => null, 'lastJob' => null);
$this->configManager->saveConfigFile($data);
$this->configManager->unlock();
return $this->getWokrer($id);
}
示例14: computeUnsafeHash
/**
* @return string Password grade hash (do not store!)
*/
protected function computeUnsafeHash()
{
if ($this->getValue('hash', FALSE)) {
throw new InvalidStateException('Hash already set');
}
if (!$this->user) {
throw new InvalidArgumentException();
}
return md5($this->createdAt->format('u') . $this->user->email) . Random::generate(15);
}
示例15: actionIn
/**
* @param $key
* @throws BadRequestException
*/
public function actionIn($key)
{
$response = $this->api->call('scud', "SCUD_CheckAccess/{$key}");
if ($response['status'] === "OK") {
$identity = new Identity(Random::generate(32));
$this->getUser()->login($identity);
$this->redirect("Dashboard:default");
}
throw new BadRequestException();
}