/**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->bind('client', function ($value, $route) {
         $hashids = new Hashids('MySecretSalt*(&^%$eo&*^%&r', 20);
         $id = $hashids->decode($value)[0];
         return Client::findOrFail($id);
     });
     $router->bind('bank', function ($value, $route) {
         $hashids = new Hashids('MySecretSalt*(&^%$eo&*^%&r', 20);
         $id = $hashids->decode($value)[0];
         return BankDetail::findOrFail($id);
     });
     $router->bind('address', function ($value, $route) {
         $hashids = new Hashids('MySecretSalt*(&^%$eo&*^%&r', 20);
         $id = $hashids->decode($value)[0];
         return Address::findOrFail($id);
     });
     $router->bind('property', function ($value, $route) {
         $hashids = new Hashids('MySecretSalt*(&^%$eo&*^%&r', 20);
         $id = $hashids->decode($value)[0];
         return Property::findOrFail($id);
     });
     $router->bind('agreement', function ($value, $route) {
         $hashids = new Hashids('MySecretSalt*(&^%$eo&*^%&r', 20);
         $id = $hashids->decode($value)[0];
         return RentalAgreement::findOrFail($id);
     });
     //
 }
Ejemplo n.º 2
0
 /**
  * Add activity metadata 
  * 
  * @param User $user
  * @param Activity $activity
  * @param array $data    key-value pair data to store
  * @param array $exclude When given exclude keys to be stored in the database
  */
 public static function addUserActivity(User $user, Activity $activity, array $data, array $exclude = [])
 {
     $rows = [];
     $exclude = array_map('strtolower', $exclude);
     // Create a session_id.
     // Session_id is use for easily identify groups of metadata
     $hashids = new Hashids('dma.activity.metadata', 6);
     $user_id = $user->getKey();
     $activity_id = $activity->getKey();
     // Add unixtime and microseconds to avoid session_id collisions
     $micro = microtime(true);
     $unixtime = floor($micro);
     $milseconds = floor(($micro - $unixtime) * pow(10, 8));
     // Create session_id
     $session_id = $hashids->encode($user_id, $activity_id, $unixtime, $milseconds);
     // Current date and time
     $now = date('Y-m-d H:i:s');
     foreach ($data as $key => $value) {
         $key = strtolower($key);
         if (!in_array($key, $exclude)) {
             $row = ['session_id' => $session_id, 'user_id' => $user_id, 'activity_id' => $activity_id, 'key' => $key, 'value' => $value, 'created_at' => $now, 'updated_at' => $now];
             $rows[] = $row;
         }
     }
     if (count($row) > 0) {
         static::insert($rows);
     }
 }
Ejemplo n.º 3
0
 public function getHashidsShortcodeId($shortcode)
 {
     // create hashids for shortcode using the url row id
     $hashids = new Hashids("this is my salt", 5, "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ1234567890");
     // $shortcode = $hashids->encode($id);
     $numberId = $hashids->decode($shortcode);
     return $numberId;
 }
Ejemplo n.º 4
0
 /**
  * Process, filter and return the given data
  * @param mixed $jsonValue the value of the property in the JSON
  * @param mixed $objectValue the value of the property in the Object
  * @param bool $jsonToObject If the process works with the json or object value first
  * @return mixed
  */
 public function process($jsonValue, $objectValue, $jsonToObject = true)
 {
     $hashids = new Hashids(JacksonPhp::$hashIdsSalt, 8);
     if ($jsonToObject) {
         $decodedId = $hashids->decode($jsonValue);
         return count($decodedId) > 0 ? $decodedId[0] : "";
     } else {
         return $hashids->encode($objectValue);
     }
 }
Ejemplo n.º 5
0
 /**
  * Сохраняет кампанию и хеширует id
  *
  * @param Campaign $campaign
  */
 public function save(Campaign $campaign)
 {
     $isNew = $campaign->getId() ? false : true;
     $this->em->persist($campaign);
     $this->em->flush($campaign);
     if ($isNew) {
         $campaign->setHashId($this->hashids->encode($campaign->getId()));
     }
     $campaign->updateUpdatedAt();
     $this->tagManager->saveTagging($campaign);
     $this->em->flush();
 }
