Exemplo n.º 1
1
 /**
  * Decodes an ID value to the numeric string value
  *
  * @param string $value
  * @param string $config
  *
  * @return int
  */
 public static function decode($value, $config = 'main')
 {
     $id = Hashids::connection($config)->decode($value);
     return isset($id[0]) ? $id[0] : 0;
 }
 /**
  * Boot Eloquent Hashids trait for the model.
  *
  * @return void
  */
 public static function bootEloquentHashids()
 {
     static::created(function (Model $model) {
         $model->{static::getHashidColumn($model)} = Hashids::connection(static::getHashidConnection($model))->encode(static::getHashidEncodingValue($model));
         $model->save();
     });
 }
Exemplo n.º 3
0
 public function makeName($file)
 {
     $filename = $file->getClientOriginalName();
     $extension = $file->getClientOriginalExtension();
     $filename = str_replace($extension, '', $filename);
     return Hashids::encode(time()) . '-' . str_slug(strtolower($filename)) . '.' . $extension;
 }
Exemplo n.º 4
0
 /**
  * Store a new game for the current seed.
  *
  * @param  StoreSeedGameRequest   $request
  *
  * @return Response
  *
  * @api               {post} /v1/seeds/:id/games Store a new game of a seed.
  * @apiVersion        1.0.0
  * @apiName           StoreSeedGame
  * @apiGroup          Seeds
  * @apiPermission     User
  *
  * @apiParam {String} user_id          User unique ID.
  * @apiParam {String} data             Game's data in json format.
  * @apiParam {Number} score            Game's score.
  *
  * @apiUse GamesSuccess
  *
  * @apiUse ApiLimitError
  */
 public function store($seedId, StoreSeedGameRequest $request)
 {
     $user = $this->user->find(Hashids::decode($request->input('user_id')))->first();
     $game = new Game($request->only('data', 'score'));
     $game->user()->associate($user);
     $game = $this->seed->find($seedId)->first()->games()->save($game);
     return $this->response->item($game, new GameTransformer());
 }
Exemplo n.º 5
0
 /**
  * @param $query
  * @param $hashid
  * @return bool|int
  */
 public function scopeWhereHashid($query, $hashid)
 {
     $id = Hashids::decode($hashid);
     if (count($id) == 0) {
         return false;
     }
     return $query->where('id', $id[0]);
 }
Exemplo n.º 6
0
 /**
  * Define the route model bindings, pattern filters, etc.
  *
  * @param \Illuminate\Routing\Router $router
  *
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->bind('analysis', function ($value) {
         $decoded = Hashids::connection('analyses')->decode($value);
         if (isset($decoded[0]) && is_numeric($decoded[0]) && ($analysis = Analysis::find($decoded[0]))) {
             return $analysis;
         }
         throw new NotFoundHttpException('Analysis not found.');
     });
     $router->bind('repo', function ($value) {
         if (is_numeric($value) && ($repo = Repo::find($value))) {
             return $repo;
         }
         throw new NotFoundHttpException('Repo not found.');
     });
 }
Exemplo n.º 7
0
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('bin', function ($value) {
         $id = Hashids::decode($value);
         if (empty($id)) {
             $id = null;
         } else {
             $id = $id[0];
         }
         return Bin::where('id', $id)->first();
     });
     $router->bind('comment', function ($value) {
         $id = Hashids::decode($value);
         if (empty($id)) {
             $id = null;
         } else {
             $id = $id[0];
         }
         return Comment::where('id', $id)->first();
     });
     parent::boot($router);
 }
Exemplo n.º 8
0
 public function Detalles($id)
 {
     $record = Hashids::decode($id);
     $registro = \DB::table('Opciones')->join('menus', 'menus.id', '=', 'Opciones.menu')->where('Opciones.id', '=', $record[0])->select('Opciones.id', 'Opciones.nombre', 'Opciones.imagen', 'Opciones.extra', 'Opciones.descripcion', 'Opciones.costo', 'menus.nombre AS menu')->first();
     return view('Center.menu.detalles')->with('registro', $registro);
 }
Exemplo n.º 9
0
 /**
  * Create a new random id.
  *
  * @return string
  */
 protected function generateUnique()
 {
     $seed = $this->makeUniqueSeed();
     return Hashids::encode($seed);
 }
Exemplo n.º 10
0
 public function Detalles($id)
 {
     $record = Hashids::decode($id);
     $registro = \DB::table('Servicios')->where('Servicios.id', '=', $record[0])->select('Servicios.id', 'Servicios.nombre', 'Servicios.imagen', 'Servicios.descripcion', 'Servicios.estado')->first();
     return view('Center.servicios.detalles')->with('registro', $registro);
 }
Exemplo n.º 11
0
 public function editar($id)
 {
     $record = Hashids::decode($id);
     $registro = Preguntas::find($record[0]);
     return view('Center.preguntas.editar')->with('registro', $registro);
 }
