예제 #1
0
 public static function generate_jwt($user)
 {
     $issuedAt = time();
     $tokenId = base64_encode(Random::key(32));
     $serverName = Config::get('serverName');
     /*
      * Create the token as an array
      */
     $data = ['iat' => $issuedAt, 'jti' => $tokenId, 'iss' => $serverName, 'exp' => $issuedAt + 1800, 'data' => ['userId' => $user->id, 'userName' => $user->username]];
     /*
      * Extract the key, which is coming from the config file.
      *
      * Generated with base64_encode(openssl_random_pseudo_bytes(64));
      */
     $secretKey = base64_decode(Config::get('jwt')['key']);
     /*
      * Extract the algorithm from the config file too
      */
     $algorithm = Config::get('jwt')['algorithm'];
     /*
      * Encode the array to a JWT string.
      * Second parameter is the key to encode the token.
      *
      * The output string can be validated at http://jwt.io/
      */
     $jwt = JWT::encode($data, $secretKey, $algorithm);
     return $jwt;
 }
예제 #2
0
 public function login($username = '', $password = '', $remember = '')
 {
     $user = $this->find($username);
     if (!$username && !$password && $this->exists()) {
         Session::put($this->_sessionName, $this->data()->id);
     } else {
         $this->find($username);
         if ($user) {
             if ($this->data()->password === Hash::make($password)) {
                 Session::put($this->_sessionName, $this->data()->id);
                 if ($remember) {
                     $hash = Hash::unique();
                     $hashCheck = $this->_db->get('users_session', ['user_id', '=', $this->data()->id]);
                     if (!$hashCheck->count()) {
                         $this->_db->insert('users_session', ['user_id' => $this->data()->id, 'hash' => $hash]);
                     } else {
                         $hash = $hashCheck->first()->hash;
                     }
                     Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry'));
                 }
                 return true;
             }
         }
     }
     return false;
 }
예제 #3
0
 public function getFacebookInformation()
 {
     if ($this->fb_post_id) {
         $facebookRequest = sprintf('/%s?oauth_token=%s&fields=comments.summary(true).filter(toplevel).fields(parent.fields(id),comments.summary(true),message,from,created_time),likes.summary(true)', $this->fb_post_id, \Config::get('laravel-facebook-sdk.facebook_config.page_access_token'));
         $facebookResponse = \Facebook::get($facebookRequest)->getDecodedBody();
         $this->facebook_information = $facebookResponse;
     }
 }
예제 #4
0
파일: Base.php 프로젝트: weopendata/medea
 /**
  * Get the Neo4j client
  *
  * @return Client
  */
 protected static function getClient()
 {
     $neo4jConfig = \Config::get('database.connections.neo4j');
     // Create an admin
     $client = new Client($neo4jConfig['host'], $neo4jConfig['port']);
     $client->getTransport()->setAuth($neo4jConfig['username'], $neo4jConfig['password']);
     return $client;
 }
예제 #5
0
 private function __construct()
 {
     try {
         $this->_pdo = new \PDO('mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/db'), Config::get('mysql/username'), Config::get('mysql/password'));
     } catch (\PDOException $e) {
         die($e->getMessage());
     }
 }
예제 #6
0
 public function getItem()
 {
     if (!$this->item) {
         $steam = new APIBridge(\Config::get('steam-api.api_key'));
         $this->item = $steam->queryPlayerInventory($this->app_id, $this->bot_steam_id)->findByClassID($this->class_id);
     }
     return $this->item;
 }
예제 #7
0
 public function getComments()
 {
     $comments = $this->comments()->with('user')->where('type', '=', 'post');
     if (\Auth::check()) {
         $blockedUsers = app('App\\Repositories\\blockedUserRepository')->listIds(\Auth::user()->id);
         $comments = $comments->whereNotIn('user_id', $blockedUsers);
     }
     return $comments = $comments->orderBy('id', 'desc')->paginate(\Config::get('post-per-page'));
 }
예제 #8
0
 private static function createUser(Hybrid_User_Profile $profile)
 {
     $user = new User();
     $data = ['email' => $profile->email ? $profile->email : null, 'name' => $profile->displayName, 'avatar' => $profile->photoURL, 'country' => $profile->country, 'gender' => $profile->gender, 'region' => $profile->region, 'phone' => $profile->phone, 'city' => $profile->city, 'address' => $profile->address, 'birthday' => $profile->birthYear . '-' . $profile->birthMonth . '-' . $profile->birthDay, 'language' => $profile->language];
     $user->fill($data);
     $user->token = md5(sha1(\Config::get('app.key') . microtime() . rand()));
     $user->save();
     return $user;
 }
