本文整理汇总了PHP中Text::random方法的典型用法代码示例。如果您正苦于以下问题:PHP Text::random方法的具体用法?PHP Text::random怎么用?PHP Text::random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Text
的用法示例。
在下文中一共展示了Text::random方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _upload_image
public function _upload_image(Validate $array, $input)
{
if ($array->errors()) {
// Don't bother uploading
return;
}
// Get the image from the array
$image = $array[$input];
if (!Upload::valid($image) or !Upload::not_empty($image)) {
// No need to do anything right now
return;
}
if (Upload::valid($image) and Upload::type($image, $this->types)) {
$filename = strtolower(Text::random('alnum', 20)) . '.jpg';
if ($file = Upload::save($image, NULL, $this->directory)) {
Image::factory($file)->resize($this->width, $this->height, $this->resize)->save($this->directory . $filename);
// Update the image filename
$array[$input] = $filename;
// Delete the temporary file
unlink($file);
} else {
$array->error('image', 'failed');
}
} else {
$array->error('image', 'valid');
}
}
示例2: create_token
protected function create_token()
{
do {
$token = sha1(uniqid(Text::random('alnum', 32), TRUE));
} while (ORM::factory('user_token', array('token' => $token))->loaded());
return $token;
}
示例3: create_token
protected function create_token()
{
do {
$token = sha1(uniqid(Text::random('alnum', 32), true));
} while (ORM::factory('User_Token', ['token' => $token])->loaded());
return $token;
}
示例4: generate_challenge
/**
* Generates a new Captcha challenge.
*
* @return string The challenge answer
*/
public function generate_challenge()
{
// Complexity setting is used as character count
$text = Text::random('distinct', max(1, Captcha::$config['complexity']));
// Complexity setting is used as character count
return $text;
}
示例5: _login
/**
* Logs a user in.
*
* @param string $user : user email
* @param string password
* @param boolean enable autologin
* @return boolean
*/
protected function _login($user, $password, $remember)
{
if (!is_object($user)) {
$q = Doctrine_Query::create()->from('User u')->innerJoin('u.Roles r')->addWhere('u.email=?', $user)->addWhere('u.password=?', $password);
}
//die($q->getSqlQuery());
$user = $q->fetchOne();
//die(print_r($user->toArray()));
if ($user && $this->_is_in_db('login', $user->Roles, 'name')) {
if ($remember === TRUE) {
// Create a new autologin token
//$token = ORM::factory('user_token');
$token = new UserToken();
// Set token data
$token->user_id = $user->id;
$token->expires = time() + $this->_config['lifetime'];
$token->token = Text::random('alnum', 32);
$token->created = time();
$token->user_agent = sha1(Request::$user_agent);
$token->save();
$user->UserToken[] = $token;
// Set the autologin cookie
Cookie::set('authautologin', $token->token, $this->_config['lifetime']);
}
//update lastlogin
$user->logins++;
$user->last_login = time();
$user->save();
// Finish the login
$this->complete_login($user);
return TRUE;
}
// Login failed
return FALSE;
}
示例6: action_signup
public function action_signup()
{
$this->template->menu_signup = TRUE;
// Если залогинен, то перекидываем на дерево
if (Auth::instance()->logged_in()) {
$this->redirect(Route::url('user/id', array('user_id' => Auth::instance()->get_user()->id)));
}
$post = Arr::extract($this->request->post(), array('name', 'surname', 'email'));
$data['errors'] = NULL;
if ($this->request->method() == 'POST') {
// Генерирую случайный пароль из цифр
$post['password'] = Text::random('numeric', 5);
try {
$user = ORM::factory('User')->values($post)->save();
$user->add('roles', ORM::factory('Role', array('name' => 'login')));
$message = '
Для входа на сайт ' . $_SERVER['HTTP_HOST'] . ' используйте следующие данные:<br><br>
Адрес электронной почты: ' . HTML::chars($user->email) . '<br>
Пароль: ' . HTML::chars($post['password']) . '<br><br>
<a href="' . URL::base(TRUE) . '">Перейти на сайт</a>';
Useful::mail($user->email, 'Регистрация LiveTex', $message, 'LiveTex');
// Авторизовываю
Auth::instance()->login($user->email, $post['password'], TRUE);
$this->redirect(Route::url('user/id', array('user_id' => $user->id)));
} catch (ORM_Validation_Exception $e) {
$data['errors'] = $e->errors('orm');
}
}
$data += $post;
$this->template->content = View::factory('auth/signup', $data);
}
示例7: create_token
/**
* This function returns a new token.
*
* @access public
* @return string a new token
*/
public function create_token()
{
do {
$token = sha1(uniqid(Text::random('alnum', 32), TRUE));
} while (DB_SQL::select($this->data_source(DB_DataSource::SLAVE_INSTANCE))->from($this->table())->where('token', DB_SQL_Operator::_EQUAL_TO_, $token)->query()->is_loaded());
return $token;
}
示例8: executeCreate
protected function executeCreate(InputInterface $input, OutputInterface $output)
{
$client = $input->getOption('client');
$name = $input->getOption('name');
$secret = $input->getOption('secret');
if (!$client) {
// We can't use the generic `get_client()` for **creation**,
// because we need to verify that the user does **not** exist.
$clients = Arr::pluck(self::db_list(), 'id');
$ask = function ($client) use($clients) {
if (in_array($client, $clients)) {
throw new RuntimeException('Client "' . $client . '" already exists, try another name');
}
return $client;
};
$client = $this->getHelperSet()->get('dialog')->askAndValidate($output, 'Enter id of new client: ', $ask, FALSE);
}
if (!$name) {
$name = $client;
}
if (!$secret) {
$secret = Text::random('distinct', 24);
}
static::db_create(['id' => $client, 'secret' => $secret, 'name' => $name]);
$input->setOption('client', $client);
return $this->executeList($input, $output);
}
示例9: create_token
public static function create_token()
{
do {
$token = sha1(uniqid(Text::random('alnum', 32), TRUE));
} while (ORM::factory('Mail', array('token' => $token))->loaded());
return $token;
}
示例10: create_email
/**
* creates a user from email if exists doesn't...
* @param string $email
* @param string $name
* @param string $password
* @return Model_User
*/
public static function create_email($email, $name = NULL, $password = NULL)
{
$user = new self();
$user->where('email', '=', $email)->limit(1)->find();
if (!$user->loaded()) {
if ($password === NULL) {
$password = Text::random('alnum', 8);
}
$user->email = $email;
$user->name = ($name === NULL or !isset($name)) ? substr($email, 0, strpos($email, '@')) : $name;
$user->status = self::STATUS_ACTIVE;
$user->id_role = Model_Role::ROLE_USER;
$user->seoname = $user->gen_seo_title($user->name);
$user->password = $password;
$user->subscriber = 1;
$user->last_ip = ip2long(Request::$client_ip);
$user->country = euvat::country_code();
//geo info EU
try {
$user->save();
//send welcome email
$url = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'edit'), TRUE);
$user->email('auth-register', array('[USER.PWD]' => $password, '[URL.QL]' => $url));
} catch (ORM_Validation_Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
}
return $user;
}
示例11: save
public function save()
{
$user_id = $this->getData('user_id', null);
if (!$user_id) {
$data = $this->getData(['email', 'phone', 'password', 'name']);
if (empty($data['password'])) {
$data['password'] = \Text::random(6);
}
$names = $this->preparename($data['name']);
unset($data['name']);
$data = array_merge($data, $names);
$user_id = $this->model('User')->registration($data);
if ($user_id) {
$data = ['user_id' => $user_id, 'salary_password' => $data['password'], 'phone' => $data['phone'], 'email' => $data['email']];
$this->model('EmployeeData')->recruit($data);
}
return $this->model('EmployeeData')->getById($user_id);
} else {
$data = $this->getData(['email', 'phone', 'password']);
$user = $this->model('User')->getById($user_id);
$data = ['user_id' => $user_id, 'salary_password' => \Arr::get($data, 'password', $user['password']), 'phone' => \Arr::get($data, 'phone', $user['phone']), 'email' => \Arr::get($data, 'email', $user['email'])];
$this->model('EmployeeData')->recruit($data);
return $this->model('EmployeeData')->getById($user_id);
}
return;
}
示例12: action_bulk
/**
* CRUD controller: CREATE
*/
public function action_bulk()
{
$this->template->title = __('Bulk') . ' ' . __($this->_orm_model);
$this->template->styles = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/css/datepicker.css' => 'screen');
$this->template->scripts['footer'] = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/js/bootstrap-datepicker.js', 'js/oc-panel/coupon.js');
if ($this->request->post()) {
$id_product = Core::post('id_product');
$discount_amount = Core::post('discount_amount');
$discount_percentage = Core::post('discount_percentage');
$valid_date = Core::post('valid_date');
$number_coupons = Core::post('number_coupons');
for ($i = 0; $i < $number_coupons; $i++) {
$c = new Model_Coupon();
//get unique coupon name
do {
$c->name = strtoupper(Text::random('alnum', 8));
} while (ORM::factory('coupon', array('name' => $c->name))->limit(1)->loaded());
$c->id_product = $id_product;
$c->discount_amount = $discount_amount;
$c->discount_percentage = $discount_percentage;
$c->valid_date = $valid_date;
$c->number_coupons = 1;
$c->status = 1;
$c->save();
}
$this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller())));
}
return $this->render('oc-panel/pages/coupon/bulk', array('products' => $this->get_products()));
}
示例13: saveArchivo
public function saveArchivo($files)
{
$dir = DOCROOT . 'files';
$ext = pathinfo($files['name'], PATHINFO_EXTENSION);
$slug = strtolower(Text::random('alnum', 10)) . '.' . $ext;
$file = Upload::save($files, $slug, $dir);
return $slug;
}
示例14: save
public function save(Validation $validation = NULL)
{
if (!$this->loaded()) {
$this->hash = Text::random('alnum', rand(24, 32));
$this->created = time();
}
return parent::save($validation);
}
示例15: action_250
/**
* This function will upgrade DB that didn't existed in versions prior to 2.5.0
*/
public function action_250()
{
//new configs
$configs = array(array('config_key' => 'api_key', 'group_name' => 'general', 'config_value' => Text::random('alnum', 32)), array('config_key' => 'twocheckout_sid', 'group_name' => 'payment', 'config_value' => ''), array('config_key' => 'twocheckout_secretword', 'group_name' => 'payment', 'config_value' => ''), array('config_key' => 'twocheckout_sandbox', 'group_name' => 'payment', 'config_value' => 0), array('config_key' => 'messaging', 'group_name' => 'general', 'config_value' => 0), array('config_key' => 'gcm_apikey', 'group_name' => 'general', 'config_value' => ''));
Model_Config::config_array($configs);
//api token
try {
DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `api_token` varchar(40) DEFAULT NULL")->execute();
} catch (exception $e) {
}
try {
DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD CONSTRAINT `oc2_users_UK_api_token` UNIQUE (`api_token`)")->execute();
} catch (exception $e) {
}
//notification date
try {
DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `notification_date` DATETIME NULL DEFAULT NULL ;")->execute();
} catch (exception $e) {
}
//device ID
try {
DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `device_id` varchar(255) DEFAULT NULL")->execute();
} catch (exception $e) {
}
//crontab ad to expire
try {
DB::query(Database::UPDATE, "INSERT INTO `" . self::$db_prefix . "crontab` (`name`, `period`, `callback`, `params`, `description`, `active`) VALUES\n ('About to Expire Ad', '05 9 * * *', 'Cron_Ad::to_expire', NULL, 'Notify by email your ad is about to expire', 1);")->execute();
} catch (exception $e) {
}
//new mails
$contents = array(array('order' => 0, 'title' => 'Your ad [AD.NAME] is going to expire', 'seotitle' => 'ad-to-expire', 'description' => "Hello [USER.NAME],Your ad [AD.NAME] will expire soon \n\nPlease check your ad here [URL.EDITAD]", 'from_email' => core::config('email.notify_email'), 'type' => 'email', 'status' => '1'), array('order' => 0, 'title' => 'Password Changed [SITE.NAME]', 'seotitle' => 'password-changed', 'description' => "Hello [USER.NAME],\n\nYour password has been changed.\n\nThese are now your user details:\nEmail: [USER.EMAIL]\nPassword: [USER.PWD]\n\nWe do not have your original password anymore.\n\nRegards!", 'from_email' => core::config('email.notify_email'), 'type' => 'email', 'status' => '1'), array('order' => 0, 'title' => 'New reply: [TITLE]', 'seotitle' => 'messaging-reply', 'description' => '[URL.QL]\\n\\n[DESCRIPTION]', 'from_email' => core::config('email.notify_email'), 'type' => 'email', 'status' => '1'), array('order' => 0, 'title' => '[FROM.NAME] sent you a direct message', 'seotitle' => 'messaging-user-contact', 'description' => 'Hello [TO.NAME],\\n\\n[FROM.NAME] have a message for you:\\n\\n[DESCRIPTION]\\n\\n[URL.QL]\\n\\nRegards!', 'from_email' => core::config('email.notify_email'), 'type' => 'email', 'status' => '1'), array('order' => 0, 'title' => 'Hello [TO.NAME]!', 'seotitle' => 'messaging-ad-contact', 'description' => 'You have been contacted regarding your advertisement:\\n\\n`[AD.NAME]`.\\n\\nUser [FROM.NAME], have a message for you:\\n\\n[DESCRIPTION]\\n\\n[URL.QL]\\n\\nRegards!', 'from_email' => core::config('email.notify_email'), 'type' => 'email', 'status' => '1'));
Model_Content::content_array($contents);
//messages
try {
DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS " . self::$db_prefix . "messages (\n `id_message` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `id_ad` int(10) unsigned DEFAULT NULL,\n `id_message_parent` int(10) unsigned DEFAULT NULL,\n `id_user_from` int(10) unsigned NOT NULL,\n `id_user_to` int(10) unsigned NOT NULL,\n `message` text NOT NULL,\n `price` decimal(14,3) NOT NULL DEFAULT '0',\n `read_date` datetime DEFAULT NULL,\n `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `status` tinyint(1) NOT NULL DEFAULT 0,\n PRIMARY KEY (id_message) USING BTREE\n ) ENGINE=MyISAM ;")->execute();
} catch (exception $e) {
}
//coupons
try {
DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS `" . self::$db_prefix . "coupons` (\n `id_coupon` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `id_product` int(10) unsigned NULL DEFAULT NULL,\n `name` varchar(145) NOT NULL,\n `notes` varchar(245) DEFAULT NULL,\n `discount_amount` decimal(14,3) NOT NULL DEFAULT '0',\n `discount_percentage` decimal(14,3) NOT NULL DEFAULT '0',\n `number_coupons` int(10) DEFAULT NULL,\n `valid_date` DATETIME NULL,\n `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `status` tinyint(1) NOT NULL DEFAULT '0',\n PRIMARY KEY (`id_coupon`),\n UNIQUE KEY `" . self::$db_prefix . "coupons_UK_name` (`name`)\n ) ENGINE=MyISAM")->execute();
} catch (exception $e) {
}
try {
DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "orders` ADD `id_coupon` INT NULL DEFAULT NULL")->execute();
} catch (exception $e) {
}
//end coupons
//myads access
try {
DB::query(Database::UPDATE, "INSERT INTO `" . self::$db_prefix . "access` (`id_role`, `access`) VALUES \n (1, 'myads.*'),(5, 'myads.*'),(7, 'myads.*')")->execute();
} catch (exception $e) {
}
//messages access
try {
DB::query(Database::UPDATE, "INSERT INTO `" . self::$db_prefix . "access` (`id_role`, `access`) VALUES \n (1, 'messages.*'),(5, 'messages.*'),(7, 'messages.*')")->execute();
} catch (exception $e) {
}
}