Exemplo n.º 12
0
function decode($value)
{
    $value = Hashids::decode($value);
    return count($value) === 1 ? $value[0] : 0;
}
Exemplo n.º 13
0
<?php

use Vinkla\Hashids\Facades\Hashids;
$api = app('Dingo\\Api\\Routing\\Router');
Route::bind('id', function ($value, $route) {
    return Hashids::decode($value);
});
// Authentification routes
$api->version('v1', ['namespace' => 'NanokaWeb\\AsyncGame\\Api\\V1\\Controllers', 'middleware' => ['api.throttle', 'cors'], 'limit' => 100, 'expires' => 5], function ($api) {
    // Auth email / password
    $api->post('v1/auth/signup', 'AuthController@signup');
    $api->post('v1/auth/login', 'AuthController@login');
    // Auth Facebook token
    $api->post('v1/auth/fblogin', 'AuthController@fbLogin');
    // Auth Device
    $api->post('v1/auth/devicelogin', 'AuthController@deviceLogin');
    //    $api->post('v1/auth/recovery', 'NanokaWeb\AsyncGame\Api\V1\Controllers\AuthController@recovery');
    //    $api->post('v1/auth/reset', 'NanokaWeb\AsyncGame\Api\V1\Controllers\AuthController@reset');
});
// Need auth
$api->version('v1', ['middleware' => ['api.auth', 'api.throttle', 'cors'], 'limit' => 100, 'expires' => 5], function ($api) {
    $api->group(['namespace' => 'NanokaWeb\\AsyncGame\\Api\\V1\\Controllers', 'middleware' => ['asyncgame.roles'], 'roles' => ['root', 'administrator', 'user']], function ($api) {
        /*
         * Endpoint me
         */
        $api->get('v1/me', 'MeController@showMe');
        $api->get('v1/me/opponents/{nb}', 'MeController@opponentsMe')->where('nb', '[0-9]');
        $api->put('v1/me', 'MeController@updateMe');
        $api->post('v1/me/coins', 'MeController@updateCoinsMe');
        /*
         * Endpoint seeds
Exemplo n.º 14
0
 public function Detalles($id)
 {
     $record = Hashids::decode($id);
     $registro = \DB::table('Promociones')->where('Promociones.id', '=', $record[0])->select('Promociones.id', 'Promociones.nombre', 'Promociones.imagen', 'Promociones.descripcion', 'Promociones.inicio', 'Promociones.fin')->first();
     return view('Center.promociones.detalles')->with('registro', $registro);
 }
Exemplo n.º 15
0
 public function url()
 {
     return route('bin.snippet', [Hashids::encode($this->bin_id), Hashids::encode($this->id)]);
 }
Exemplo n.º 16
0
 /**
  * Get the value of the model's route key.
  *
  * @return mixed
  */
 public function getRouteKey()
 {
     return Hashids::encode($this->getKey());
 }
Exemplo n.º 17
0
 /**
  * Get the analysis hashids id.
  *
  * @return string
  */
 protected function id()
 {
     return Hashids::connection('analyses')->encode($this->wrappedObject->id);
 }
Exemplo n.º 18
0
 public function ajax(Request $request)
 {
     $type = $request->type;
     $id = $request->id;
     $record = Bin::where('user_id', auth()->user()->getAuthIdentifier())->find(Hashids::decode($id));
     if (!$record) {
         return response()->json(['msg' => 'There was an issue with your request!'], 422);
     }
     if ($type == 'visibility') {
         $record->visibility = $request->visibility;
         $record->save();
         return response()->json(['msg' => 'Bin updated successfully!'], 200);
     }
     if ($type == 'hash') {
         // make sure bin is private, if not, then hash isn't needed
         if ($record->isPrivate()) {
             // Bin has private hash, request is to delete
             if ($record->isShared()) {
                 $record->private_hash = null;
                 $record->save();
                 return response()->json(['msg' => 'Bin sharing has been disabled!', 'status' => 'disabled'], 200);
             } else {
                 // No private hash exists, create one
                 $record->private_hash = str_random(30);
                 $record->save();
                 return response()->json(['msg' => 'Bin sharing enabled!', 'status' => 'enabled', 'url' => $record->shareUrl()], 200);
             }
         }
         return response()->json(['msg' => 'Bin is not private! No need for share url!'], 400);
     }
     return response()->json([], 200);
 }
Exemplo n.º 19
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     $hash = Hashids::connection('hashtag')->encode(time());
     return Usuarios::create(['twitter_id' => $data['twitter_id'], 'socket_id' => $hash]);
 }
Exemplo n.º 20
0
 /**
  * Funcion que retorna la vista de edicion de registro
  * @param $id - parametro que contiene el id del registro a editar
  */
 public function editar($id)
 {
     $record = Hashids::decode($id);
     $registro = User::find($record[0]);
     $roles = \DB::table('roles')->get();
     return view('Center.empleados.editar')->with('registro', $registro)->with('roles', $roles);
 }