예제 #9
0
 public static function connectToEs()
 {
     if (is_null(static::$_esInstance)) {
         $params = array('hosts' => Config::get('elasticsearch.hosts'));
         static::$_esInstance = new ElasticSearch\Client($params);
     }
     static::setEsIndex(Config::get('elasticsearch.annotationIndex'));
     return static::$_esInstance;
 }
예제 #10
0
 private static function createStartingCountries(Field $field)
 {
     $countries = new Collection();
     for ($x = 0; $x < \Config::get('settings.fieldWidth'); $x++) {
         for ($y = 0; $y < \Config::get('settings.fieldHeight'); $y++) {
             $countries->push(Country::create(['x' => $x, 'y' => $y, 'field_id' => $field->id]));
         }
     }
     return $countries;
 }
예제 #11
0
 /**
  * @param  string $targetRole
  * @param  bool $checkSubRoles
  * @return bool
  */
 public function hasRole($targetRole, $checkSubRoles = true)
 {
     $roles = [];
     foreach ($this->roles as $role) {
         $roles[] = $role->role;
     }
     if (in_array($targetRole, $roles)) {
         return true;
     }
     if (!$checkSubRoles) {
         return false;
     }
     $roleConfigs = \Config::get('admin_user.roles', []);
     foreach ($roles as $role) {
         $subRoles = array_get($roleConfigs, "{$role}.sub_roles", []);
         if (in_array($targetRole, $subRoles)) {
             return true;
         }
     }
     return false;
 }
예제 #12
0
 protected static function connect()
 {
     $params['hosts'] = Config::get('elasticsearch.hosts');
     $es = new Elasticsearch\Client($params);
     return $es;
 }
예제 #13
0
 public function scopeSearch($query, $searchData = array(), $status = '')
 {
     if (!empty($searchData)) {
         $idCountry = $searchData[0]['value'];
         $idCate = $searchData[1]['value'];
         $typeName = $searchData[2]['value'];
         $keyword = $searchData[3]['value'];
         $status = $searchData[4]['value'];
         if (!empty($idCountry)) {
             $query->where('country', $idCountry);
         }
         if (!empty($idCate)) {
             $query->where('category', $idCate);
         }
         if (isset($status) && $status != -1) {
             $query->where('status', $status);
         }
         if (!empty($keyword)) {
             if ($typeName == "company") {
                 $query->where("company", "LIKE", DB::raw("'%{$keyword}%'"));
             } else {
                 $query->where('email', 'LIKE', DB::raw("'%{$keyword}%'"));
             }
         }
     } else {
         if ($status == Config::get('backend.publisher_approved')) {
             $query = $query->where('status', Config::get('backend.publisher_approved'));
         } else {
             $query->where('status', '0');
         }
     }
     return $query;
 }
예제 #14
0
파일: User.php 프로젝트: konato-events/web
 public function setPictureAttribute($file)
 {
     if (is_string($file)) {
         $path = $file;
         //TODO: should we copy the picture to our storage instead?
     } elseif ($file instanceof UploadedFile) {
         //no $file->guessExtension() as this would create dups if the user uploads a pic with a different extension
         $rel_path = 'users/picture-' . $this->id;
         $stored = \Storage::put($rel_path, file_get_contents($file->getRealPath()));
         if (!$stored) {
             $this->errors()->add('picture', _('Sorry, we were unable to save your picture. Can you try again later?'));
         }
         $path = \Config::get('filesystems.root_url') . $rel_path;
     }
     if (isset($path)) {
         //FIXME: resize the picture to create a smaller avatar (what size?)
         $this->attributes['picture'] = $this->attributes['avatar'] = $path;
     }
 }
예제 #15
0
<?php