Ejemplo n.º 6
0
 /**
  * Generate a hashid based on random data.
  *
  * @param null $salt
  *
  * @return string
  */
 function generate_hashid($salt = null)
 {
     if (empty($salt)) {
         $salt = config('key');
     }
     $hashids = new Hashids($salt);
     $min = rand(1, 1000) * rand(1, 1000);
     $max = rand(1, 1000) * rand(1, 1000);
     $quantity = rand(1, 64);
     $numbers = unique_random_numbers_within_range($min, $max, $quantity);
     return StaticStringy::truncate(StaticStringy::shuffle($hashids->encode($numbers)), 8);
 }
Ejemplo n.º 7
0
 /**
  * сохранение площадки
  *
  * @param Platform $platform
  */
 public function save(Platform $platform)
 {
     $isNew = $platform->getId() ? false : true;
     $this->em->persist($platform);
     $this->em->flush($platform);
     if ($isNew) {
         $platform->setHashId($this->hashids->encode($platform->getId()));
     }
     $platform->updateUpdatedAt();
     $this->tagManager->saveTagging($platform);
     $this->em->flush();
 }
Ejemplo n.º 8
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next, $obscuredParameter = 'id')
 {
     $hashids = new Hashids(config('obscure.salt'), config('obscure.length'), config('obscure.alphabet'));
     // decode form request hashs
     if ($request->request->has($obscuredParameter)) {
         $request->request->add([$obscuredParameter => $hashids->decode($request->request->get($obscuredParameter))[0]]);
     }
     // decode route hashs
     if ($this->route->parameter($obscuredParameter)) {
         $this->route->setParameter($obscuredParameter, $hashids->decode($this->route->parameter($obscuredParameter))[0]);
     }
     return $next($request);
 }
Ejemplo n.º 9
0
 /**
  * Display the contents of the uploaded file
  */
 public function download()
 {
     $hashids = new Hashids(Configure::read('Security.salt'));
     $pk = $hashids->decode($this->request->query['i'])[0];
     $this->loadModel($this->request->query['m']);
     $data = $this->{$this->request->query['m']}->find('first', array('recursive' => -1, 'conditions' => array("{$this->request->query['m']}." . $this->{$this->request->query['m']}->primaryKey => $pk), 'fields' => array("{$this->request->query['m']}.{$this->request->query['f']}")));
     $file = json_decode($data[$this->request->query['m']][$this->request->query['f']], true);
     header('Content-length: ' . $file['size']);
     header('Content-type: ' . $file['type']);
     header('Content-Disposition: inline; filename=' . $file['name']);
     echo base64_decode($file['content']);
     die;
 }
Ejemplo n.º 10
0
 public function setAvatar($user_id, $avatar)
 {
     $hashids = new Hashids('amtek123456');
     $source = $avatar;
     $filename = 'avatar_u' . $hashids->encode($user_id);
     $manager = new ImageManager();
     $upload_dir = PATH_AVATAR;
     $image = $manager->make($source);
     $image->save($upload_dir . '/' . $filename, 90);
     $data['avatar'] = $filename;
     $this->db->where('user_id', $user_id);
     $this->db->update('profile', $data);
 }
Ejemplo n.º 11
0
 public function test()
 {
     echo __CLASS__, "</br>", __METHOD__, "</br>";
     $id = 12;
     $hashids = new Hashids('this is mysalt111');
     $en = $hashids->encode($id);
     $de = $hashids->decode($en);
     //var_dump($en,$de);
     $a = $_SERVER["REQUEST_URI"];
     $path = $_SERVER["QUERY_STRING"];
     $query = $_SERVER["SCRIPT_NAME"];
     //echo $a,"<br>",$path,"<br>",$query,"<br>",$_SERVER['HOST'];
     var_dump($_SERVER);
     //echo "hiiiiiiiii";
 }
Ejemplo n.º 12
0
 public function test()
 {
     $a = $this->one;
     $u = new User();
     $wo = strpos('fling', $a);
     $_SERVER['yyy'] = "xxx";
     header("HTTP/1.1 204 OK");
     header("cache-control:max-age=0");
     header("cache-control:no-cache");
     header("expires:0");
     header("expires:Tue, 01 Jan 1980 1:00:00 GMT");
     header("pragma:no-cache");
     $view = view("testone")->withName("xj");
     // test jsonp
     return $view;
     /*
     echo "head";
     //echo "php_self=".$_SERVER['PHP_SELF']."<BR>";
     //echo "http_referer=".$_SERVER['HTTP_REFERER']."<BR>";
     //return $_SERVER;
     exit;
     echo $_SERVER['SCRIPT_FILENAME']."<BR>";
     echo $_SERVER['HTTP_HOST'],"<BR>";
     echo $_SERVER['REQUEST_URI'],"<BR>";
     //return $_SERVER;
     //      var_dump($_SERVER);
     */
     //exit;
     //echo __CLASS__,"</br>",__METHOD__;
     //$a=Apacl::getinfo("hello");
     //echo $a;
     $a = msgService::add("aaa");
     $b = new msgService();
     $c = $b->info("waa");
     echo $a;
     echo $c;
     exit;
     echo __CLASS__, "</br>", __METHOD__, "</br>";
     $id = 12;
     $hashids = new Hashids('this is mysalt111');
     $en = $hashids->encode($id);
     $de = $hashids->decode($en);
     //var_dump($en,$de);
     $a = $_SERVER["REQUEST_URI"];
     $path = $_SERVER["QUERY_STRING"];
     $query = $_SERVER["SCRIPT_NAME"];
     var_dump($_SERVER);
 }
Ejemplo n.º 13
0
 /**
  * Decode the hashed value.
  *
  * @param  string  $hashed
  *
  * @return mixed
  */
 public function decode($hashed)
 {
     return head($this->hasher->decode($hashed));
 }
Ejemplo n.º 14
0
use Hashids\Hashids;
/*
 * |--------------------------------------------------------------------------
 * | Routes File
 * |--------------------------------------------------------------------------
 * |
 * | Here is where you will register all of the routes in an application.
 * | It's a breeze. Simply tell Laravel the URIs it should respond to
 * | and give it the controller to call when that URI is requested.
 * |
 */
Route::get('/', function () {
    return view('index');
});
Route::get('/generate/{count}', function ($count) {
    $hashids = new Hashids('smpx', 6);
    echo $hashids->encode($count);
});
Route::resource('/urls', 'UrlController', ['only' => ['index', 'show', 'create', 'store', 'edit', 'destroy', 'update']]);
Route::get('/urls/from/{from}/to/{to}', 'UrlController@getLimitedUrls');
Route::get('/urls/from/{from}', 'UrlController@getLimitedUrlsUsingFrom');
Route::get('/{shortUrl}', 'UrlController@redirect');
/*
 * |--------------------------------------------------------------------------
 * | Application Routes
 * |--------------------------------------------------------------------------
 * |
 * | This route group applies the "web" middleware group to every route
 * | it contains. The "web" middleware group is defined in your HTTP
 * | kernel and includes session state, CSRF protection, and more.
 * |
Ejemplo n.º 15
0
 public function scopeFindByCodeHash($query, $code)
 {
     $hashids = new Hashids('quizprivate123');
     return $query->where('id', $hashids->decode($code))->firstOrFail();
 }
Ejemplo n.º 16
0
 /**
  * Use the encode function to obscure the ids in your views
  *
  * @param $id
  * @return string
  */
 public function encode($id)
 {
     $hashids = new Hashids(config('obscure.salt'), config('obscure.length'), config('obscure.alphabet'));
     return $hashids->encode($id);
 }
