/** * Run the database seeds. * * @return void */ public function run() { $access_token = generate_access_token(); $email = 'a1t1-' . generate_email() . '@telegramlogin.com'; $user = new User(); $user->name = 'david pichsenmeister'; $user->username = '******'; $user->email = $email; $user->telegram_id = 41478911; $user->access_token = $access_token; $user->save(); $app = new App(); $app->user_id = $user->id; $app->name = 'Telegram Login'; $app->client_id = 314159265; $app->client_secret = generate_client_secret(); $app->website = env('URL'); $app->redirect_url = env('URL') . '/login'; $app->save(); $tg = new TelegramUser(); $tg->telegram_id = 41478911; $tg->name = 'david pichsenmeister'; $tg->username = '******'; $tg->save(); $auth = new Auth(); $auth->app_id = $app->id; $auth->telegram_user_id = $tg->id; $auth->email = $email; $auth->access_token = $access_token; $auth->save(); }
/** * Method to instantiate the view. * * @param App $app The application object. * @param ModelInterface $model The model object. * @param string|array $templatesPaths The templates paths. * * @throws \RuntimeException * @since 1.0 */ public function __construct(App $app, ModelInterface $model, $templatesPaths = '') { parent::__construct($model); $this->app = $app; $renderer = $app->getContainer()->get('config')->get('renderer.type'); $className = 'App\\View\\Renderer\\' . ucfirst($renderer); if (false == class_exists($className)) { throw new \RuntimeException(sprintf('Invalid renderer: %s', $renderer)); } $config = array(); $config['templates_base_dir'] = JPATH_TEMPLATES; // Load the renderer. $this->renderer = new $className($config); // Register application's Twig extension. $this->renderer->addExtension(new TwigExtension($app)); // Register additional paths. if (!empty($templatesPaths)) { $this->renderer->setTemplatesPaths($templatesPaths, true); } // Register the theme path $this->renderer->set('themePath', DEFAULT_THEME . '/'); // Retrieve and clear the message queue $this->renderer->set('flashBag', $app->getMessageQueue()); $app->clearMessageQueue(); }
public function testCatchException() { $stub = \Mockery::mock('Load'); $stub->shouldReceive('getExceptionHandler')->once()->andReturnSelf(); $stub->shouldReceive('catchException')->once(); MockTest::inject($this->app, 'load', $stub); $this->app->catchException(null); }
/** * Récupère les genres d'un album */ public function getGenres() { if (isset($this->id)) { $this->genres = App::getInstance()->getTable('Genres')->allByAlbum($this->id); $this->total_genres = count($this->genres); } }
private function getUser($code, $state) { $app = App::findByClientId(314159265); $params = array('code' => $code, 'client_id' => $app->client_id, 'client_secret' => $app->client_secret); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, env('URL') . '/code'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $json = curl_exec($ch); $result = json_decode($json, true); if (!array_key_exists('access_token', $result)) { app()->abort($result['error'], $result['description']); } if (array_key_exists('active', $result) && !$result['active']) { app()->abort($result['error'], $result['description']); } $tg = TelegramUser::findByTelegramId($result['telegram_user']['telegram_id']); if ($tg->status != $state) { app()->abort(403, 'Invalid state.'); } $tg->status = 'access_granted'; $tg->save(); try { $user = User::findByTelegramId($result['telegram_user']['telegram_id']); } catch (ModelNotFoundException $e) { $user = new User(); $user->email = $result['email']; $user->telegram_id = $result['telegram_user']['telegram_id']; } $user->access_token = $result['access_token']; $user->name = $result['telegram_user']['name']; $user->username = $result['telegram_user']['username']; $user->save(); return $user; }
public function actionDelete() { if (!isset($_POST['imageId'])) { App::instance()->show404(); exit; } /** @var \models\Image $model */ $model = Image::findByID((int) $_POST['imageId']); if (!$model || $model->uid != App::instance()->getUser()->getId()) { App::instance()->show404(); exit; } if ($model->delete()) { $response['error'] = false; } else { $response = json_encode(['error' => true]); } if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 'XMLHttpRequest' === $_SERVER['HTTP_X_REQUESTED_WITH']) { $response['totalCount'] = Image::countByProp('uid', App::instance()->getUser()->getId()); echo json_encode($response); } else { $this->redirect('/site/index/'); echo $response; } }
public function __construct(array $attributes = []) { parent::__construct($attributes); $this->errors = new MessageBag(); $this->validator = \App::make('validator'); $this->manejaConcurrencia = true; }
/** * login process */ public static function login() { // form validation if (!filter_input(INPUT_POST, "form_token") || Form::isFormTokenValid(filter_input(INPUT_POST, "form_token"))) { View::setMessageFlash("danger", "Form tidak valid"); return FALSE; } if (!filter_input(INPUT_POST, "username") || !filter_input(INPUT_POST, "password")) { View::setMessageFlash("danger", "Masukkan Username dan Password"); return FALSE; } $username = filter_input(INPUT_POST, "username", FILTER_SANITIZE_STRING); $password = md5(filter_input(INPUT_POST, "password", FILTER_SANITIZE_STRING)); $mysqli = App::getConnection(true); $sql = "SELECT user_id FROM users WHERE username='******' AND password='******'"; if (!($query = $mysqli->query($sql))) { View::setMessageFlash("danger", $mysqli->error); return FALSE; } if ($query->num_rows == 0) { View::setMessageFlash("danger", "Username dan Password Salah"); return FALSE; } $row = $query->fetch_row(); $_SESSION['user_id'] = $row[0]; return TRUE; }
public function translation($language = null) { if ($language == null) { $language = App::getLocale(); } return $this->hasMany('App\\CategoryTranslation')->where('language_id', '=', $language); }
private static function config() { if (!static::$Config) { static::$Config = App::config('db'); } return static::$Config; }
public function actionLogout() { if (!App::instance()->isGuest()) { App::instance()->logoutUser(); } $this->redirect('/site/index/'); }
/** * Récupère les albums d'un artiste */ public function getAlbums() { if (isset($this->id)) { $this->albums = App::getInstance()->getTable('Albums')->allByArtist($this->id); $this->total_albums = count($this->albums); } }
public static function getLastWithCategories() { return App::getDatabase()->query(' SELECT article.id, article.titre, article.contenu, categories.titre as categorie FROM article LEFT JOIN categories ON categories.id = article.category_id', __CLASS__); }
/** * Returns the singleton instance of this class. * * @return DatabaseService */ public static function instance() { if (!isset(self::$instance)) { $db = App::instance()->config['db']; self::$instance = new \PDO('mysql:host=' . $db['host'] . ';dbname=' . $db['name'], $db['username'], $db['password'], $db['options']); } return self::$instance; }
public function appView($app_id) { $appInfo = App::dataHandle(App::find($app_id)); if (!$appInfo) { header('Location:' . action('App\\Http\\Controllers\\HomeController@index')); } $commendApps = App::dataHandle(App::where('category_id', '=', $appInfo->category_id)->where('id', '!=', $app_id)->orderBy('download', 'desc')->take(4)->get()); return view('index.appView')->with(['appInfo' => $appInfo, 'commendApps' => $commendApps]); }
public function __construct($id) { $mysqli = App::getConnection(true); $sql = "SELECT * FROM " . $this->table . " WHERE " . $this->key . " = '" . $id . "'"; if (!($query = $mysqli->query($sql))) { return; } $this->data = $query->fetch_assoc(); }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { if ($this->route('app')) { $id = $this->route('app'); $user = $this->user(); return App::where('id', '=', $id)->where('user_id', '=', $user->id)->exists(); } return $this->user() ? true : false; }
public function __construct() { parent::__construct(); $app = App::getInstance(); $auth = new DBAuth($app->getDb()); if (!$auth->logged()) { $this->forbidden(); } }
public function scopeGetPage($query, $slug) { $query = $query->where('slug', '=', $slug)->firstOrFail(); if (!$query) { App::abort(404); } else { return $query; } }
/** * Run the database seeds. * * @return void */ public function run() { $cid = ['社交·娱乐' => 1, '射击·竞速' => 2, '冒险·益智' => 3, '场景·体验' => 4, '其他' => 5]; /* //3个平台 $platforms = [ 'android', 'ios', 'oculus' ]; foreach ($platforms as $platform) { for($i =1; $i<=5; $i++){ for($j=1; $j<=20; $j++){ App::create([ 'ids' => uniqid(), 'name_chn' => '星际战争', 'name_eng' => 'Insectizide Wars VR', 'description' => '《星际战争》是一款ios虚拟现实格斗射击游戏。一个巨大的不明飞行物接近太阳系,并且飞快的像地球靠近,地球为了避免比撞击到,所以做出了相应的对策,当发现这个不明飞行并不是自然现象的时候,地球人类派出了宇宙飞船,进行保卫地球计划。喜欢星际题材的玩家快快下载体验吧!', 'platform' => $platform, 'operation' => 'head', 'cid' => $i, ]); } } }*/ //1 $file = file_get_contents('http://101.69.251.189:2183/android.json'); $c = json_decode($file, true); foreach ($c as $v) { //$type = str_replace('.', '', $v['type']); if ($v['name'] == $v['nameE']) { $v['name'] = ''; } App::create(['ids' => $v['id'], 'name_chn' => $v['name'], 'name_eng' => $v['nameE'], 'thumb' => $v['img'], 'description' => $v['info'], 'platform' => 'android', 'operation' => 'head', 'source' => $v['src'], 'cid' => isset($cid[$v['type']]) ? $cid[$v['type']] : 5]); } //2 $file = file_get_contents('http://101.69.251.189:2183/ios.json'); $c = json_decode($file, true); foreach ($c as $v) { //$type = str_replace('.', '', $v['type']); if ($v['name'] == $v['nameE']) { $v['name'] = ''; } if (isset($v['src'])) { App::create(['ids' => $v['id'], 'name_chn' => $v['name'], 'name_eng' => $v['nameE'], 'thumb' => $v['img'], 'description' => $v['info'], 'platform' => 'ios', 'operation' => 'head', 'source' => $v['src'], 'cid' => isset($cid[$v['type']]) ? $cid[$v['type']] : 5]); } } //3 $file = file_get_contents('http://101.69.251.189:2183/oculus.json'); $c = json_decode($file, true); foreach ($c as $v) { //$type = str_replace('.', '', $v['type']); if ($v['name'] == $v['nameE']) { $v['name'] = ''; } App::create(['ids' => $v['id'], 'name_chn' => $v['name'], 'name_eng' => $v['nameE'], 'thumb' => $v['img'], 'description' => $v['info'], 'platform' => 'oculus', 'operation' => 'head', 'source' => $v['src'], 'cid' => isset($cid[$v['type']]) ? $cid[$v['type']] : 5]); } }
/** * 获取模板绝对路径 * * @param string $tpl * @return string */ protected function getTplPath($tpl) { $slash = strpos($tpl, ':'); if ($slash !== false) { $tpl = $slash === 0 ? substr($tpl, 1) : str_replace(':', '/', $tpl); } else { $controller = App::getController(); $tpl = strtolower($controller) . '/' . $tpl; } return $tpl; }
public function generateToken(Request $request, $clientId) { $app = App::findByClientId($clientId); $token = $this->createToken($app); $query = str_replace($request->url(), '', $request->fullUrl()); if ($query && strlen($query)) { $token->query_string = substr($query, 1); $token->save(); } return redirect('https://telegram.me/' . env('BOT_NAME') . '?start=' . $token->token); }
/** * Constructor */ public function __construct() { //create new App instance if no one $this->_connection = App::instance()->getDb(); $currencyDbName = Processor::$currencyDbInfo['tableName']; $sql = "SELECT id ,pair FROM {$currencyDbName}"; $stmnt = $this->_connection->query($sql); $results = $stmnt->fetchAll(PDO::FETCH_ASSOC); foreach ($results as $result) { $this->_currencyPairs[$result['pair']] = (int) $result['id']; } }
public function translationCompanyInformation($language = null) { if ($language == null) { $language = App::getLocale(); } if ($language == 'kh') { return $this->getAttribute('company_information_kh'); } elseif ($language == 'ch') { return $this->getAttribute('company_information_ch'); } else { return $this->getAttribute('company_information'); } }
public function update() { $mysqli = App::getConnection(true); $sql = "UPDATE " . $this->table . " SET "; $sql .= "name='" . $this->data['name'] . "', "; $sql .= "phone='" . $this->data['phone'] . "', "; $sql .= "address='" . $this->data['address'] . "' "; $sql .= "WHERE " . $this->key . "='" . $this->data[$this->key] . "' "; if (!($query = $mysqli->query($sql))) { return FALSE; } return TRUE; }
public function login() { $errors = false; if (!empty($_POST)) { $auth = new DBAuth(App::getInstance()->getDb()); if ($auth->login($_POST['username'], $_POST['password'])) { header('Location: index.php?page=admin.post.index'); } else { $errors = true; } } $form = new FoundationForm($_POST); $this->render('user.login', compact('form', 'errors')); }
/** * 初始化session环境 * * @return bool */ public static function init() { if (self::$start) { return true; } /**@type \handler\ISessionHandler $session*/ $session = App::getConfig()->getSessionHandler(); if (!$session->isDisabled()) { session_set_save_handler(array($session, 'open'), array($session, 'close'), array($session, 'read'), array($session, 'write'), array($session, 'destroy'), array($session, 'gc')); } session_name('XSSSESSID'); session_start(); self::$start = true; return true; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function code(Requests\CodeRequest $request) { try { $app = App::findByClientIdAndClientSecret($request->input('client_id'), $request->input('client_secret')); $code = Code::findByAppAndCode($app, $request->input('code')); $auth = $code->auth()->first(); if (!$auth || !$auth->active) { return response()->json(['error' => 401, 'description' => 'No active user found.'], 401); } else { $auth->telegram_user = $auth->telegramUser()->first(); return response()->json($auth); } } catch (ModelNotFoundException $e) { return response()->json(['error' => 404, 'description' => 'Invalid code.'], 404); } }
/** * @param BaseModel $model * @param $propName */ public static function isUnique(BaseModel $model, $propName, $scenario = []) { if (isset($model->{$propName}) && (empty($scenario) || in_array($model->scenario, $scenario))) { /** @var PDO $connection */ $connection = App::instance()->getDB(); $modelTable = $model::tableName(); $sql = "SELECT COUNT(id) AS cnt FROM {$modelTable} WHERE {$propName} = :value"; $stmnt = $connection->prepare($sql); $stmnt->execute([':value' => $model->{$propName}]); $result = $stmnt->fetch(PDO::FETCH_ASSOC); if (false !== $result && 0 == $result['cnt']) { return; } $model->addErrorMsg($propName, 'Already exists.'); } }
/** * Shell out to phantomjs to take a screenshot of our chart + download the svg * * @param string $slug The chart slug to export. * @param int $width Desired width in pixels of the exported image. * @param int $height Desired height in pixels of the exported image. * @param string $format Either "svg" or "png". Both will be saved, only affects return * @return string Path to exported file. */ public static function export($slug, $query, $width, $height, $format) { $phantomjs = base_path() . "/node_modules/.bin/phantomjs"; $rasterize = base_path() . "/phantomjs/rasterize.js"; $target = \Request::root() . "/" . $slug . ".export" . "?" . $query; $queryHash = hash('md5', $query); $pngFile = public_path() . "/exports/" . $slug . "-" . $queryHash . ".png"; $returnFile = public_path() . "/exports/" . $slug . "-" . $queryHash . "." . $format; if (!file_exists($returnFile)) { $command = $phantomjs . " " . $rasterize . " " . escapeshellarg($target) . " " . escapeshellarg($pngFile) . " '" . $width . "px*" . $height . "px'" . " 2>&1"; Log::info($command); exec($command, $output, $retval); if ($retval != 0) { return \App::abort(406, json_encode($output)); } } return $returnFile; }