//namespace app\core;
use app\models\Cookie;
use app\models\Config;
use app\models\Session;
use app\models\User;
use app\classes\DB;
session_start();
$GLOBALS['config'] = ['mysql' => ['host' => '127.0.0.1', 'username' => 'root', 'password' => 'root', 'db' => 'test'], 'remember' => ['cookie_name' => 'hash', 'cookie_expiry' => 604800], 'session' => ['session_name' => 'root', 'token_name' => 'token']];
spl_autoload_register(function ($class) {
    require_once 'classes/' . $class . '.php';
});
require_once "functions/sanitize.php";
if (Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('session/session_name'))) {
    $hash = Cookie::get(Config::get('remember/cookie_name'));
    $hashCheck = DB::connect()->get('users_session', ['hash', '=', $hash]);
    if ($hashCheck->count()) {
        $user = new User($hashCheck->first()->user_id);
        $user->login();
    }
}
예제 #16
0
 /**
  * @param  int $width
  * @param  int $height
  * @return string
  */
 public function getThumbnailUrl($width, $height)
 {
     if (\Config::get('app.offline_mode', false)) {
         return \URL::to('static/img/local/local.png');
     }
     if (empty($this->url)) {
         if ($height == 0) {
             $height = intval($width / 4 * 3);
         }
         return 'https://placehold.jp/' . $width . 'x' . $height . '.jpg';
     }
     $categoryType = $this->file_category;
     $confList = \Config::get('file.categories');
     $conf = array_get($confList, $categoryType);
     if (empty($conf)) {
         return $this->getUrl();
     }
     $size = array_get($conf, 'size');
     if ($width === $size[0] && $height === $size[1]) {
         return $this->getUrl();
     }
     if (preg_match(' /^(.+?)\\.([^\\.]+)$/', $this->url, $match)) {
         $base = $match[1];
         $ext = $match[2];
         foreach (array_get($conf, 'thumbnails', []) as $thumbnail) {
             if ($width === $thumbnail[0] && $height === $thumbnail[1]) {
                 return $base . '_' . $thumbnail[0] . '_' . $thumbnail[1] . '.' . $ext;
             }
             if ($thumbnail[1] == 0 && $height == 0 && $width <= $thumbnail[0]) {
                 return $base . '_' . $thumbnail[0] . '_' . $thumbnail[1] . '.' . $ext;
             }
             if ($thumbnail[1] == 0 && $height != 0 && $size[1] != 0) {
                 if (floor($width / $height * 1000) === floor($size[0] / $size[1] * 1000) && $width <= $thumbnail[0]) {
                     return $base . '_' . $thumbnail[0] . '_' . $thumbnail[1] . '.' . $ext;
                 }
             }
             if ($thumbnail[1] > 0 && $height > 0) {
                 if (floor($width / $height * 1000) === floor($thumbnail[0] / $thumbnail[1] * 1000) && $width <= $thumbnail[0]) {
                     return $base . '_' . $thumbnail[0] . '_' . $thumbnail[1] . '.' . $ext;
                 }
             }
         }
     }
     return $this->getUrl();
 }
예제 #17
0
 public function __construct()
 {
     parent::__construct();
     $this->sizes = array_keys(['o' => TRUE] + \Config::get('media.sizes'));
 }
예제 #18
0
파일: Doc.php 프로젝트: st421/madison
 public static function esConnect()
 {
     $esParams['hosts'] = \Config::get('elasticsearch.hosts');
     $es = new \Elasticsearch\Client($esParams);
     return $es;
 }
예제 #19
0
 public function meta()
 {
     $meta = ['title' => "p" . $this->num . " - Flaneur #3", 'description' => $this->descr, 'og:type' => 'books.book', 'og:title' => "p" . $this->num . " - Flaneur #3", 'og:description' => $this->descr, 'og:image' => $this->thumb, 'og:see_also' => $this->feeds()->lists('url'), 'books:isbn' => Config::get('flaneur.isbn'), 'books:initial_release_date' => Config::get('flaneur.initial_release_date'), 'books:release_date' => $this->updated_at];
     return $meta;
 }
 public function getRoleName()
 {
     return \Lang::get(\Config::get('admin_user.roles.' . $this->role . '.name'));
 }
예제 #21
0
 /**
  * Determines whether or not the provided subdomain
  * meets subdomain length and character requirements.
  * 
  * @param string $subdomain
  * @return bool
  */
 public function isValidSubdomain($subdomain)
 {
     $subdomain = lowertrim($subdomain);
     $min_length = Config::get('stryve.tenant.subdomain-min-length');
     $max_length = Config::get('stryve.tenant.subdomain-max-length');
     $subdomain_length = strlen($subdomain);
     // check subdomain is of valid characters
     if (!isValidSubdomain($subdomain)) {
         return false;
     }
     // check subdomain meets length requirements
     if ($subdomain_length < $min_length || $subdomain_length > $max_length) {
         return false;
     }
     return true;
 }
예제 #22
0
파일: Listing.php 프로젝트: remix101/compex
 public function getStatusAttribute()
 {
     switch ($this->property_status) {
         case \Config::get('constants.PROPERTY_STATUS_NA'):
             return 'N/A';
         case \Config::get('constants.PROPERTY_STATUS_FREEHOLD'):
             return 'Real Property';
         case \Config::get('constants.PROPERTY_STATUS_LEASE'):
             return 'On Lease';
         case \Config::get('constants.PROPERTY_STATUS_BOTH'):
             return 'Both';
     }
 }