/** * __construct * * Constructs the object. * * @access public * @param \Pimple $pimple * @return void */ public function __construct(\Pimple $pimple) { $this->pimple = $pimple; $this->config = $pimple['config']; $this->setReporting(); $appDir = $this->config['general.appDir'] . 'src'; $appLoader = new Autoloader($this->config['general.namespace'], $appDir); $appLoader->register(); $this->router = new Router($this->pimple); $this->session = $this->pimple['session']; $this->session->start(); $this->session->set('language', $this->session->get('language', $this->config['general.default_language'])); }
public static function getSessionAppIdByAppUrl($appUrl) { $session = new \Symfony\Component\HttpFoundation\Session\Session(); $aplicativos = $session->get('aplicativos'); if (!$aplicativos) { return null; } foreach ($aplicativos as $aplicativo) { if ($aplicativo['prefijoUrl'] == $appUrl) { return $aplicativo['id']; } } return null; //return isset($_SESSION['_sf2_attributes']['aplicativo.id']) ? $_SESSION['_sf2_attributes']['aplicativo.id'] : null; //return $session->get('aplicativo.id'); }
/** * @param Symfony\Component\HttpFoundation\Session\Session $session * @return mixed */ public function sessionStateGet($session) { return $session->get(static::SESSION_STATE_KEY); }
/** * @author: lmkhang - skype * @date: 2016-01-15 * Getting and Processing registration from Daily API * */ public function callback_daily_channel(Request $request) { $get = $request->all(); if (isset($get['code']) && $get['code'] != '') { $code = $get['code']; $api_key = \App\Config::where(['prefix' => 'daily', 'name' => 'api_key_channel', 'del_flg' => 1])->get()[0]['value']; $api_secret = \App\Config::where(['prefix' => 'daily', 'name' => 'api_secret_channel', 'del_flg' => 1])->get()[0]['value']; $url_callback = \App\Config::where(['prefix' => 'daily', 'name' => 'url_callback_channel', 'del_flg' => 1])->get()[0]['value']; $get_token = \App\Config::where(['prefix' => 'daily', 'name' => 'get_token', 'del_flg' => 1])->get()[0]['value']; $urlHome = config('app.url'); $data = ['grant_type' => 'authorization_code', 'client_id' => $api_key, 'client_secret' => $api_secret, 'redirect_uri' => $urlHome . $url_callback, 'code' => $code]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $get_token); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, count($data)); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $response = curl_exec($ch); $error = curl_error($ch); curl_close($ch); $response = json_decode($response, true); if (isset($response['access_token'])) { //set Dailymotion Login SESSION $session = new \Symfony\Component\HttpFoundation\Session\Session(); $session->set('daily_channel_access_token', $response['access_token']); $session->set('daily_channel_refresh_token', $response['refresh_token']); $session->set('daily_channel_uid', $response['uid']); //get status $status = config('constant.channel_status'); //get Info $url_get_info = str_replace(['{USER_ID}'], [$response['uid']], \App\Config::where(['prefix' => 'daily', 'name' => 'url_get_info', 'del_flg' => 1])->get()[0]['value']); $ch = curl_init(); $data_auth = ['access_token' => $response['access_token']]; curl_setopt($ch, CURLOPT_URL, $url_get_info); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, count($data_auth)); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_auth); $response_auth = curl_exec($ch); $error_auth = curl_error($ch); curl_close($ch); $response_auth = json_decode($response_auth, true); //Check existed account $channel_get = new \App\Channels(); $channel = $channel_get->getChannel($session->get('daily_channel_uid')); if (!$channel) { //Insert $channel = new \App\Channels(); $channel->user_id = $this->_user_id; $channel->daily_channel_id = $session->get('daily_channel_uid'); $channel->daily_channel_username = $response_auth['username']; $channel->daily_channel_name = $response_auth['screenname']; $channel->email = $response_auth['email']; $channel->save(); //set Flash Message $this->setFlash('message', 'Add New Channel Successfully!'); return Redirect::intended($this->_page_url)->with('message', 'Add New Channel Successfully!'); } else { if ($channel && $channel->user_id == $this->_user_id) { //checking user was changed from dailymotion -> update if ($response_auth['username'] != $channel->daily_channel_username) { $old_username = $channel->daily_channel_username; $channel->daily_channel_username = $response_auth['username']; $channel->save(); //set Flash Message $this->setFlash('message', 'The system updated username for your channel from: ' . $old_username . ' to: ' . $response_auth['username']); return Redirect::intended($this->_page_url)->with('message', 'We updated username for your channel: ' . $response_auth['username']); } else { //set Flash Message $this->setFlash('message', 'This channel had been added by you!. This channel is ' . $status[$channel->status]); return Redirect::intended($this->_page_url)->with('message', 'This channel had been added by you!. This channel is ' . $status[$channel->status]); } } else { if ($channel && $channel->user_id != $this->_user_id) { //set Flash Message $this->setFlash('message', 'This channel had been added by other person!'); return Redirect::intended($this->_page_url)->with('message', 'This channel had been added by other person!'); } } } } } //set Flash Message $this->setFlash('message', 'Error!'); return Redirect::intended($this->_page_url)->with('message', 'Error!'); }
/** * @author: lmkhang - skype * @date: 2016-01-05 * Getting and Processing registration from GG API * */ public function callback_google() { //Check isLogged if ($this->isLogged()) { die; } $session = new \Symfony\Component\HttpFoundation\Session\Session(); //get Info of Google's API $google['api_key'] = \App\Config::where(['prefix' => 'google', 'name' => 'api_key', 'del_flg' => 1])->get()[0]['value']; $google['client_id'] = \App\Config::where(['prefix' => 'google', 'name' => 'client_id', 'del_flg' => 1])->get()[0]['value']; $google['client_secret'] = \App\Config::where(['prefix' => 'google', 'name' => 'client_secret', 'del_flg' => 1])->get()[0]['value']; $google['scope'] = \App\Config::where(['prefix' => 'google', 'name' => 'scope', 'del_flg' => 1])->get()[0]['value']; $google['url_callback'] = \App\Config::where(['prefix' => 'google', 'name' => 'url_callback', 'del_flg' => 1])->get()[0]['value']; //Create Client Request to access Google API $client = new \Google_Client(); $client->setApplicationName("Media Center Network"); $client->setClientId($google['client_id']); $client->setClientSecret($google['client_secret']); $client->setRedirectUri(config('app.url') . $google['url_callback']); $client->setDeveloperKey($google['api_key']); $client->addScope(explode(',', $google['scope'])); //Send Client Request $objOAuthService = new \Google_Service_Oauth2($client); //Authenticate code from Google OAuth Flow //Add Access Token to Session if (isset($_GET['code'])) { $client->authenticate($_GET['code']); //set Facebook Login SESSION $session->set('google_access_token', $client->getAccessToken()); return redirect(filter_var(config('app.url') . $google['url_callback'], FILTER_SANITIZE_URL)); } //Set Access Token to make Request if ($session->has('google_access_token')) { $client->setAccessToken($session->get('google_access_token')); } //Get User Data from Google Plus //If New, Insert to Database if ($client->getAccessToken()) { $userData = $objOAuthService->userinfo->get(); $user_get = get_object_vars($userData); if ($user_get && is_array($user_get)) { //Check existed account $registration_system = config('constant.registration'); $user = $this->checkAccountSNS(['username' => $user_get['id']], $registration_system['google']); if (!$user) { //insert $match = new Libraries\Math(); $register['refer'] = $match->to_base(rand(10, 30) . substr(time(), 5, 10) . rand(10, 30), 62) . $match->to_base(rand(100, 300) . substr(time(), 5, 10) . rand(100, 300), 62) . $match->to_base(rand(100, 300) . substr(time(), 5, 10) . rand(100, 300), 62); //from_refer if ($this->hasFlash('refer')) { $register['from_refer'] = $this->getFlash('refer'); } else { $register['from_refer'] = 'no_refer'; } $message_refer = $this->checkUserAttributes($register); $user = new \App\User(); $user->refer = $register['refer']; $user->from_refer = !$message_refer ? $register['from_refer'] : ''; $user->username = $user_get['id']; $user->first_name = $user_get['givenName']; $user->last_name = $user_get['familyName']; $user->full_name = $user_get['name']; $user->email = ''; //$user_get['email']; $user->gavatar = $user_get['picture']; // $user->country = strtoupper($user_get['locale']); $user->del_flg = 1; $user->registration_system = $registration_system['google']; $user->save(); //Insert User Stats $user_stats = new \App\UserStats(); $user_stats->user_id = $user->user_id; $user_stats->total = 0; $user_stats->del_flg = $user->del_flg; $user_stats->save(); } //Set Session $this->setLogSession(['email' => $user->email, 'user_id' => $user->user_id, 'registration_system' => $user->registration_system]); //set Flash Message $this->setFlash('message', 'Welcome to MCN!'); // return Redirect::intended('/')->with('message', 'Register successfully!'); } } // return Redirect::intended('/')->with('message', 'Back Home!'); if (!$this->hasFlash('message')) { //set Flash Message $this->setFlash('message', 'Error!'); } return redirect('/'); }
public function createUser() { $this->user = $this->pimple['user']; if ($this->session->get('user_id', 0) != 0) { $entityName = '\\' . $this->config['general.namespace'] . '\\Model\\Entity\\' . User; $userEntity = $this->entityManager->find($entityName, $this->session->get('user_id')); $this->user->setEntity($userEntity); } $this->user->setLanguage($this->session->get('language', $this->config['general.default_language'])); }
/** * {@inheritdoc} */ public static function get($name, $default = null) { return static::$instance->get($name, $default); }