Example #1
0
 /**
  * Actual routing + sanitizing data
  *
  * @param       $class
  * @param array $params
  */
 public static function connect($namespace, $class, $params = array())
 {
     $defaults = array('indexPage' => 'index', 'loginPage' => false, 'loginRedirect' => false);
     static::$class = strtolower($class);
     $class = $namespace . '\\' . $class;
     $params += $defaults;
     extract($params);
     // Authenticated controllers
     if ($loginPage) {
         Auth::checkLogin($loginRedirect, $loginPage);
     }
     $method = $indexPage;
     $parameters = array();
     if (isset($_SERVER[URI_INFO])) {
         $url = explode('/', substr($_SERVER[URI_INFO], 1));
         array_shift($url);
         if ($url) {
             foreach ($url as $key => $element) {
                 if (!$key && !is_numeric($element)) {
                     $method = $element;
                 } else {
                     $parameters[] = $element;
                 }
             }
         }
     }
     // Check availability
     try {
         $methodInfo = new \ReflectionMethod($class, $method);
         // Methods that start with _ are not accesible from browser
         $name = $methodInfo->getName();
         if ($name[0] == '_') {
             $method = $indexPage;
         }
         $methodParams = $methodInfo->getParameters();
         // Force cast parameters by arguments default value
         if ($methodParams) {
             foreach ($methodParams as $parameterKey => $parameterValue) {
                 try {
                     $defaultValue = $parameterValue->getDefaultValue();
                     $type = gettype($defaultValue);
                     if ($defaultValue) {
                         unset($methodParams[$parameterKey]);
                     }
                     //							settype($parameters[$parameterKey], $type);
                 } catch (\Exception $e) {
                     continue;
                 }
             }
         }
         //				if(count($methodParams) != count($parameters)) {
         //					$parameters = array();
         //				}
     } catch (\Exception $e) {
         $method = $indexPage;
     }
     static::$method = $method;
     call_user_func_array($class . '::' . $method, $parameters);
     return;
 }
Example #2
0
 function signin()
 {
     $this->doNotRenderHeader = 1;
     Auth::checkLogin(false);
     if (isset($_POST['username']) && isset($_POST['password'])) {
         if (Auth::login($_POST['username'], $_POST['password'])) {
             header("Location:" . INSTALL_FOLDER . "/home");
         } else {
             echo "invalid password";
         }
     }
 }
Example #3
0
 public function home()
 {
     $this->doNotRenderHeader = 1;
     Auth::checkLogin(true);
     $model = new $this->model();
     /*  //if count score then if
             //count where answer is 0 if less goto test else if 0 goto result
           if($model->countrows()==QUESTION_LIMIT)
               {
                   header("Location:".INSTALL_FOLDER."/result");
               }
     
     
           if(isset($_POST["name"]))
               {
                   $model->generate_name($_POST["name"]);
                   //$model->generateAll();
                   header("Location:".INSTALL_FOLDER."/test");
               }
               */
     if ($model->scoreExists()) {
         if (!$model->zeroCount()) {
             header("Location:" . INSTALL_FOLDER . "/result");
             echo "r";
         } else {
             header("Location:" . INSTALL_FOLDER . "/test");
             echo "t";
         }
     }
     if (isset($_POST["name"]) && !empty($_POST["name"])) {
         setcookie("my_cookie", '3600', time() - 7200);
         $model->generate_name($_POST["name"]);
         $model->generateAll();
         header("Location:" . INSTALL_FOLDER . "/test");
     }
 }
Example #4
0
<?php

error_reporting(E_ALL);
require 'vendor/autoload.php';
$auth = new Auth();
if ($auth->checkLogin()) {
    $route = new Route();
    // Add a route and a method to map it to
    require 'routes.php';
    $route->submit();
}
Example #5
0
 public function __construct()
 {
     parent::__construct();
     Auth::checkLogin();
 }
Example #6
0
 public static function __init()
 {
     Auth::checkLogin();
 }
Example #7
0
<?php

require_once '../core_nufarm/libs.php';
$login = Auth::checkLogin();
echo "<pre>";
print_r(session_save_path());
echo "</pre>";
if (isset($_POST['_token'])) {
    if (Token::check($_POST['_token'])) {
        Auth::userLogin($_POST['nf_username'], $_POST['nf_password']);
    }
} else {
    Token::generate();
}
Token::all();
if ($login->check) {
    Auth::startSession();
    require_once 'select.php';
} else {
    require_once 'login.php';
}
Example #8
0
 function test()
 {
     $this->doNotRenderHeader = 1;
     Auth::checkLogin(true);
     $model = new $this->model();
     if ($model->scoreExists()) {
         if (isset($_POST['answer'], $_POST['qid'])) {
             $model->putresult($_POST['qid'], $_POST['answer']);
         }
         $zero = $model->zeroCount();
         if (!isset($_POST['next']) && empty($_POST['next']) || $_POST['next'] > QUESTION_LIMIT) {
             $_POST['next'] = 1;
             $_POST['next'] = QUESTION_LIMIT - $zero + 1;
             /////////////////temp only if not requred to go back
         }
         /////////////////////////////////////////////////////////////////////////////////////////
         $_POST['next'] = QUESTION_LIMIT - $zero + 1;
         /////////////////temp only if not requred to go back
         if ($zero != 0) {
             if (isset($_COOKIE["my_cookie"])) {
                 if ($_COOKIE["my_cookie"] == 0) {
                     //fetch quid with zero
                     $qid = $model->qidWithZero();
                     for ($j = 0; $j < $zero; $j++) {
                         $model->putresult($qid[$j]['q_id'], -1);
                     }
                     unset($_COOKIE['my_cookie']);
                     setcookie('my_cookie', null, -1, '/');
                     setcookie('my_cookie', null, -1, '/');
                     header('Location: result');
                 }
             }
             $this->_question = $model->get_next($_POST['next'] - 1);
             $_SESSION["qid"] = $this->_question['id'];
             $this->set("question_done", QUESTION_LIMIT - $zero + 1);
             $this->set("question_no", $_POST['next']);
             $this->set("next", $_POST['next'] + 1);
             $this->set("question_total", QUESTION_LIMIT);
             $this->set("question", $this->_question['question_name']);
             $this->set("answer1", $this->_question['answer1']);
             $this->set("answer2", $this->_question['answer2']);
             $this->set("answer3", $this->_question['answer3']);
             $this->set("answer4", $this->_question['answer4']);
             //$this->set("value", $this->_question['answer']);////////////////////////////////////////////////////
             $this->set("qid", $this->_question['id']);
             if ($this->_question['code']) {
                 //$this->set("code", '<pre class="prettyprint linenum"  style="text-align:left;"><code>'.$this->_question['code'].'</code></pre>');
             }
             if ($this->_question['img']) {
                 $this->set("image", '<img src="photo.php?id=' . $this->_question['img'] . '"class="md-card-image">');
             }
         } else {
             echo "yo";
             header("Location:" . INSTALL_FOLDER . "/result");
         }
     } else {
         echo "yo";
         header("Location:" . INSTALL_FOLDER . "/home");
     }
     /*
              if(isset($_COOKIE["my_cookie"]))
                  {
                         if($_COOKIE["my_cookie"]==0)
                         {
                             $i=QUESTION_LIMIT-$model->countrows();
                             for($j=0;$j<$i;$j++)
                             {
                                 echo $model->putresult(-$j,-$j);
                             }
                                 unset($_COOKIE['my_cookie']);
                                 setcookie('my_cookie', null, -1, '/');
                                 setcookie('my_cookie', null, -1, '/');
                                 header('Location: result');
                         }
                  } else{
                   $this->_valid="0";
                  }
              if(isset($_POST['answer'],$_POST['qid']))
                 {
                    if($model->putresult($_POST['answer'],$_POST['qid']))
                    { $this->_valid="0"; }
                 }
             if($model->countrows()<QUESTION_LIMIT)
              {
                 if($this->_valid=="0"){
                  $this->_question=$model->generate_one();
                  $_SESSION["qid"]=$this->_question['id'];
                     $this->_valid="1";
                 }
                 else{
                   $this->_question=$model->generate_withid();
                 }
                  $this->set("question_no", $model->countrows()+1);
                  $this->set("question_total", QUESTION_LIMIT);
                  $this->set("question", $this->_question['question_name']);
                  $this->set("answer1", $this->_question['answer1']);
                  $this->set("answer2", $this->_question['answer2']);
                  $this->set("answer3", $this->_question['answer3']);
                  $this->set("answer4", $this->_question['answer4']);
                  $this->set("qid", $this->_question['id']);
                 
                  if($this->_question['code']){
                     $this->set("code", $this->_question['code']);
                      echo $this->_question['code'];
                      
                      <pre class='prettyprint linenums' style='text-align:left;'><code
     >${{code}}
     </code></pre>
                      
                  }
                  if($this->_question['img']){
                     $this->set("image", '<img src="photo.php?id='.$this->_question['img'].'"class="md-card-image">');
                  }
                 
              }else
             { header('Location: result');}
          }
         
         public function accept(){
             //update input answer api
         }
     */
 }
Example #9
0
$displayForm = true;
// FORM WAS SUBMITTED
if (isset($_POST['submitted'])) {
    // validate user input server-side (use of exceptions in order to be able to add other error checks)
    try {
        // ensure that user filled out all compulsory fields
        if (empty($_POST[$FIELD_EMAIL]) || empty($_POST[$FIELD_PWD])) {
            throw new Exception(I18n::t('login.err.notallfields'));
        }
        // prevent HTML and SQL injection
        $email = htmlspecialchars($_POST[$FIELD_EMAIL]);
        $email = DB::escapeString($email);
        $email = strtolower($email);
        $pw = $_POST[$FIELD_PWD];
        // check if login data is valid and correct
        if (!Auth::checkLogin($email, $pw)) {
            throw new Exception(I18n::t('login.err.notcorrect'));
        }
    } catch (Exception $e) {
        $errorMessage = $e->getMessage();
    }
    // validation is successful
    if (!isset($errorMessage)) {
        $displayForm = false;
        // perform the actual login
        $user = User::getUserByEmail($email);
        if (!$user || is_null($user)) {
            $message = I18n::t('login.err.general');
        } else {
            // save user object to session
            $_SESSION['user'] = $user;
Example #10
0
	<?php 
//include all the files nessary
include_once 'core/init.php';
include_once 'core/sanatize.php';
//intilize the object
$Auth = new Auth();
if ($Auth->checkLogin() == TRUE) {
    header("Location: member.php");
} else {
    $email = sanatize($_POST['email']);
    $password = sanatize($_POST['password']);
    if ($_POST['submit']) {
        if ($email) {
            if ($password) {
                if ($Auth->login($email, $password) == TRUE) {
                    echo "Success";
                } else {
                    echo "ERROR: Invalid Email or Password";
                }
            } else {
                echo "Please Enter a Password";
            }
        } else {
            echo "Please Enter an Email";
        }
    }
}
Example #11
0
<?php

require $_SERVER['DOCUMENT_ROOT'] . '/../ajax.inc.php';
$act = $_REQUEST['act'];
$code = 0;
$msg = '操作成功';
$data = array();
switch ($act) {
    case 'login':
        //验证登录
        $username = $_REQUEST['username'];
        $password = $_REQUEST['password'];
        $result = Auth::checkLogin($username, $password);
        $code = $result['code'];
        $msg = $result['msg'];
        break;
    case 'logout':
        session_destroy();
        break;
    default:
        $code = 1;
        $msg = '没有这个操作';
}