-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
159 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
* Controller.php | ||
*/ | ||
|
||
class Controller { | ||
protected $model; | ||
protected $view; | ||
|
||
public function __construct($model, $view) { | ||
$this->model = $model; | ||
$this->view = $view; | ||
} | ||
} | ||
|
||
class Auth extends Controller { | ||
public $user; | ||
function __construct($model, $view) { | ||
parent::__construct($model, $view); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/* | ||
* Models.php | ||
* Contains the definition of super models and other models inherit from that | ||
*/ | ||
|
||
namespace Model; | ||
|
||
class User { | ||
private $userid; | ||
private $auth; | ||
private $level; | ||
private $question; | ||
public function __construct($userid) { | ||
$this->userid = $userid; | ||
$this->auth = false; | ||
//fetch initially the level that's stored in DB | ||
$this->level = getDBLevel(); | ||
$this->question = getDBQuestion(); | ||
} | ||
public function get($key) { | ||
switch($key) { | ||
case 'id': return $this->userid; | ||
case 'level': return $this->level; | ||
case 'question': return $this->question; | ||
default: return null; | ||
} | ||
} | ||
public function grant() { | ||
$this->auth = true; | ||
} | ||
private function getDBLevel() { | ||
$userAccess = mysql_query("SELECT `to` FROM `user_level` WHERE `userid`='{$this->userid}' ORDER BY `id` DESC LIMIT 1") or die(mysql_error()); | ||
$userAccessArray = mysql_fetch_array($userAccess); | ||
$userLevel = $userAccessArray['to']; | ||
if(empty($userLevel)): | ||
//then try to find the starting level from the database | ||
$startNodeQuery = mysql_query("SELECT `value` FROM `config` WHERE `key`='start'") or die(mysql_error()); | ||
$startNodeArray = mysql_fetch_assoc($startNodeQuery); | ||
if(empty($startNodeArray['value'])) | ||
return 1; | ||
else | ||
return $startNodeArray['value']; | ||
endif; | ||
return $userLevel; | ||
} | ||
private function getDBQuestion() { | ||
$questionQuery = mysql_query("SELECT `url`,`question`,`comments`,`header` FROM `questions` WHERE `level`='{$this->level}' LIMIT 1") or die(mysql_error()); | ||
$questionArray = mysql_fetch_assoc($questionQuery); | ||
$question = $questionArray['question'] . "\n" . $questionArray['comments']; | ||
return array( | ||
"question"=>$question, | ||
"header"=>$questionArray['header'], | ||
"comments"=>stripslashes_deep($questionArray['comments']), | ||
"url"=>$questionArray['url'] | ||
); | ||
} | ||
} | ||
|
||
class Page { | ||
public $pageid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
/* | ||
* Author: Boopathi Rajaa <me@boopathi.in> | ||
* Auth.lib.php | ||
* A class that provides to implement custom auth logic | ||
*/ | ||
|
||
class Auth { | ||
function __construct(){ | ||
$this->auth = false; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
* Authentication part. | ||
* A function auth - returns true if authentication was successfull | ||
* if not, then function error will be called. | ||
*/ | ||
|
||
require_once('model.lib.php'); | ||
namespace Auth { | ||
function authenticate() { | ||
|
||
} | ||
}; | ||
|
||
class Authenticate { | ||
public var $userid; | ||
function __construct() { | ||
$this->userid = null; | ||
//call the authenticate method that returns the authenticate variable; | ||
$this->authenticate = $this->authenticate(); //true or false only | ||
if($this->authenticate == false) | ||
$this->error(); | ||
} | ||
function authenticate() { | ||
//Write your authenticate method here | ||
//Return true if authenticated. Note: It should be strictly true | ||
|
||
//For PragyanCMS authentication | ||
return this->pragyanAuth(); | ||
} | ||
public function error() { | ||
//This function ll be the callback when authenticate returns false. | ||
//You may exit the program here. Not exiting is no harm either. | ||
echo "Authentication Failure."; | ||
return false; | ||
} | ||
function pragyanAuth() { | ||
ini_set("session.name", "PHPSESSID"); | ||
ini_set("session.save_path", "/home/boopathi/tmp/sessions"); | ||
|
||
session_start(); | ||
|
||
if(!isset($_SESSION['userId'])) { | ||
echo "Session not set "; | ||
return false; | ||
} | ||
if($_SESSION['userId'] == 0 ) { | ||
echo "User Id is 0"; | ||
return false; | ||
} | ||
//set the userid if everything is fine. | ||
$this->userid = $_SESSION['userId']; | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters