public function sampleUserProvider() { $user = ["name" => "John", "password" => "chatbox1234"]; $hash = Str::random(); $user["email"] = "t.goto+{$hash}@chatbox-inc.com"; return [[$user]]; }
/** * Execute the console command. * * @return void */ public function handle() { parent::fire(); try { if (cmsinstalled()) { throw new \Exception('The CMS is already installed!'); } $success = $this->r_installer->testDBConnection($this->argument('db-host'), $this->argument('db-name'), $this->argument('db-username'), $this->argument('db-password')); if ($success) { $this->r_installer->generateConfigs($this->argument('site-name'), $this->argument('site-description'), $this->argument('site-url'), $this->argument('db-host'), $this->argument('db-name'), $this->argument('db-username'), $this->argument('db-password'), $this->argument('user-first-name'), $this->argument('user-last-name'), $this->argument('user-email')); $this->call('cache:clear'); $this->r_installer->migrate(['APP_SITE_NAME' => $this->argument('site-name'), 'APP_URL' => $this->argument('site-url')], ['--force' => true, '--database' => 'installer'], ['--force' => true, '--database' => 'installer']); $password = Str::random(Settings::get('installer.password_length')); $this->r_installer->addUserAdmin(['civility' => $this->argument('user-civility'), 'first_name' => $this->argument('user-first-name'), 'last_name' => $this->argument('user-last-name'), 'email' => $this->argument('user-email'), 'password' => $password]); $this->r_installer->set_env_as_production(); $this->line(sprintf(trans('installer::installer.command_line_show_password'), $this->argument('user-email'), $password)); $this->line(trans('installer::installer.command_line_remember_change_password')); } else { $this->error(trans('installer::installer.error:db_connection')); } } catch (InvalidArgumentException $e) { $this->error($e->getMessage()); } catch (\Exception $e) { $this->error($e->getMessage()); } }
/** * Generates a random token * * @param String $str [description] * * @return String [description] */ function token($str = null) { $str = isset($str) ? $str : \Illuminate\Support\Str::random(); $value = str_shuffle(sha1($str . microtime(true))); $token = hash_hmac('sha1', $value, env('APP_KEY')); return $token; }
/** * Update the users profile * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function store(Request $request) { $user = User::find($request->input('user_id')); $user->name = $request->input('name'); $user->email = $request->input('email'); $user->username = $request->input('username'); if ($request->input('password') != '') { $user->password = bcrypt($request->input('password')); } $user->update(); $company = Company::where('user_id', $request->input('user_id'))->first(); $company->name = $request->input('company_name'); $company->description = $request->input('company_description'); $company->phone = $request->input('company_phone'); $company->email = $request->input('company_email'); $company->address1 = $request->input('company_address'); $company->address2 = $request->input('company_address2'); $company->city = $request->input('company_city'); $company->postcode = $request->input('company_postcode'); if ($request->hasFile('logo')) { $file = $request->file('logo'); $name = Str::random(25) . '.' . $file->getClientOriginalExtension(); $image = Image::make($request->file('logo')->getRealPath())->resize(210, 113, function ($constraint) { $constraint->aspectRatio(); }); $image->save(public_path() . '/uploads/' . $name); $company->logo = $name; } $company->update(); flash()->success('Success', 'Profile updated'); return back(); }
/** * Generate a random key for the application. * * @param string $cipher * @return string */ protected function getRandomKey($cipher) { if ($cipher === 'AES-128-CBC') { return Str::random(16); } return Str::random(32); }
public function createNewToken(City $city) { $this->token = hash_hmac('sha256', Str::random(40), config('app.key')); $this->city_id = $city->id; $this->save(); return $this->token; }
/** * Run the request filter. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (!$request->session()->has('sift_session_id')) { $request->session()->put('sift_session_id', Str::random(24)); } return $next($request); }
public function run() { DB::table('projects')->delete(); Project::create(['name' => 'Deployer', 'hash' => Str::random(60), 'repository' => 'https://github.com/REBELinBLUE/deployer.git', 'url' => 'http://deploy.app', 'group_id' => 2, 'private_key' => '-----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEAmrMjtajVvmd99T8xwUNrIFbrzSmZ6VCM89hfm4Ut9atv29gG l2HFPJY7VtslXDJVL67w5EUMspy82tkAX7F03iaarSsbo6nC16UTfbfNTi44Snm0 T/5RMavSOnOMRJ8BQcfzqge4oIQzVGXOs0YvNFdSt4paBp9dssKS+7yP/hDvgAVz +LE3IcIeO26aXATcuB4zq3vjaqSzWZGdNhOJZ4EmjgmOq9+k3SAmooHkF+p/14MJ tq0ZK9KjSGbHfyKMi2EuvwllFCY19eqsV7dcMDIsMKUW2diFC52dJSO+EF47nA/j sNDisFsIC7De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KBgCtikMNAqTParY/tX0xNohD7+svTKZt92CxW7Q/17H26ehFKUQvw6Agd ulR2AVTGi6STEgzXf6UP5CAVhYRw9irCAQYpceL0GVzfZPQsXyLuMCnJ8UD6CBRn i5vkNY4OZdOuEV9boFOFYa58WRNK7vthHkZJj++Amu3dZ6RHBlLQ -----END RSA PRIVATE KEY-----', 'public_key' => 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCasyO1qNW+Z331PzHBQ2sgVuvNKZnpUIzz2F+bhS31q2/b2Aa' . 'XYcU8ljtW2yVcMlUvrvDkRQyynLza2QBfsXTeJpqtKxujqcLXpRN9t81OLjhKebRP/lExq9I6c4xEnwFBx/OqB7' . 'ighDNUZc6zRi80V1K3iloGn12ywpL7vI/+EO+ABXP4sTchwh47bppcBNy4HjOre+NqpLNZkZ02E4lngSaOCY6r3' . '6TdICaigeQX6n/Xgwm2rRkr0qNIZsd/IoyLYS6/CWUUJjX16qxXt1wwMiwwpRbZ2IULnZ0lI74QXjucD+Ow0OKw' . 'WwgLsN55VUGXVOlpX1GJ2p5mZ3H6YX0B deploy@deployer', 'last_run' => null, 'build_url' => 'http://ci.rebelinblue.com/build-status/image/3?branch=master']); }
/** * Execute the console command. * @throws Exception */ public function fire() { $login = $this->argument('login'); if ($this->rainlab) { $rainlab = (bool) $this->option('rainlab'); } else { $rainlab = false; } if ($rainlab) { $user = \RainLab\User\Models\User::where('email', '=', $login)->orWhere('username', '=', $login)->first(); } else { $user = User::whereLogin($login)->first(); } if (!$user) { return $this->error('User not found'); } $password = $this->option('password'); if ($rainlab) { $login = '******' . $login; } else { $login = '******' . $login; } if ($password == null) { $password = $this->ask('Set password for ' . $login . ' (or press Enter to skip)'); } if ($password == null) { $password = Str::random(5); } $user->update(['password' => $password, 'password_confirmation' => $password]); $message = "\n -> new password for " . $login . ": "; $this->comment($message . $password); return; }
/** * @param string $fileType * * @return ImportJob */ public function create(string $fileType) : ImportJob { $count = 0; $fileType = strtolower($fileType); $keys = array_keys(config('firefly.import_formats')); if (!in_array($fileType, $keys)) { throw new FireflyException(sprintf('Cannot use type "%s" for import job.', $fileType)); } while ($count < 30) { $key = Str::random(12); $existing = $this->findByKey($key); if (is_null($existing->id)) { $importJob = new ImportJob(); $importJob->user()->associate($this->user); $importJob->file_type = $fileType; $importJob->key = Str::random(12); $importJob->status = 'import_status_never_started'; $importJob->extended_status = ['total_steps' => 0, 'steps_done' => 0, 'import_count' => 0, 'importTag' => 0, 'errors' => []]; $importJob->save(); // breaks the loop: return $importJob; } $count++; } return new ImportJob(); }
/** * @param \Lio\Accounts\User $user * @param \Lio\Accounts\UserUpdaterListener $listener * @param array $data * @return mixed */ private function updateUser(User $user, UserUpdaterListener $listener, array $data) { $oldEmail = $user->email; $user->fill($data); // If the email changed, the user will need to re-confirm it. if ($data['email'] !== $oldEmail) { $user->confirmed = false; // Set a confirmation code for the user. He'll need to verify his email address // with this code before he can use certain sections on the website. $confirmationCode = Str::random(30); // We'll generate a new one if we find a user with the same code. while ($this->users->getByConfirmationCode($confirmationCode) !== null) { $confirmationCode = Str::random(30); } $user->confirmation_code = $confirmationCode; } // check the model validation if (!$this->users->save($user)) { return $listener->userValidationError($user->getErrors()); } // Send a confirmation email to the user. if ($data['email'] !== $oldEmail) { $this->confirmation->send($user); } return $listener->userUpdated($user, $data['email'] !== $oldEmail); }
/** * Generate unique reference * * @return string */ public function uniqueReference() { do { $reference = Str::upper(Str::random($this->referenceLength())); } while (self::where($this->referenceField(), '=', $reference)->count() > 0); return $reference; }
protected function generateUniqueName($file, $path) { do { $fileName = Str::random(20) . '.' . File::extension($file->getClientOriginalName()); } while (file_exists(public_path($path) . '/' . $fileName)); return $fileName; }
public function createWish($user, $projectHash) { $project = $this->projectRepository->getByHash($projectHash); $hash = Str::random(38); $attrs = ['hash' => $hash, 'user_id' => $user->id, 'project_id' => $project->id]; $wish = $this->wishRepository->create($attrs); return $wish; }
/** * * @param null $config * @return string */ public function src($config = null, $formId = false) { $this->configure($config, $formId); if ($this->formId) { return url('captcha' . ($config ? '/' . $config : '/default')) . '/' . $this->formId . '?' . $this->str->random(8); } return url('captcha' . ($config ? '/' . $config : '/default')) . '?' . $this->str->random(8); }
/** * Redirect the user of the application to the provider's authentication screen. * * @return \Illuminate\Http\RedirectResponse */ public function redirect() { $state = Str::random(40); if (!$this->isStateless()) { $this->request->getSession()->set('state', $state); } return new RedirectResponse($this->getAuthUrl($state)); }
/** * Display the specified resource. * * @param $link * @return \Illuminate\Http\Response * @internal param int $id */ public function show($link) { $client = new Client(); $baseUrl = 'https://www.youmagine.com/'; $response = $client->get($baseUrl . 'designs/' . $link); $code = $response->getBody(); $xs = Selector::loadHTML($code); // Scrape Youmagine thing information from DOM try { $name = $xs->find('/html/body/div[2]/div/h1')->extract(); $description = $xs->find('//*[@id="information"]/div[2]')->extract(); $files = $xs->findAll('//*[@id="documents"]/div/ul/li[*]/div[3]/div[1]/a')->map(function ($node) { return $node->find('@href')->extract(); }); } catch (NodeNotFoundException $e) { return response()->view('thing.none'); } // Get files $downloadLinks = []; foreach ($files as $file) { $response = $client->get($baseUrl . $file, ['allow_redirects' => false]); $code = $response->getBody(); preg_match('/"(.*?)"/', $code, $downloadLinkMatch); $downloadLinks[] = $downloadLinkMatch[1]; } // Get access token $response = $client->request('POST', 'https://developer.api.autodesk.com/authentication/v1/authenticate', ['form_params' => ['client_id' => env('AUTODESK_CLIENT_ID', ''), 'client_secret' => env('AUTODESK_CLIENT_SECRET', ''), 'grant_type' => 'client_credentials']]); $authToken = json_decode($response->getBody())->access_token; // Create a bucket $bucketKey = Str::lower(Str::random(16)); $response = $client->request('POST', 'https://developer.api.autodesk.com/oss/v2/buckets', ['json' => ['bucketKey' => $bucketKey, 'policyKey' => 'transient'], 'headers' => ['Authorization' => 'Bearer ' . $authToken]]); $bucketKey = json_decode($response->getBody())->bucketKey; // Upload to bucket $bucket = []; foreach ($downloadLinks as $downloadLink) { $fileName = pathinfo($downloadLink)['basename']; $file = fopen(base_path('public/cache/' . $fileName), 'w'); /** @noinspection PhpUnusedLocalVariableInspection */ $response = $client->get($downloadLink, ['sink' => $file]); $file = fopen(base_path('public/cache/' . $fileName), 'r'); $response = $client->request('PUT', 'https://developer.api.autodesk.com/oss/v2/buckets/' . $bucketKey . '/objects/' . $fileName, ['body' => $file, 'headers' => ['Authorization' => 'Bearer ' . $authToken]]); $body = json_decode($response->getBody()); $bucket[] = ['filename' => $body->objectKey, 'urn' => $body->objectId]; } // Set up references $references = ['master' => $bucket[0]['urn'], 'dependencies' => []]; foreach ($bucket as $file) { if ($file['filename'] === $bucket[0]['filename']) { continue; } $references['dependencies'][] = ['file' => $file['urn'], 'metadata' => ['childPath' => $file['filename'], 'parentPath' => $bucket[0]['filename']]]; } $response = $client->post('https://developer.api.autodesk.com/references/v1/setreference', ['json' => $references, 'headers' => ['Authorization' => 'Bearer ' . $authToken]]); // Register data with the viewing services $urn = base64_encode($bucket[0]['urn']); $response = $client->post('https://developer.api.autodesk.com/viewingservice/v1/register', ['json' => ['urn' => $urn], 'headers' => ['Authorization' => 'Bearer ' . $authToken]]); return response()->view('thing.show', compact('name', 'description', 'urn', 'authToken') + ['pollUrl' => 'https://developer.api.autodesk.com/viewingservice/v1/' . $urn, 'dl' => $downloadLinks[0]]); }
/** * {@inheritdoc} */ public function redirect() { $state = null; if ($this->usesState()) { $state = Str::random(40); \Cache::put($state, $state, 3); } return new RedirectResponse($this->getAuthUrl($state)); }
public function CreateImage($currentImage, $folderName, $thumbResize, $largeResize) { $fileName = $currentImage->getClientOriginalName(); $fileName = Str::random(5) . '' . $fileName; $realPath = $currentImage->getRealPath(); \Image::make($realPath)->resize($thumbResize[0], $thumbResize[1])->save(public_path('images/uploads/' . $folderName . '/thumbnail/' . $fileName)); \Image::make($realPath)->resize($largeResize[0], $largeResize[1])->save(public_path('images/uploads/' . $folderName . '/large/' . $fileName)); return $fileName; }
/** * Generates a code and then hashes it, giving us the token. */ public function generate() { if (empty($this->attributes['token'])) { do { $token = hash('md5', Str::random(16) . time(), false); } while (DB::table($this->table)->where('token', $token)->count() != 0); $this->attributes['token'] = $token; } }
/** * Generates a code and then hashes it, giving us the token. */ public function generate() { if (empty($this->attributes['code'])) { do { $code = Str::random(8); } while (DB::table($this->table)->where('code', $code)->count() != 0); $this->attributes['code'] = $code; } }
public function generate() { do { $key = hash('md5', Str::random(16) . $this->attributes['id'] . time(), false); } while (DB::table($this->table)->where('key', $key)->count() != 0); $secret = hash('sha256', $key . Str::random(32), false); $this->attributes['key'] = $key; $this->attributes['secret'] = $secret; }
public function postStore() { $id = Input::get('id'); /* * Validate */ $rules = array('image' => 'mimes:jpg,jpeg,png,gif|max:500', 'name' => 'required', 'short_description' => 'required', 'long_description' => 'required', 'start_date' => 'required', 'end_date' => 'required'); $validation = Validator::make(Input::all(), $rules); if ($validation->passes()) { $name = Input::get('name'); $short_description = Input::get('short_description'); $long_description = Input::get('long_description'); $image = Input::file('image'); $active = Input::get('active') == '' ? FALSE : TRUE; $cn_name = Input::get('cn_name'); $cn_short_description = Input::get('cn_short_description'); $cn_long_description = Input::get('cn_long_description'); $options = array('name' => $cn_name, 'short_description' => $cn_short_description, 'long_description' => $cn_long_description); $start_date = DateTime::createFromFormat('d/m/Y', Input::get('start_date')); $end_date = DateTime::createFromFormat('d/m/Y', Input::get('end_date')); $promotion = isset($id) ? Promotion::find($id) : new Promotion(); $promotion->name = $name; $promotion->start_date = $start_date; $promotion->end_date = $end_date; $promotion->short_description = $short_description; $promotion->long_description = $long_description; $promotion->active = $active; $promotion->options = json_encode($options); $promotion->save(); if (Input::hasFile('image')) { // Delete all existing images for edit if (isset($id)) { $promotion->deleteAllImages(); } //set the name of the file $originalFilename = $image->getClientOriginalName(); $filename = 'promo' . date("dmY") . '_' . Str::random(20) . '.' . File::extension($originalFilename); //Upload the file $isSuccess = $image->move('assets/img/promotions', $filename); if ($isSuccess) { // create photo $newimage = new Image(); $newimage->path = $filename; // save photo to the loaded model $promotion->images()->save($newimage); } } } else { if (isset($id)) { return Redirect::to('admin/promotions/edit/' . $id)->withErrors($validation)->withInput(); } else { return Redirect::to('admin/promotions/create')->withErrors($validation)->withInput(); } } return Redirect::to('admin/promotions'); }
/** * Service Provider Boot * * @return void */ public function boot() { Route::get('/', function () { return redirect('/web_installer'); }); Route::post('/install/post', '\\App\\Http\\Controllers\\InstallController@install'); \App\Http\Middleware\ExceptAppendableVerifyCsrfToken::setExcept('/install/post'); // 실제 키 생성전 임시 app('config')->set('app.key', Str::random(32)); }
/** * @param $user_email * @return string */ protected function createSystemUser($user_email) { $password = Str::random(); $password_hashed = bcrypt($password); $system_user = new User(); $system_user->email = $user_email; $system_user->password = $password_hashed; $system_user->save(); return $password; }
public function login($service) { $service_state = Str::random(); Session::put('service_state', $service_state); // store the state code in the session $classNamespace = "Cresjie\\SocialLogin\\Auth\\" . Config::get('social-login::oauth_version')[strtolower($service)] . '\\' . ucwords($service); $service = new $classNamespace(); $url = $service->loginUrl(['state' => $service_state]); return Redirect::to($url); }
/** * Get unique random filename with $extenstion within $path directory * @param string $path * @param string $extension * @return string */ public static function get($path, $extension) { if (!Str::endsWith($path, '/')) { $path .= '/'; } do { $name = Str::random(10) . '.' . $extension; } while (file_exists($path . $name)); return $name; }
protected function _testUpdateProfile($authtoken, $user) { $newName = Str::random(); $this->put("/profile", ["user" => ["name" => $newName]], ["X-AUTHTOKEN" => $authtoken]); $this->assertResponseOk(); $this->assertArrayHasKey("user", $this->response->getOriginalContent()); $actualUser = $this->response->getOriginalContent()["user"]; $this->assertInstanceOf(Chatbox\ApiAuth\Domains\User::class, $actualUser); $this->assertEquals($user["name"], $actualUser->data["name"]); }
/** * index. * * @param \Recca0120\Terminal\TerminalManager $terminalManger * @param string $view * * @return mixed */ public function index(TerminalManager $terminalManger, $view = 'index') { $csrfToken = null; if ($this->request->hasSession() === true) { $csrfToken = $this->request->session()->token(); } $options = json_encode(array_merge($terminalManger->getOptions(), ['csrfToken' => $csrfToken])); $id = $view === 'panel' ? Str::random(30) : null; return $this->responseFactory->view('terminal::' . $view, compact('options', 'id')); }
private function startSession() { $session = new Session(); $session->setName('flarum_session'); $session->start(); if (!$session->has('csrf_token')) { $session->set('csrf_token', Str::random(40)); } return $session; }