public function createOrder(CreateOrderRequest $request) { $order = \DB::transaction(function () use($request) { $order = Order::create($request->all()); $order->reference = \Hashids::encode($order->id); $order->save(); foreach (\Cart::content() as $item) { $order->addItem($item); } return $order; }); if ($order) { return response()->json(['success' => true, 'reference' => $order->reference], 200); } return response()->json(['success' => false]); }
/** * Correct any null hash values */ function rehashNullValues() { $table = 'project_1_images'; $i = 0; $rows = $this->db->query('select * from ' . $table . ' where hash is null'); foreach ($rows->result() as $row) { // Update the hash values $hashids = new Hashids('abracadabra', 5); $hash = $hashids->encode($row->image_id); $dataUpdate = array('hash' => $hash); $this->db->where('image_id', $row->image_id); $this->db->update($table, $dataUpdate); $i++; } return $i; }
/** * Create a new model instance and store it in the database * * @param array $data * @return static */ public function store(array $data) { // Do we need to create a reference id? if ($this->model->isFillable('ref') && !isset($data['ref'])) { $data['ref'] = $this->generateReferenceId(); } // Create the new model object $model = $this->model->create($data); // Do we need to set a hash? if ($this->model->isFillable('hash')) { $model->hash = \Hashids::encode($model->id); $model->save(); } // Return the new model object return $model; }
public function postSenha() { $associate = ORGAssociates::where('email', '=', Input::get('login'))->take(1)->get(); if (isset($associate[0])) { $new_password = Hashids::encode(date('YmdHis')); $associate = $associate[0]; $associate->senha = md5($new_password); $associate->save(); $user = null; if ($associate->associate != null) { $user = $associate->associate->getuser; $user->password = Hash::make($new_password); $user->save(); } else { $user = new User(); $user->type = 'associate'; $user->email = $associate->email; $user->password = Hash::make($new_password); $user->name = $associate->nombre_completo; $user->status = 'publish'; $user->save(); $assoc = new Associates(); $assoc->associate = $associate->id_asociado; $assoc->user = $user->id; $assoc->name = $associate->nombre_completo; $assoc->email = $associate->email; $assoc->password = $associate->senha; $assoc->cpf = $associate->cpf; $assoc->type = 'associate'; $assoc->status = 'publish'; $assoc->save(); } $data = array('associate' => $associate, 'password' => $new_password); Mail::send(array('html' => 'emails.password'), $data, function ($message) use($associate) { $message->from('*****@*****.**', 'ABGE'); $message->to($associate->email, $associate->nombre_completo)->subject('Esqueci minha senha!'); /*$message->to('*****@*****.**', $associate->nombre_completo)->subject('Esqueci minha senha!');*/ $message->to('*****@*****.**', $associate->nombre_completo)->subject('Esqueci minha senha!'); }); return View::make('auth.minhasenha')->with('route', self::$route); } else { dd('email no encontrado'); } return Redirect::to(self::$route); }
public static function makeQlink($name) { usleep(1100000); return Hashids::encode((int) microtime(true)); }
{{--</a>--}} {{--</li>--}} {{--@endfor--}} {{--</ul>--}} {{--</div>--}} {{--</div>--}} </div> {{-- Goc Mang Non --}} <div class="actnews-list-content clearfix"> <h2 class="box-title"><span>Góc măng non</span></h2> @forelse ($gmn as $key => $p) <?php $postUri = $p->term_slug . '/' . $p->post_name . '--' . Hashids::encode($p->id); ?> @if ($key == 0) {{-- First post --}} <article class="actnews actnews-first" style="float: left;"> <header class="entry-header"> <h3 class="entry-title"> <a href="{{ route('article.index', $postUri) }}"> <img src="{{ empty($p->post_avatar) ? 'assets/img/transparent.gif' : route('_image.index') . '/' . $p->post_avatar }}" alt="" /> {{ $p->post_title }} </a> </h3> </header> <div class="entry-summary"> {{ $p->post_excerpt }} </div>
public function uploadImage($image) { //dd(storage_path('uploads/')); $info_image = getimagesize($image); $ratio = $info_image[0] / $info_image[1]; $newheight = array(); $width = array("100", $info_image[0]); #$filename = "prueba.".$image->getClientOriginalExtension(); $filename = Hashids::encode(idate('U')) . "." . $image->getClientOriginalExtension(); $nombres = ["thumb_" . $filename, $filename]; for ($i = 0; $i < count($width); $i++) { $path = public_path('uploads/classificados/' . $nombres[$i]); Image::make($image->getRealPath())->resize($width[$i], null, function ($constraint) { $constraint->aspectRatio(); })->save($path); } return $filename; }
public function authUserInfo() { $data[] = ['name' => Auth::user()->name, 'profile_picture' => '/avatar/' . \Hashids::encode(Auth::user()->id, rand(0, 100)), 'email' => Auth::user()->email]; return $data; }
public function getHashAttribute() { return \Hashids::encode($this->attributes['id']); }
public function processLoadProducts() { DB::beginTransaction(); try { //get args $op_id = Session::get('HomeController.op_id'); $op_type = Session::get('HomeController.op_type'); $products = Session::get('HomeController.products'); $admin_add_form = Input::get('query.add_attributes'); $string_of_keywords = Input::get('query.keywords_profile'); //prep admin add form, ex: clear sub interests if interest is not selected $admin_add_form = $this->add_form_prepper->prep($admin_add_form); //make sure we have needed args if ($op_type == 'ProductRequest' && count($products) > 1) { throw new \RuntimeException('More than one product provided for single product input'); } if ($op_type != 'Idea' && $op_type != 'ProductRequest') { throw new \RuntimeException('Invalid op type'); } //make sure categorization data is provided if (empty($admin_add_form)) { DB::rollback(); return Redirect::route('get_add-categorize')->withErrors('Category information must be provided.'); } //make sure there is only one id per category since this form is limited to radio selections foreach ($admin_add_form as $key => $value) { if (is_array($value)) { throw new \InvalidArgumentException('Should not have more than one id per category type for this form.'); } } //determine add type $add_type = 6; //load each product $loaded_products_exist = false; $approved_products_exist = false; foreach ($products as $product_key => $product_suite) { //ensure the product is not blacklisted if (!$this->blacklisted_product_repo->isProductSuiteBlackListed($product_suite)) { //make keyword profile $product_suite['keyword_profile']['profile'] = $this->keyword_profile_generator->make($string_of_keywords); //make category keywords $product_suite['category_keywords'] = $this->category_keywords_generator->make($this->multi_adds_service->getFormattedAdd($admin_add_form)); //load product suite $product = $this->product_suite_repo->finderCreate($product_suite, $op_type, $op_id, \AuthMgr::getLoggedUserId(), false); if (!$product && $op_type == 'Idea') { //since we dont want to roll back, if the product exists let's just delete it $existing_failed_prod_ids = $this->product_suite_repo->errors()->get('sub_products_failure_product_id'); $this->product_suite_repo->delete(end($existing_failed_prod_ids)); \Log::notice('Could not complete finderCreate for product suite: ' . json_encode($product_suite) . ' REPO ERRORS: ' . json_encode($this->product_suite_repo->errors())); continue; } elseif (!$product) { DB::rollback(); return Redirect::route('get_add-categorize')->withErrors("Hmm, I guess we're having an issue, we aren't able to complete this submission."); } //load add for product suite $add = $this->multi_adds_service->save($product->id, $add_type, $admin_add_form); $loaded_products_exist = true; } $approved_products_exist = true; } //if there are no approved products, redirect back with errors if (!$approved_products_exist && $loaded_products_exist) { DB::rollback(); return Redirect::route('get_add-categorize')->withErrors('At least one product must be approved'); } //if all products where blacklisted if (!$loaded_products_exist) { DB::rollback(); return Redirect::route('get_add-categorize')->withErrors('This product is either blacklisted or not eligible to be listed, sorry.'); } //update op model to mark it as fulfilled if ($op_type == 'Idea') { if (!$this->idea_repo->update($op_id, ['is_fulfilled' => 1])) { throw new \RuntimeException($this->idea_repo->errors()); } } else { if ($op_type == 'ProductRequest') { if (!$this->request_repo->update($op_id, ['product_id' => $product->id])) { throw new \RuntimeException($this->idea_repo->errors()); } } } //flush product suite indexing (do this last to ensure everything else is successful before comitting to index) $this->product_suite_repo->flushIndexing(); } catch (\Exception $e) { DB::rollback(); throw $e; } \DB::commit(); return Redirect::route('get_add')->with('success_message', 'Your Gift Recommendation Has Been Set Up! <a href="' . route('get_item') . '/' . \Hashids::encode($product->id) . '" class="alert-link">Check It Out!</a>'); }
public static function makeUrlGenre($object) { Yii::import("application.vendors.Hashids.*"); $hashids = new Hashids(Yii::app()->params["hash_url"]); $type = $object['type']; $name = $object['name']; $id = $object['id']; $gt = isset($object['gt']) ? $object['gt'] : ''; $suffix = 'gr'; $code = $hashids->encode($id); $code = $suffix . $code; $prefix = 'nhac-'; $urlKey = $prefix . Common::makeFriendlyUrl($name); if ($type == 'song') { $type = 'bai-hat'; } $params = array("action" => $type, "url_key" => $urlKey, "code" => $code); if (!empty($gt)) { if ($gt == 'new') { $gt = 'moi'; } $params['gt'] = $gt; } if (isset($object['other'])) { foreach ($object['other'] as $key => $ac) { $params[$key] = $ac; } } $link = Yii::app()->createAbsoluteUrl("site/url2", $params); return $link; }
public function edScrypt($in) { $hashids = new Hashids(url_hash_key); $out = $hashids->encode($in); return $out; }
/** * POST action untuk me-regenerate kode_kelas * @param Request $request [description] * @return [type] [description] */ public function regenerate_kode_kelas(Request $request) { $k = $this->kelas->findOrFail($request->id); $k->kode_kelas = \Hashids::encode($request->id . '' . date('YmdHis')); $k->save(); return $k; }
{{-- PAGE HEADER --}} <h1 class="page-header"> <span class="glyphicon glyphicon-globe" aria-hidden="true"></span> {{ $termCategory->term_name }} </h1> {{-- COLUMNS & CONTENT --}} <div class="row"> <div class="col-md-6 col-md-push-3"> @forelse ($articles as $key => $p) <?php $author = $p->author()->select('id', 'name')->first(); $postId = Hashids::encode($p->id); ?> @if ($key == 0) {{-- First post --}} <div class="post post-first"> <h2 class="post-title"> <a href="{{ route('article.index', $termCategory->term_slug . '/' . $p->post_name . '--' . $postId) }}">{{ $p->post_title }}</a> </h2> <p class="post-info"> <span class="post-date">{{ ivy_echo_date($p->post_date) }}</span> <span class="post-author">bởi {{ $author ? $author->name : 'Hệ thống' }}</span> </p> @unless (empty($p->post_avatar)) <div class="post-avatar"> <a href="{{ route('article.index', $termCategory->term_slug . '/' . $p->post_name . '--' . $postId) }}"> <img src="{{ route('_image.index') }}/{{ $p->post_avatar }}" alt="" />
public function processProductCategorizationUpdate() { $product_id = \Input::get('product_id'); $admin_add_form = \Input::get('query.add_attributes'); $keyword_profile_string = \Input::get('query.keywords_profile'); //prep admin add form, ex: clear sub interests if interest is not selected $admin_add_form = $this->add_form_prepper->prep($admin_add_form); if (empty($admin_add_form)) { return \Redirect::back()->withErrors('Categorization data must be provided'); } if (empty($product_id)) { throw new \InvalidArgumentException(); } \DB::beginTransaction(); try { //update add for product suite $this->save_adds->updateAdminAdd($product_id, $admin_add_form); //update keyword profile for product suite $keyword_profile = $this->keyword_profile_generator->make($keyword_profile_string); if (!$this->keyword_profile_repo->updateForProduct($product_id, ['profile' => $keyword_profile])) { \DB::rollback(); return \Redirect::back()->withErrors($this->keyword_profile_repo->errors()); } } catch (\Exception $e) { \DB::rollback(); throw $e; } \DB::commit(); return \Redirect::route('get_item', [Hashids::encode($product_id)])->with('success_message', 'Product updated'); }
private function _unhash($input, $alphabet) { $number = 0; if (strlen($input) && $alphabet) { $alphabet_length = strlen($alphabet); $input_chars = str_split($input); foreach ($input_chars as $i => $char) { $pos = strpos($alphabet, $char); if ($this->_math_functions) { $number = $this->_math_functions['str']($this->_math_functions['add']($number, $pos * pow($alphabet_length, strlen($input) - $i - 1))); } else { $number += $pos * pow($alphabet_length, strlen($input) - $i - 1); } } } return $number; } } $key = 'test'; $min_hash_length = 12; $hashids = new Hashids($key, $min_hash_length); //$ids = array(1,2,3); $ids = array(134); // 加密 $str = $hashids->encode($ids); echo $str . "<br>"; //exit; // 解密 $ids = $hashids->decode($str); echo "<pre>"; var_dump($ids);