Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 public function indexAction()
 {
     $_request = new Request();
     $title = MetaHelper::setPageTitle('Главная(admin)');
     $login_form = new LoginForm($_request);
     $errors = array();
     if ($_request->isPost()) {
         if ($login_form->validate()) {
             $user = new UserModel();
             $login = $_request->post('login');
             $hash_password = new Password($_request->post('password'));
             $res = $user->getUser($login, $hash_password);
             if (!$res) {
                 $msg = "No such user";
             } else {
                 Session::set('user', $res);
                 $msg = "You have successfully logged in!";
             }
             Session::setFlash($msg);
         } else {
             $errors = $login_form->showErrors();
         }
     }
     $model = new WeatherModel();
     $data = $model->getSourcelist();
     $args = ['errors' => $errors, 'data' => $data, 'page_title' => $title];
     return $this->render('index.phtml', $args, 'admin');
 }
Esempio n. 4
0
 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');
 }
Esempio n. 5
0
 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');
     }
 }
Esempio n. 6
0
 /**
  * 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');
 }
Esempio n. 7
0
 private static function ActNumberOfProducts()
 {
     $p = 0;
     $cart = \Lib\Session::get('cart');
     if (!empty($cart)) {
         foreach ($cart as $key => $product) {
             $order = new Order($product['order_id']);
             if (!$order->getQuantity()) {
                 continue;
             }
             $p += $cart_data[$key]['product_quantity'] = $order->getQuantity();
         }
     }
     \lib\Session::set('cart_num_of_products', $p);
 }
Esempio n. 8
0
 public function purchuase()
 {
     if (LoginVal::isLogged()) {
         $this->confirm();
     } else {
         \Lib\Session::set('intended', URL . 'cart/purchuase');
         Location::To(URL . 'login');
     }
 }
Esempio n. 9
0
 /**
  * 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');
 }
Esempio n. 10
0
 /**
  * şifremi unuttum
  *
  * @return mixed
  */
 public function SifremiUnuttum()
 {
     if (\Lib\Session::get('loggedin')) {
         \Lib\Url::redirect('hesapim');
     }
     // if (isset ( $_POST ['submit'] )) {
     if (Request::isPost()) {
         $email = $this->request->get('email');
         if ($email == '') {
             $error[] = 'email alanı boş bırakılamaz';
         }
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $error[] = 'lütfen geçerli bir email adresi yazınız ';
         }
         if (!$error) {
             $total = $this->_model->getEmail_Varmi($email);
             if ($total > 0) {
                 $user = $this->_model->getKullaniciBilgileri($email);
                 // print_r($user);die;
                 $email_adresi = $user['email'];
                 $ad_soyad = \Lib\Strings::adSoyadParcala($bilgiler['unvan']);
                 $adi_soyadi = $ad_soyad['adi'] . ' ' . $ad_soyad['soyadi'];
                 $user_id = $user['id'];
                 $subject = 'İdeal.com.tr Şifre Yenileme';
                 $tokenkey = \Lib\Tools::token_key_olustur();
                 $toplam_token_adet = $this->_model->getBoyle_bir_token_varmi($tokenkey);
                 // aynı isimde token key olabilir onu engellemek gerek
                 if ($toplam_token_adet > 0) {
                     $tokenkey = $tokenkey . 'st_n_ck_ey';
                 }
                 $postdata = array('token_key' => $tokenkey);
                 $where = array('id' => $user_id);
                 $this->_model->update_tokenKey_user($postdata, $where);
                 $message = '<a href="' . DIR . 'uyelik?action=uye_sifremiunuttum_degisiklik&token=' . $tokenkey . '">Şifre değiştirmek için tıklyayınız</a>';
                 $mail = new \Helpers\Mailler_Helper();
                 $sonuc = $mail->sendmail("*****@*****.**", $email_adresi, $adi_soyadi, $subject, $message);
                 if (!$sonuc) {
                     $hata = \Lib\Tools::message_ver('hata', $sonuc);
                     \Lib\Session::set('message', $hata);
                     // \Lib\Url::redirect('uyelik?action=sifremi_unuttum');
                 } else {
                     $basarili = \Lib\Tools::message_ver('ok', 'Şifre değiştirme linki mail adresinize gönderilmiştir');
                     \Lib\Session::set('message', $basarili);
                     // \Lib\Url::redirect('uyelik?action=uye_sifremiunuttum_degisiklik');
                 }
             } else {
                 $err = 'Böyle bir e-mail adresi bulunamadi';
                 $hata = \Lib\Tools::message_ver('hata', $err);
                 \Lib\Session::set('message', $hata);
                 // \Lib\Url::redirect('uyelik?action=sifremi_unuttum');
             }
         }
     }
     return $error;
 }