/** * OAuth2 response handler */ public static function authenticateUser($code) { $retVal = false; $client = self::_createOAuth2(); $auth = new OAuth2\Strategy\AuthCode($client); try { $token = $auth->getToken($code, ['redirect_uri' => REDDIT_HANDLER]); if ($token) { $response = $token->get('https://oauth.reddit.com/api/v1/me.json'); $data = json_decode($response->body()); if ($data) { $user = self::getByName($data->name); if (!$user) { // Block out new user accounts if ((int) $data->created > time() - REDDIT_MINAGE) { $retVal = false; } else { $user = new User(); $user->name = $data->name; $user->ip = $_SERVER['REMOTE_ADDR']; if ($user->sync()) { $retVal = true; } } } else { $retVal = true; } Lib\Session::set('user', $user); } } } catch (Exception $e) { } return $retVal; }
/** * OAuth2 response handler */ public static function authenticateUser($code) { $retVal = false; $client = self::_createOAuth2(); $auth = new OAuth2\Strategy\AuthCode($client); try { $token = $auth->getToken($code, ['redirect_uri' => REDDIT_HANDLER]); if ($token) { $response = $token->get('https://oauth.reddit.com/api/v1/me.json'); $data = json_decode($response->body()); if ($data) { $user = self::getByName($data->name); if (!$user) { $user = new User(); $user->name = $data->name; $user->age = (int) $data->created; $user->ip = $_SERVER['REMOTE_ADDR']; if ($user->sync()) { $retVal = true; } } else { // This is to update any records that were created before age was tracked if (!$user->age) { $user->age = (int) $data->created; $user->sync(); } $retVal = true; } Lib\Session::set('user', $user); } } } catch (Exception $e) { } return $retVal; }
/** * @access public * @param string $name * @param int $length * @return string */ public static function generateCSRFToken($name, $length = 100) { $token = Helper::random($length); Session::Start(); Session::Set($name, $token); return hash('sha256', $token); }
public static function isAdmin() { $admin = \Lib\Session::get('admin'); if ($admin) { return true; } else { return false; } }
function users() { if (Session::isSession('user')) { $user = new User(); $usersData = $user->getAll(); $this->view->addUsers($usersData); $this->view->forAjax('users'); } else { Error::authFail(); } }
public static function intended($default = null) { if (\Lib\Session::get('intended')) { $to = \Lib\Session::get('intended'); \Lib\Session::delete('intended'); header("Location: {$to}"); exit; } header("Location: {$default}"); exit; }
public function __construct() { ob_start(); $url = \Lib\Tools::currentPageURL(); $path_config = parse_url($url, PHP_URL_HOST); require_once "app/Config." . $path_config . ".php"; // hata yakalama ayarları set_exception_handler('Core\\Logger::exceptionHandler'); set_error_handler('Core\\Logger::errorHandler'); // sessions başlat \Lib\Session::init(); // TODO :: iptal edilebilir // set vasyılan template ayarı \Lib\Session::set('template', 'default'); }
function deletePost($alias) { if (Session::isSession('user')) { $user = new User(); $user->findByName(Session::getData('user')); $authlevel = $user->getAuthlevel(); if ($authlevel > 3) { $toDelete = new PostModel(); $toDelete->deleteByAlias($alias); $posts = new PostModel(); $this->view->addAuthlevel($authlevel); $this->view->addPosts($posts->getAll()); $this->view->forAjax('index'); } } }
private function check() { $admin = \Lib\Session::get('admin'); $id = \Lib\Session::get('id'); $login = \Lib\Session::get('login'); $admin_mode = $this->http->post('admin'); if (!$admin) { if ($this->http->isActive('login') && $admin_mode) { $login = $this->http->post('login'); $password = $this->http->post('password'); if ($login == ADMIN_LOGIN && $password == ADMIN_PASSWORD) { \Lib\Session::set('admin', true); Location::To(URL . 'admin'); } else { $this->render('Login', array('categories' => $this->categories, 'd_product' => $this->d_product, 'ids' => $this->category_ids, 'error' => 'Nieprawidłowa nazwa użytkownika lub hasło.')); } } } else { Location::To(URL . 'admin'); } if (empty($id) || empty($login)) { if ($this->http->isActive('login') && !$admin_mode) { $this->m_login = new \Models\Login(); if ($this->m_login->login($this->http->post('login'), $this->http->post('password'))) { if ($this->m_login->isActivated($this->http->post('login'))) { \Lib\Session::set('id', $this->m_login->getId()); \Lib\Session::set('login', $this->m_login->getLogin()); Location::intended(URL . 'user'); } else { $this->render('Login', array('categories' => $this->categories, 'd_product' => $this->d_product, 'ids' => $this->category_ids, 'error' => 'Konto jest nieaktywne.')); } } else { $this->render('Login', array('categories' => $this->categories, 'd_product' => $this->d_product, 'ids' => $this->category_ids, 'error' => 'Nieprawidłowa nazwa użytkownika lub hasło.')); } } else { $this->render('login', array('categories' => $this->categories, 'd_product' => $this->d_product, 'ids' => $this->category_ids)); } } else { Location::To(URL . 'user'); } }
<?php use Lib\Session; use Lib\Helper; ?> <div class="col-xs-12 col-sm-12 col-md-10 col-lg-10 col-md-offset-1 col-lg-offset-1"> <div class="panel panel-danger"> <div class="panel-heading"> <h3 class="panel-title">Edit post</h3> </div> <div class="panel-body"> <form id="post"> <input type="hidden" id="posted_by" class="form-control" value="<?php echo Session::getData('user'); ?> "> <input type="hidden" id="id" class="form-control" value="<?php echo $data['id']; ?> "> <input type="text" id="post_title" class="form-control" placeholder="Post title" value="<?php echo $data['title']; ?> "> <br> <textarea name="" id="post_text" class="form-control" rows="3" required="required" placeholder="Post text"><?php echo $data['text']; ?> </textarea>
/** * düzenleme alanı * * @param int $id * @return mixed */ public function edit($post_id) { $languages = $this->_model->All_languages(); // tüm diller foreach ($languages as $value) { $lng = $value['slug']; $data['lang'][$lng] = $this->_model->fetch_cats($post_id, $lng); } $data['languages'] = $languages; $data['_setting'] = $this->default_params(); $data_head['page_title'] = 'Sayfa Düzenleme'; $data['post_id'] = $post_id; // && \Lib\Tools::is_ajax() if ($this->request->getMethod() == 'POST') { $this->post->editCat(); $ok = \Lib\Tools::message_ver('ok', 'Bilgileriniz başarı ile değiştirilmiştir'); \Lib\Session::set('message', $ok); \Lib\Url::redirect('admin/' . $this->post_name . '_edit/' . $post_id); } View::RenderAdminTemplate('head_view', $data_head); View::RenderAdminTemplate('header_view'); View::RenderAdminTemplate('sidebar_view'); View::RenderAdmin('posts_cat/edit_view', $data, $error); View::RenderAdminTemplate('footer_view'); }
public function logout() { Session::remove('user'); }
<h1> Haber Düzenleme <small>Preview</small> </h1> <ol class="breadcrumb"> <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li> <li><a href="#">Forms</a></li> <li class="active">General Elements</li> </ol> </section> <!-- Main content --> <section class="content"> <div class="row"> <?php echo \Lib\Session::pull('message'); echo \Lib\Error::display($error); ?> <div id="warning_error" style="display: none" class="alert alert-danger"></div> <div id="warning_ok" style="display: none" class="alert alert-success"></div> <!-- left column --> <div class="col-md-12"> <div class="nav-tabs-custom"> <!-- Tabs within a box --> <ul class="nav nav-tabs pull-right"> <?php
private function finalize() { $user = new User(\Lib\Session::get('id')); $name = $user->getFirstName(); $surname = $user->getSurname(); $country = $user->getCountry(); $zipcode = $user->getZipCode(); $city = $user->getCity(); $street = $user->getStreet(); $house = $user->getHousNr(); $appartment = $user->getAppartmentNr(); $order_details = new Order_details(); $order_details->setAddress('Imie: ' . $user->getFirstName() . ' Nazwisko: ' . $user->getSurname() . ' Kraj: ' . $user->getCountry() . ' Kod-Pocztowy: ' . $user->getZipCode() . ' Miasto: ' . $user->getCity() . ' Ulica : ' . $user->getStreet() . ' Nr domu: ' . $user->getHousNr() . ' Nr mieszkania: ' . $user->getAppartmentNr()); $time = time(); $id = \Lib\Session::get('id'); $rand = rand(1, 100); $nr = $id . $time . $rand; $order_details->setOrderNr($nr); $order_details->setDisplaySeller(true); $order_details->setDisplayUser(true); $sm = $this->http->get('shipping_method'); if (empty($sm)) { Location::To(URL . 'cart/show'); } $order_details->setShippingMethodId($sm); $order_details->setDate(); $order_details->setStatus(1); $cart = \Lib\Session::get('cart'); if (!empty($cart)) { $db = Register::get('db'); $db->query('START TRANSACTION'); $id = $order_details->writeData(); foreach ($cart as $product) { $order = new Order($product['order_id']); $order->setActive(1); $order->setOrderDetailsId($id); $order->writeData(true); if (!$order->writeData(true)) { $db->query('ROLLBACK'); return false; } } if ($id) { $db->query('COMMIT'); } else { $db->query('ROLLBACK'); return false; } $mess = $this->http->get('message'); if (!empty($mess)) { $mesage = new Message(); $mesage->setUserId(\lib\Register::get('id')); $mesage->setReaded(false); $mesage->setSeller(false); $mesage->setMessage($order_details->getOrderNr() . ': ' . $this->http->get('message')); $mesage->setDate(); $mesage->setDisplayUser(true); $mesage->setDisplaySeller(true); $mesage->writeData(); } \Lib\Session::delete('cart'); $this->ActNumberOfProducts(); return true; } }
public static function getNumberOfProducts() { $p = \lib\Session::get('cart_num_of_products'); return $p; }
<?php require "config.php"; use Lib\Session; use Lib\Registry; use Lib\Router; use Lib\Controller; use Lib\Debugger; use Controller\Site\IndexController; Session::start(); $url = explode('?', $_SERVER['REQUEST_URI']); $url = $url[0]; //функуия автозагрузки function __autoload($classname) { $classFile = str_replace('\\', '/', $classname); if (file_exists(ROOT . $classFile . '.php')) { require ROOT . $classFile . '.php'; } else { throw new Exception("{$classFile} not found"); } } try { $dbh = new PDO($dsn, $user, $password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); Registry::set('dbh', $dbh); Router::resolve($url); $_controller = Router::$_controller; $_action = Router::$_action; $_controller = '\\Controller\\' . ucfirst($_controller) . "Controller"; $_action .= "Action";
/** * düzenleme alanı * * @param int $id * @return mixed */ public function edit($post_id) { $data['post'] = $this->_model->fetch_post($post_id); $data['languages'] = $languages; $data['categories'] = $this->_model->AllPostsCategories(); $data['pictures'] = $this->_model->AllPostsPictures(1); $data['_setting'] = $this->default_params(); $data_head['page_title'] = 'Sayfa Düzenleme'; $data['post_id'] = $post_id; // && \Lib\Tools::is_ajax() if ($this->request->getMethod() == 'POST') { $this->edit_post(); $this->upload($post_id); $ok = \Lib\Tools::message_ver('ok', 'Bilgileriniz başarı ile değiştirilmiştir'); \Lib\Session::set('message', $ok); \Lib\Url::redirect('admin/' . $this->post_name . '_edit/' . $post_id); } View::RenderAdminTemplate('head_view', $data_head); View::RenderAdminTemplate('header_view'); View::RenderAdminTemplate('sidebar_view'); View::RenderAdmin('posts/edit_view', $data, $error); View::RenderAdminTemplate('footer_view'); }
public static function getCacheStats() { $retVal = []; $trackedKeys = self::Get(CACHE_STATS_KEYS, true, true); if ($trackedKeys) { foreach ($trackedKeys as $key => $val) { // Throw away session keys if (!Session::isSessionKey($key)) { $hits = self::Get('CacheStats_' . $key . '_hit', true, true) ?: 0; $misses = self::Get('CacheStats_' . $key . '_miss', true, true) ?: 0; $retVal[$key] = (object) ['hits' => $hits, 'misses' => $misses, 'total' => $hits + $misses]; } } } return $retVal; }
public function admLogoutAction() { Session::delete('user'); Session::setFlash('You have logged out!'); header("Location: " . Router::getRoute('admin', 'adm_default')); }
private function logout() { \Lib\Session::deleteAll(); Location::To(URL . 'home'); }
/** * çıkış yap */ public function logout() { \Lib\Session::destroy('loggedin'); \Lib\Session::destroy('kullanici_bilgileri'); \Lib\Session::destroy('stncart'); \Lib\Session::destroy('teslimatZamani'); \Lib\Session::destroy('sepetStokSorunu'); \Lib\Url::redirect('uyelik'); }
public static function YeniSiparisBildirimi($data, $mailYazisi) { $kullanici_bilgileri = \Lib\Session::get('kullanici_bilgileri'); $ad_soyad = \Lib\Strings::strtoTrUcFirst($kullanici_bilgileri['adi']) . ' ' . \Lib\Strings::strtoTrUcFirst($kullanici_bilgileri['soyadi']); // echo '<pre>'; extract($data); $file = self::TableStyle() . '<body bgcolor="#f6f6f6"> <strong> ' . $mailYazisi . ' </strong>' . $data['sepet'] . ' <table class="body-wrap"> <tbody> <tr class="price2"> <td class="right"><b>Toplam:</b></td> <td class="right"><a class="toplamfiyat" href="' . $data['sepet_fiyat_toplami'] . '"></a> <span class="toplamfiyatspan">' . $data['sepet_fiyat_toplami'] . ' TL</span> </td> </tr> </tbody> </table> <strong>Bilgileriniz </strong> <table class="body-wrap" border="1" cellspacing="0" cellpadding="0"> <tbody> <tr> <th>Sipariş No:</th> <td>' . $siparis_no . '</td> </tr> <tr> <th>Siparişi Oluşturan:</th> <td>' . $ad_soyad . '</td> </tr> <tr> <th>Telefon Numarası</th> <td>' . $telefon . '</td> </tr> <tr> <th>Email Adresi</th> <td>' . $email . '</td> </tr> <tr> <th>Oluşturma Zamanı:</th> <td>' . $olusturma_zamani . '</td> </tr> <tr> <th>Sipariş Durumu:</th> <td>' . $siparis_durumu . '</td> </tr> <tr> <th>Sipariş Tutarı</th> <td>' . $siparis_tutari . ' TL</td> </tr> <tr> <th>Ödeme Türü</th> <td>' . $odeme_tipi . '</td> </tr> <tr> <th>Mağaza</th> <td>' . $magaza_adi . '</td> </tr> </tbody> </table> </div> <strong>Teslimat Bilgileri </strong> <table class="body-wrap" border="1" cellspacing="0" cellpadding="0"> <tbody> <tr> <th>Teslimat Saati:</th> <td>' . $teslimat_saati . '</td> </tr> <tr> <th>Teslimat Tarihi:</th> <td>' . $teslimat_tarihi . '</td> </tr> <tr> <th>İsim Soyisim:</th> <td>' . $ad_soyad . '</td> </tr> <tr> <th>Adres:</th> <td>' . $alici_adres . ' </td> </tr> <tr> <th>Şehir ,İlçe, Semt/Mahalle</th> <td>' . $alici_il . ' , ' . $alici_ilce . ' , ' . $alici_semt . '</td> </tr> </tbody> </table> </div> <strong>Fatura Bilgileri </strong> <table class="body-wrap" border="1" cellspacing="0" cellpadding="0"> <tbody> <tr> <th>İsim Soyisim:</th> <td>' . $ad_soyad . '</td> </tr> <tr> <th>Adres:</th> <td>' . $fatura_adres . ' </td> </tr> <tr> <th>Şehir ,İlçe, Semt/Mahalle</th> <td>' . $fatura_il . ' , ' . $fatura_ilce . ' , ' . $fatura_semt . '</td> </tr> </tbody> </table> </div></body></html>'; $file = self::replaceSpace($file); return $file; }