本文整理汇总了PHP中Str::random方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::random方法的具体用法?PHP Str::random怎么用?PHP Str::random使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Str
的用法示例。
在下文中一共展示了Str::random方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: encrypt
/**
* 对明文进行加密
* @param string $text 需要加密的明文
* @return string 加密后的密文
*/
public function encrypt($text, $appid)
{
try {
//获得16位随机字符串,填充到明文之前
$random = \Str::random('alnum', 16);
$text = $random . pack("N", strlen($text)) . $text . $appid;
// 网络字节序
$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$iv = substr($this->key, 0, 16);
//使用自定义的填充方式对明文进行补位填充
$pkc_encoder = new PKCS7Encoder();
$text = $pkc_encoder->encode($text);
mcrypt_generic_init($module, $this->key, $iv);
//加密
$encrypted = mcrypt_generic($module, $text);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
//print(base64_encode($encrypted));
//使用BASE64对加密后的字符串进行编码
return array(ErrorCode::$OK, base64_encode($encrypted));
} catch (Exception $e) {
//print $e;
return array(ErrorCode::$EncryptAESError, null);
}
}
示例2: post_upload
public function post_upload()
{
$input = Input::get();
$file = Input::file('fileInput');
$separator = $input['claimdetailid'] != NULL ? $input['claimid'] . '/' . $input['claimdetailid'] : $input['claimid'];
$extension = File::extension($file['name']);
$directory = 'upload/claims/' . sha1(Auth::user()->userid) . '/' . str_replace("-", "", date('Y-m-d')) . '/' . $separator;
$filename = Str::random(16, 'alpha') . time() . ".{$extension}";
if (!is_dir(path('public') . $directory)) {
mkdir(path('public') . $directory, 0777, true);
}
$maxSize = ini_get('upload_max_filesize') * 1024 * 1024 * 1024;
if ($file['size'] != null && $file['size'] < $maxSize) {
try {
$upload_success = Input::upload('fileInput', path('public') . $directory, $filename);
if ($upload_success) {
$input['recpath'] = $directory . '/' . $filename;
$receipt = new Claims_Receipt();
$receipt->fill($input);
$receipt->save();
Log::write('Claims Receipt', 'File Uploaded : ' . $filename . ' by ' . Auth::user()->username);
return $directory . '/' . $filename;
}
} catch (Exception $e) {
Log::write('Claims Receipt', 'Upload error: ' . $e->getMessage());
}
} else {
Log::write('Claims Receipt', 'Upload error: Exceed max size ' . ini_get('upload_max_filesize'));
}
}
示例3: create
/**
* Create Agent
* @return \Illuminate\Http\JsonResponse
*/
public function create()
{
$success = false;
if ($this->validator->validate(\Input::all()) && $this->userValidator->validate(['email' => \Input::get('email'), 'password' => \Str::random(8)])) {
$user = User::create(['email' => \Input::get('email'), 'username' => \Input::get('name'), 'password' => \Str::random(8)]);
$agentData = \Input::all();
$agentData['user_id'] = $user->id;
// TODO: save uploaded image :|
// Destination path for uplaoded files which is at /public/uploads
$destinationPath = public_path() . '/uploads/img/';
// Handle profile Picture
if (Input::hasFile('profile_pic_filename')) {
$file = Input::file('profile_pic_filename');
$propic_filename = str_random(6) . '_' . str_replace(' ', '_', $file->getClientOriginalName());
$uploadSuccess = $file->move($destinationPath, $propic_filename);
if ($uploadSuccess) {
$agentData['profile_pic_filename'] = $propic_filename;
}
}
$agent = Agent::create($agentData);
// Send Invitation Email
$invitation_code = bin2hex(openssl_random_pseudo_bytes(16));
$invite = Invite::create(['code' => $invitation_code, 'email' => Input::get('email'), 'user_id' => $user->id, 'user_type' => 'Agent']);
Mail::send('emails.invitation.invite', ['confirmation' => $invitation_code, 'client_base_url' => 'http://d.motibu-head.com/'], function ($message) {
$message->to(Input::get('email'))->subject('You have been invited to motibu.com');
});
$user->roles()->attach(Role::findByName('Agent')->id);
$success = $user && $agent;
}
return \Response::json(['success' => $success, 'data' => $agent->getTransformed(new AgentTransformer())]);
}
示例4: create
/**
* Show the form for creating a new user.
*
* @return Response
*/
public function create()
{
$groups = $this->group->all();
$permissions = $this->permissions->allWithChecked();
$password = \Str::random(16);
$this->view('users.create', compact('groups', 'permissions', 'password'));
}
示例5: postRegistro
public function postRegistro()
{
$input = Input::all();
$reglas = array('nombre' => 'required', 'apellido' => 'required', 'celular' => 'required|numeric|unique:users', 'cedula' => 'required|numeric|unique:users', 'email' => 'required|email|unique:users', 'pin' => 'required|numeric|digits_between:0,4', 'password' => 'required|numbers|case_diff|letters|min:6|confirmed', 'password_confirmation' => 'required|min:6');
$validation = Validator::make($input, $reglas);
if ($validation->fails()) {
return Response::json(['success' => false, 'errors' => $validation->errors()->toArray()]);
}
try {
// se guarda los datos del usuario
$user = Sentry::register(array('first_name' => Input::get('nombre'), 'last_name' => Input::get('apellido'), 'email' => Input::get('email'), 'habilitar_pin' => 1, 'celular' => Input::get('celular'), 'cedula' => Input::get('cedula'), 'password' => Input::get('password'), 'pin' => Input::get('pin'), 'porcentaje' => 0.05, 'activated' => true));
$userId = $user->getId();
$token = new Token();
$token->user_id = $userId;
$token->api_token = hash('sha256', Str::random(10), false);
$token->client = BrowserDetect::toString();
$token->expires_on = Carbon::now()->addMonth()->toDateTimeString();
$token->save();
// Se autentica de una
$user_login = Sentry::findUserById($userId);
Sentry::login($user_login, false);
return Response::json(['success' => true, 'user' => $user_login, 'token' => $token->api_token]);
} catch (Cartalyst\Sentry\Users\LoginRequiredException $e) {
$error = array('usuario' => 'Email es requerido');
} catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) {
$error = array('usuario' => 'Password es requerido');
} catch (Cartalyst\Sentry\Users\UserExistsException $e) {
$error = array('usuario' => 'El Email ya está registrado');
}
return Response::json(['success' => false, 'errors' => $error]);
}
示例6: getPaymentCart
public function getPaymentCart()
{
$values = Session::get('payment');
foreach ($values as $key => $value) {
$product[$key]['name'] = $value['name'];
$price = round((int) $value['price'] / 21270);
$product[$key]['price'] = $price;
$product[$key]['quantity'] = 1;
$product[$key]['product_id'] = $value['id'];
}
$tmpTransaction = new TmpTransaction();
$st = Str::random(16);
$baseUrl = URL::to('/product/payment/return?order_id=' . $st);
// $value[1]['name'] = "sản phẩm 1";
// $value[1]['price'] = "20000";
// $value[1]['quantity'] = "1";
// $value[1]['product_id'] = "3";
// $value[2]['name'] = "sản phẩm 2";
// $value[2]['price'] = "20000";
// $value[2]['quantity'] = "1";
// $value[2]['product_id'] = "3";
$payment = $this->makePaymentUsingPayPalCart($product, 'USD', "{$baseUrl}&success=true", "{$baseUrl}&success=false");
$tmpTransaction->order_id = $st;
$tmpTransaction->payment_id = $payment->getId();
$tmpTransaction->save();
header("Location: " . $this->getLink($payment->getLinks(), "approval_url"));
exit;
return "index";
}
示例7: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
DB::table('tags')->truncate();
//DB::table('pastes')->truncate();
$faker = Faker\Factory::create();
$paste_count = 10;
$tags = array('php', 'javascript', 'ruby', 'js', 'cpp', 'c++', 'c#', 'go', 'html', 'css');
for ($i = 0; $i < $paste_count; $i++) {
$tags_per_paste = rand(1, 3);
// Generate the paste
$examplePaste = new Paste();
$examplePaste->paste = $faker->paragraph;
$examplePaste->title = $faker->realText(46);
$examplePaste->expire = $faker->dateTime($max = 'now');
$examplePaste->token = Str::random(40);
$examplePaste->private = rand(0, 1);
$examplePaste->delete_token = Str::random(40);
$examplePaste->save();
// Attach some tags to the new paste
for ($i = 0; $i < $tags_per_paste; ++$i) {
$exampleTag = new Tag();
$exampleTag->tag = $tags[rand(0, sizeof($tags) - 1)];
$exampleTag->paste_id = $examplePaste->id;
$examplePaste->tags()->save($exampleTag);
}
print "Seeded paste with ID of " . $examplePaste->id . "\n";
}
}
示例8: setPasswordAttribute
/**
* Salts and saves the password
*
* @param string $password
*/
public function setPasswordAttribute($password)
{
$salt = md5(Str::random(64) . time());
$hashed = Hash::make($salt . $password);
$this->attributes['password'] = $hashed;
$this->attributes['salt'] = $salt;
}
示例9: view
public function view()
{
// Group's inputs.
$name_group_inputs = [View::forge('form/group/input', ['label_coltype' => 'col-xs-2', 'input_coltype' => 'col-xs-4', 'input' => Form::input('name', $this->requested_aircraft->name, ['class' => 'form-control', 'type' => 'text']), 'label' => 'A/C Name'], false)];
$general_group_1_inputs = [View::forge('form/group/input', ['label_coltype' => 'col-xs-2', 'input_coltype' => 'col-xs-4', 'input' => Form::input('basic_empty_weight', $this->requested_aircraft->basic_empty_weight, ['class' => 'form-control', 'type' => 'number']) . "kg", 'label' => 'Basic Empty Weight'], false), View::forge('form/group/input', ['label_coltype' => 'col-xs-2', 'input_coltype' => 'col-xs-4', 'input' => Form::input('cg_position', $this->requested_aircraft->cg_position, ['class' => 'form-control', 'type' => 'number']) . "aft of datum", 'label' => 'C of G Position'], false)];
$description_group_inputs = [View::forge('form/group/input', ['label_coltype' => 'col-xs-12', 'input_coltype' => 'col-xs-12', 'input' => Form::textarea('description', $this->requested_aircraft->description, ['class' => 'form-control']), 'label' => 'Description', 'label_left' => true], false)];
$weight_limits_group_1_inputs = [View::forge('form/group/input', ['label_coltype' => 'col-xs-2', 'input_coltype' => 'col-xs-4', 'input' => Form::input('max_ramp_weight', $this->requested_aircraft->max_ramp_weight, ['class' => 'form-control', 'type' => 'text']), 'label' => 'Max Ramp Weight'], false), View::forge('form/group/input', ['label_coltype' => 'col-xs-2', 'input_coltype' => 'col-xs-4', 'input' => Form::input('mctow', $this->requested_aircraft->mctow, ['class' => 'form-control', 'type' => 'text']), 'label' => 'MCTOW'], false)];
$weight_limits_group_2_inputs = [View::forge('form/group/input', ['label_coltype' => 'col-xs-2', 'input_coltype' => 'col-xs-4', 'input' => Form::input('mlw', $this->requested_aircraft->mlw, ['class' => 'form-control', 'type' => 'text']), 'label' => 'MLW'], false), View::forge('form/group/input', ['label_coltype' => 'col-xs-2', 'input_coltype' => 'col-xs-4', 'input' => Form::input('mzfw', $this->requested_aircraft->mzfw, ['class' => 'form-control', 'type' => 'text']), 'label' => 'MZFW'], false)];
$arms_table_template = View::forge('widgets/tablewithactions/template', ['duplicate_action' => false, 'cells' => [View::forge('widgets/tablewithactions/row/cell', ['cell_content' => Form::input('_name', '', ['class' => 'form-control'])], false), View::forge('widgets/tablewithactions/row/cell', ['cell_content' => Form::input('_position', '', ['class' => 'form-control'])], false), View::forge('widgets/tablewithactions/row/cell', ['cell_content' => Form::input('_value', '', ['class' => 'form-control']) . Form::hidden('_type', 'arm')], false)]]);
$arms_table = View::forge('widgets/tablewithactions', ['template_row' => $arms_table_template, 'name' => '_arms', 'coltype' => 'col-xs-12 col-md-6', 'headings' => ['<th>Label</th>', '<th>Arm (aft of datum)</th>', '<th>Max Weight</th>'], 'rows' => $this->arms_table_rows], false);
$cglimits_table_template = View::forge('widgets/tablewithactions/template', ['duplicate_action' => false, 'cells' => [View::forge('widgets/tablewithactions/row/cell', ['cell_content' => Form::input('_position', '', ['class' => 'form-control'])], false), View::forge('widgets/tablewithactions/row/cell', ['cell_content' => Form::input('_value', '', ['class' => 'form-control']) . Form::hidden('_type', 'maxweight') . Form::hidden('_name', 'limit')], false)]]);
$cglimits_table = View::forge('widgets/tablewithactions', ['template_row' => $cglimits_table_template, 'name' => '_arms', 'coltype' => 'col-xs-6', 'headings' => ['<th>Arm (aft of datum)</th>', '<th>Weight Limit</th>'], 'rows' => $this->cglimits_table_rows], false);
$button_group_1_inputs = [Asset::js('tablewithactions.js', false), View::forge('form/button', ['coltype' => 'col-xs-offset-5 col-xs-2', 'link' => 'submit/aircraft/' . $this->id, 'response_target' => './aircraft_form', 'class' => 'form-control btn-success', 'label' => 'Save Changes'], false)];
// Headings
$general_heading = View::forge('form/heading', ['text' => 'General', 'size' => 4], false);
$weight_limits_heading = View::forge('form/heading', ['text' => 'Weight Limits', 'size' => 4], false);
$arms_heading = View::forge('form/heading', ['text' => 'Arms', 'size' => 4], false);
$cg_limits_heading = View::forge('form/heading', ['text' => 'C of G Limits', 'size' => 4], false);
// Groups
$name_group = View::forge('form/group', ['inputs' => $name_group_inputs], false);
$general_group_1 = View::forge('form/group', ['inputs' => $general_group_1_inputs], false);
$description_group = View::forge('form/group', ['inputs' => $description_group_inputs], false);
$weight_limits_group_1 = View::forge('form/group', ['inputs' => $weight_limits_group_1_inputs]);
$weight_limits_group_2 = View::forge('form/group', ['inputs' => $weight_limits_group_2_inputs]);
$buttons_group = View::forge('form/group', ['inputs' => $button_group_1_inputs], false);
$cg_limits_group = View::forge('form/group', ['inputs' => ['<div class="col-xs-6">' . $cglimits_table . '</div>' . '<div class="col-xs-6">' . 'Graph here' . '</div>']], false);
$weightandbalance_section_data = ['heading' => 'Weight and Balance Data', 'unique_id' => Str::random('uuid'), 'groups' => [$general_heading, $name_group, $general_group_1, $description_group, $weight_limits_heading, $weight_limits_group_1, $weight_limits_group_2, $arms_heading, $arms_table, $cg_limits_heading, $cg_limits_group, $buttons_group]];
$weightandbalance_section = View::forge('form/section', $weightandbalance_section_data, false);
$this->aircraft_form = $weightandbalance_section;
}
示例10: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$id = Auth::user()->ID;
$files = Input::file('files');
$assetPath = '/uploads/' . $id;
$uploadPath = public_path($assetPath);
$results = array();
foreach ($files as $file) {
if ($file->getSize() > $_ENV['max_file_size']) {
$results[] = array("name" => $file->getClientOriginalName(), "size" => $file->getSize(), "error" => "Please upload file less than " . $_ENV['max_file_size'] / 1000000 . "mb");
} else {
//rename filename so that it won't overlap with existing file
$extension = $file->getClientOriginalExtension();
$filename = time() . Str::random(20) . "." . $extension;
// store our uploaded file in our uploads folder
$name = $assetPath . '/' . $filename;
$photo_attributes = array('name' => $filename, 'size' => $file->getSize(), 'url' => asset($name), 'user_id' => $id);
$photo = new Photo($photo_attributes);
if ($photo->save()) {
if (!is_dir($uploadPath)) {
mkdir($uploadPath, 0777);
}
//resize image into different sizes
foreach (Photo::getThumbnailSizes() as $key => $thumb) {
Image::make($file->getRealPath())->resize($thumb['width'], $thumb['height'])->save($uploadPath . "/" . $key . "-" . $filename);
}
//save original file
$file->move($uploadPath, $filename);
$results[] = Photo::find($photo->id)->find_in_json();
}
}
}
// return our results in a files object
return json_encode(array('files' => $results));
}
示例11: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$this->info('Iniciando a requisição para o webservice');
$this->info('Carregando a lista de estados');
$estados = $this->makeRequest('estados');
$this->info('Foram encontrados ' . count($estados) . ' estados');
$this->info('Carregando a lista de cargos');
$cargos = CandidateType::all()->lists('id', 'type');
$this->info('Foram encontrados ' . count($cargos) . ' cargos');
$this->info('Carregando a lista de partidos');
$partidos = Party::all()->lists('id', 'abbreviation');
$this->info('Foram encontrados ' . count($partidos) . ' partidos');
foreach ($estados as $estado_id => $estado) {
$this->info("Carregando os candidatos de {$estado->sigla} ({$estado_id}/" . count($estado) . ")");
foreach ($cargos as $cargo_nome => $cargo_id) {
$this->info('- Procurando por ' . $cargo_nome);
$candidatos = $this->makeRequest('candidatos', ['estado' => $estado->sigla, 'cargo' => $cargo_id]);
foreach ($candidatos as $candidato) {
$candidate = Candidate::where('full_name', $candidato->nome)->first();
if (!$candidate) {
$this->info('-- Processando ' . $candidato->nome . '/' . $candidato->apelido);
$picture_hash = Str::random(90) . ".jpg";
file_put_contents(app_path() . '/../www/uploads/' . $picture_hash, file_get_contents($candidato->foto));
Candidate::create(['party_id' => $partidos[$candidato->partido], 'candidate_type_id' => $cargos[ucfirst(strtolower(str_replace('º', '', (string) $candidato->cargo)))], 'nickname' => $candidato->apelido, 'full_name' => $candidato->nome, 'picture' => $picture_hash]);
}
}
//$this->info('Foram encontrados ' . count($candidatos) . ' candidatos');
}
}
}
示例12: submitFile
public function submitFile($id)
{
$files = Input::file('files');
foreach ($files as $file) {
$rules = array('file' => FileTypes::getAllFileTypes());
$validator = Validator::make(array('file' => $file), $rules);
if ($validator->passes()) {
$randomId = Str::random(14);
$destinationPath = 'uploads/group/activity/' . Auth::user()->StudentID . '/';
$filename = $file->getClientOriginalName();
$mime_type = $file->getMimeType();
$extension = $file->getClientOriginalExtension();
$upload_success = $file->move('public/' . $destinationPath, $randomId . $filename);
if ($upload_success) {
$check = GroupPageActivityFiles::hasSubmitted($id);
if (!count($check)) {
GroupPageActivityFiles::create(['path' => $destinationPath . $randomId . $filename, 'filename' => $filename, 'grouppageactivityID' => $id, 'OwnerID' => Auth::user()->StudentID]);
} else {
$check->update(array('path' => $destinationPath . $randomId . $filename, 'filename' => $filename));
}
return Redirect::to('/')->with('message', 'Successfully submitted your activity')->with('url', '');
}
}
}
return Redirect::to('/')->with('message', 'Error submitted your activity')->with('url', '');
}
示例13: solicpremium
/**
* Display a listing of the resource.
*
* @return Response
*/
public function solicpremium()
{
$authuser = Auth::user();
$clasificado = Clasificado::find(Input::get('clasfid'));
$clasificado->solicitar_premium = 1;
$clasificado->save();
//Generar row en cobros y cobros_pendientes
$cobrotipoSerProveedor = CobroTipo::where('tipo', 'clasificado_premium')->first();
$cobro = new Cobro();
$cobro->tipo_id = $cobrotipoSerProveedor->id;
$cobro->usuario_id = $authuser->id;
$cobro->estado = 'pendiente';
$cobro->datosAdicionales = $clasificado->id;
//Al entrar a este metodo estoy seguro que el usuario tiene un registro de proveedor asociado
$cobro->save();
$id = Str::random(4);
$date_now = new DateTime();
$cobrop = new CobroPendiente();
$cobrop->cobro_id = $cobro->id;
$cobrop->fecha = $date_now;
$cobrop->cobro_concepto = 'TODCONS' . $cobro->id . 'CLASF' . $clasificado->id . $date_now->format('YmdHi') . $id;
// Concepto = clave_empresa+ clave_cobro+ clave_tipo_cobro + clave_objeto_de_cobro + fecha+4_digitos_random (Por favor mejorar!!)
$cobrop->save();
return Redirect::to('vistausuario/clasificados')->with(array('usuarioimg' => $authuser->imagen, 'usuarionombre' => $authuser->nombre, 'usuarioid' => $authuser->id));
}
示例14: set_password
/**
* Salts and saves the password
*
* @param string $password
*/
public function set_password($password)
{
$salt = md5(\Str::random(64) . time());
$hashed = \Hash::make($salt . $password);
$this->set_attribute('password', $hashed);
$this->set_attribute('salt', $salt);
}
示例15: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$file = $this->argument('file');
if (!file_exists($file) || !is_file($file)) {
$this->error('Please provide a valid file.');
}
if ($handle = fopen($file, 'r')) {
while (($data = fgetcsv($handle, 0, ';')) !== false) {
// If the "level" column is present, use it instead of the
// "level" option.
$level = $this->option('level');
if (count($data) === 7) {
$level = $data[6];
} elseif ($this->option('level') === null) {
$this->error('The file does not include the level of the newcomer, please provide it via the "level" flag.');
return;
}
// See the class description for file format.
$attributes = ['first_name' => $data[2], 'last_name' => $data[1], 'password' => Str::random(6), 'sex' => strpos($data[0], 'M') !== false ? 'M' : 'F', 'email' => $data[5], 'phone' => $data[4], 'level' => $level, 'birth' => new DateTime($data[3])];
$newcomer = Newcomer::create($attributes);
if ($newcomer->save() === false) {
$this->error('Error while adding ' . $newcomer->first_name . ' ' . $newcomer->last_name);
}
}
}
}