Ejemplo n.º 17
0
 public function getHashids()
 {
     $hashids = new Hashids(HASHIDS_SALT);
     $id = $hashids->encode($this->model->id);
     return $id;
 }
Ejemplo n.º 18
0
 /**
  *
  */
 protected function generateId($minLen = 6)
 {
     $salt = 'Muh1tt1n Ne 3tT1n';
     $alphabet = '0123456789ACDEFGHJKLMNPRTUVXYZ';
     $hash = new Hashids($salt, $minLen, $alphabet);
     $mtime = time() - 1420092000;
     // Thu, 01 Jan 2015 06:00:00
     return $hash->encode($mtime);
 }
Ejemplo n.º 19
0
 /**
  * Generate a unique code for this group.
  * This code can be used to join this group
  * @return string
  */
 public function generateCode()
 {
     $hashids = new Hashids('friends', 6, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890');
     $id = $this->getKey();
     $owner_id = $this->owner->getKey();
     $code = $hashids->encode($id, $owner_id);
     return $code;
 }
 /**
  * Number to encode.
  *
  * @param int $number The integer to encode
  * @param int $length The minimum id length setting
  *
  * @return string The hash-like string
  *
  * @api
  */
 public function encodeID(int $number, int $length = 21) : string
 {
     $this->setCipherKey($this->initializationVector);
     $hashids = new Hashids($this->cipherKey, $length);
     return $hashids->encode($number);
 }
Ejemplo n.º 21
0
 /**
  * Get the value of the model's route key.
  *
  * @return mixed
  */
 public function getRouteKey()
 {
     $hashids = new Hashids('MySecretSalt*(&^%$eo&*^%&r', 20);
     return $hashids->encode($this->getKey());
 }
 public function test()
 {
     $hashids = new Hashids(Config::get('app.key'), 16, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
     var_dump($hashids->encrypt(5));
     var_dump($hashids->encrypt(6));
 }
 /**
  * @return void
  */
 public function testSaveWithField()
 {
     $this->Addresses->behaviors()->Hashid->config('field', 'hash');
     $data = ['city' => 'Foo'];
     $address = $this->Addresses->newEntity($data);
     $res = $this->Addresses->save($address);
     $this->assertTrue((bool) $res);
     $this->assertSame(3, $address->id);
     $hasher = new Hashids();
     $expected = $hasher->encode($address->id);
     $this->assertEquals($expected, $address->hash);
 }
Ejemplo n.º 24
0
 public function getLinkDownloadAttribute()
 {
     $hashids = new Hashids($this->hashids_salt);
     $id = $hashids->encode($this->id);
     return kelas_url('course/download/' . $id);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $hashids = new Hashids('smpx', 6);
     $hashed_url = $hashids->encode(125);
     $url = new Url();
     $url->long_url = $request["long_url"];
     $url->short_url = config('app.url') + '/' + $hashed_url;
     $url->is_active = true;
     $url->clicks = 0;
     $urlInstance = $url->create();
     echo $urlInstance->toJson(), "hoeee";
     return;
 }
Ejemplo n.º 26
0
 /**
  * Store a newly created Url in storage.
  * Required: long_url
  * Optional: custom_key, category
  */
 public function create(Request $request)
 {
     //	Get the largest Id of url from db
     $maxId = Url::withTrashed()->max('id');
     //	Validate maxId, and fix it
     if (!isset($maxId)) {
         $maxId = 0;
     }
     //	Validate custom Key (key for short url), and generate new one using MAXID
     if (empty($request["custom_key"])) {
         $hashids = new Hashids('smpx', 6);
         $hashedUrl = $hashids->encode($maxId++);
     } else {
         $hashedUrl = $request["custom_key"];
     }
     //	trim long url (Original Url)
     $longUrl = trim($request["long_url"]);
     //	Validate Long Url and send error if invalid
     if (strlen($longUrl) <= 0) {
         $error = Utility::getError(null, 400, 'Error', 'Invalid Url');
         return response()->json($error, 400);
     }
     //	Check whether Long url contains http protocol or not, If not then append 'http://'
     //	Here not checking for protocols other than http
     if (substr($longUrl, 0, 7) !== "http://" and substr($longUrl, 0, 8) !== "https://") {
         $longUrl = 'http://' . $longUrl;
     }
     //	Validate category
     if (!isset($request["category"]) || $request["category"] == '') {
         $category = 'no_category';
     } else {
         $category = $request["category"];
     }
     //	build array object of Url data to save to DB
     $array = array('long_url' => $longUrl, 'short_url' => config('app.url') . '/' . $hashedUrl, 'is_active' => true, 'clicks' => 0, 'category' => $category);
     try {
         //	save Url data to DB
         $urlInstance = Url::create($array);
     } catch (QueryException $e) {
         // Make logging for QueryException
         $error = Utility::getError(null, 400, 'Error', 'Duplicate Entry of short Url');
         return response()->json($error, 400);
     }
     //	Add attribute 'time' containing humna readable time format
     $urlInstance['time'] = $urlInstance['created_at']->diffForHumans(Carbon::now());
     //	Build response object
     $res = new \stdClass();
     $res->status = 'Success';
     $res->data = $urlInstance;
     $res->message = 'Successfully created';
     //	Send response Object in json string
     return response()->json($res, 200);
 }
Ejemplo n.º 27
0
 /**
  * Generates ticket Hash ID
  *
  * @param integer $id
  *
  * @return string
  */
 public function generateHashId($id)
 {
     $code = new Hashids(Config::get('app.key'), 8, 'ABCDEF1234567890');
     return $code->encode($id);
 }
Ejemplo n.º 28
0
 public function decode($value)
 {
     $hashids = new Hashids(config('paysera.projectid'), 10);
     $decoded = $hashids->decode($value);
     return isset($decoded[0]) ? $decoded[0] : null;
 }
Ejemplo n.º 29
0
Archivo: Hasher.php Proyecto: n8b/VMN
 /**
  * Create unqiue hash and store it in the database
  * @return string Hash
  */
 public function save()
 {
     $url = sanitize_string($this->url);
     $hash = sanitize_string($this->hash);
     $time_created = sanitize_int($this->time_created);
     $meta = !is_string($this->meta) ? json_encode($this->meta) : $this->meta;
     $meta = sanitize_string($meta);
     if (!$this->id) {
         $query = "INSERT INTO {$this->dbprefix}url_meta_cache (long_url, hash, meta, time_created)\n\t\t\t\t\tVALUES ('{$url}','{$hash}','{$meta}',{$time_created})\n\t\t\t\t\t\tON DUPLICATE KEY UPDATE long_url='{$url}',meta='{$meta}'";
         $id = insert_data($query);
         $this->id = $id;
         $hashids = new Hashids(get_site_secret());
         $hash = $hashids->encode($id, $this->time_created);
         $query = "UPDATE LOW_PRIORITY {$this->dbprefix}url_meta_cache\n\t\t\t\t\tSET hash = '{$hash}' WHERE id = {$id}";
         update_data($query);
     } else {
         $query = "UPDATE {$this->dbprefix}url_meta_cache SET meta='{$meta}'\n\t\t\t\t\t\tWHERE id='{$this->id}'";
     }
     self::$cache[$this->url] = array('id' => $this->id, 'hash' => $this->hash, 'meta' => $this->meta, 'time_created' > $this->time_created);
     return $hash;
 }
Ejemplo n.º 30
0
 /**
  * Return the max integer that is supported by PublicId in your environment
  *
  * @access      public
  *
  * @param       string
  * @return      model|null
  */
 public static function testPublicIdMaxInt()
 {
     $hashids = new Hashids(self::getSalt(), self::getMinLength(), self::getAlphabet());
     return $hashids->get_max_int_value();
 }