Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions codeigniter/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RewriteEngine on
RewriteCond $1 !^(index\.php|css|js|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
4 changes: 2 additions & 2 deletions codeigniter/application/config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
| $autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/

$autoload['libraries'] = array();
$autoload['libraries'] = array('database','session','form_validation');


/*
Expand All @@ -64,7 +64,7 @@
| $autoload['helper'] = array('url', 'file');
*/

$autoload['helper'] = array();
$autoload['helper'] = array('url','form');


/*
Expand Down
12 changes: 6 additions & 6 deletions codeigniter/application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
| path to your installation.
|
*/
$config['base_url'] = '';
$config['base_url'] = 'http://satishathome.net/';

/*
|--------------------------------------------------------------------------
Expand All @@ -26,7 +26,7 @@
| variable so that it is blank.
|
*/
$config['index_page'] = 'index.php';
$config['index_page'] = '';

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -69,7 +69,7 @@
| than english.
|
*/
$config['language'] = 'japanese';
$config['language'] = 'english';

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -224,7 +224,7 @@
| MUST set an encryption key. See the user guide for info.
|
*/
$config['encryption_key'] = '';
$config['encryption_key'] = 'REALLY_LONG_NUMBER';

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -279,7 +279,7 @@
| COOKIE data is encountered
|
*/
$config['global_xss_filtering'] = FALSE;
$config['global_xss_filtering'] = TRUE;

/*
|--------------------------------------------------------------------------
Expand All @@ -293,7 +293,7 @@
| 'csrf_cookie_name' = The cookie name
| 'csrf_expire' = The number in seconds the token should expire.
*/
$config['csrf_protection'] = FALSE;
$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
Expand Down
4 changes: 4 additions & 0 deletions codeigniter/application/config/constants.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

define('DEFAULT_STATUS',"express yourself");
define('LENGTH',2);
define('LOGIN_FAILED',"Username or password is incorrect.");
define('NO_MESSAGE'," ");
/*
|--------------------------------------------------------------------------
| File and Directory Modes
Expand Down
2 changes: 1 addition & 1 deletion codeigniter/application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
|
*/

$route['default_controller'] = "welcome";
$route['default_controller'] = "Login";
$route['404_override'] = '';


Expand Down
48 changes: 48 additions & 0 deletions codeigniter/application/controllers/login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
public function _remap($method, $args) {
if (method_exists($this, $method)){
// Call before action
$this->before();
return call_user_func_array(array($this, $method), $args);
}
show_404(); //if the user enters any other function which is not in this class
}

private function before() {
if($this->session->userdata('logged_in')){
redirect('room','refresh');
}
}

public function index(){
$data['message'] = NO_MESSAGE;
$this->load->view('loginView',$data);
}

private function verifyLogin(){
$this->form_validation->set_rules('username', 'Username', 'trim|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|xss_clean');

if ($this->form_validation->run() == FALSE) { //if form validation fails, redirect to login page with message
$data['message'] = LOGIN_FAILED;
return $this->load->view('loginView',$data);
} else { //if form validation passes, get data and check database
$email = htmlspecialchars($_POST['email']);
$password = sha1(htmlspecialchars($_POST['password']));
$this->load->model('users');
$singleRowResult=$this->users->authenticate($email,$password); //the authenticate function is in model:users
}

if ($singleRowResult) { //if user exists create session and redirect to room
$sess_array = array();
$sess_array = array('userid' => $singleRowResult['userid'],'username' => $singleRowResult['username']);
$this->session->set_userdata('logged_in', $sess_array);
redirect('room','refresh');
} else { // if user does not exist, redirect to login page with message
$data['message'] = LOGIN_FAILED;
$this->load->view('loginView',$data);
}
}
}
48 changes: 48 additions & 0 deletions codeigniter/application/controllers/register.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Register extends CI_Controller {
public function _remap($method, $args) {
if (method_exists($this, $method)){
// Call before action
$this->before();
return call_user_func_array(array($this, $method), $args);
}
show_404();
}

private function before() {
if($this->session->userdata('logged_in')){
redirect('room','refresh');
}
}

public function index(){
$this->load->view('registerView');
}

private function verifyRegister(){
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('email', 'Email', 'trim|xss_clean|required|valid_email|is_unique[users.email]');
$this->form_validation->set_rules('password', 'Password', 'trim|xss_clean|required');
$this->form_validation->set_rules('confirmPassword', 'Confirm Password', 'trim|xss_clean|matches[password]|required');

if ($this->form_validation->run() == FALSE){ // if form validation fails,load the registrationForm
$this->load->view('registerView');
} else { //if form validation passes,authenticate,set the session and redirect to room
$username = htmlspecialchars($_POST['username']);
$password =sha1(htmlspecialchars($_POST['password']));
$email = $_POST['email'];
$this->load->model('users');
$isRegistered = $this->users->register($username,$email,$password);
if ($isRegistered) {
$singleRowResult=$this->users->authenticate($email,$password);
$sess_array = array();
$sess_array = array('userid' => $singleRowResult['userid'],'username' => $singleRowResult['username']);
$this->session->set_userdata('logged_in', $sess_array);
redirect('room','refresh');
} else {
echo("A technical error has occurred!");
}
}
}
}
98 changes: 98 additions & 0 deletions codeigniter/application/controllers/room.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Room extends CI_Controller {
public function _remap($method, $args) {
if (method_exists($this, $method)){
// Call before action
$this->before();
return call_user_func_array(array($this, $method), $args);
}
show_404(); //if the user enters any other function which is not in this class
}

private function before() {
if($this->session->userdata('logged_in')){
return true;
}
else{
redirect('login','refresh');
}
}

public function index(){
$posts = $this->showInitialPosts();
if($posts){ //if result exists send the result to room for display
$data['jsonObject'] = $posts;
$this->load->view('roomView',$data);
}
else{
$data['message'] = "NO_POSTS_YET";
$this->load->view('roomView',$data);
}
}

public function showInitialPosts(){
$this->load->model('posts');
$postsFromDB = $this->posts->getInitialPosts();

if ($postsFromDB) {
return json_encode($postsFromDB);
} else {
return false;
}
}

public function showPosts($parameter){
$postid = (int) $parameter; //type casting the parameter to integer will cause page to be 0 is it contains alphabets

$this->load->model('posts');
$postsFromDB = $this->posts->getPosts($postid);

if ($postsFromDB) {
return json_encode($postsFromDB);
} else {
return false;
}
}

public function ajaxDisplay(){
$postid = $_POST['postid'];
$posts = $this->showPosts($postid);
if($posts){
print_r($posts); //returns the JSON Object Array to ajax responseText
}
else{
echo("[{\"message\":\"OUT_OF_INDEX\"}]");
}
}

public function ajaxPost(){
$session_data = $this->session->userdata('logged_in');
if(isset($_POST['status'])){
$userid = $session_data['userid'];
$username = $session_data['username'];
$posts = $_POST['status'];
$time_of_post = date("Y-m-d H:i:s");

$this->load->model('posts');
$insertPost = $this->posts->post($userid,$username,$posts,$time_of_post);
} else {
echo("VARIABLES_NOT_SET_IN_AJAXPOST");
}

if($insertPost){
echo($time_of_post);
}
else{
echo("POST_NOT_INSERTED");
}
}

public function logout(){
$this->session->unset_userdata('logged_in');
$this->session->sess_destroy();
redirect('login', 'refresh');
}
}

?>
100 changes: 100 additions & 0 deletions codeigniter/application/controllers/room_1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

session_start();

class Room extends CI_Controller {
public function _remap($method, $args) {
if (method_exists($this, $method)){
// Call before action
$this->before();
return call_user_func_array(array($this, $method), $args);
}
show_404(); //if the user enters any other function which is not in this class
}

private function before() {
if($this->session->userdata('logged_in')){
return true;
}
else{
redirect('login','refresh');
}
}


public function index(){
$posts = $this->showPosts("1");
if($posts){ //if result exists send the result to room for display
$this->load->view('roomView',$posts);
}
else{
$data['message'] = "NO_POSTS_YET";
$this->load->view('roomView',$data);
}
}

public function showPosts($parameter){
$page = (int) $parameter; //type casting the parameter to integer will cause page to be 0 is it contains alphabets
$session_data = $this->session->userdata('logged_in');

$this->load->model('posts');
$postsFormDB = $this->posts->getPosts($page);

if($postsFormDB){
if(!isset($postsFormDB['message'])){
$postsFormDB['message'] = "NOT_SET";
}
$n = count($postsFormDB);
array_unshift($postsFormDB,$session_data['username'],$n + 2,$page);
//setting the data to be sent to the view
for($i = 0; $i < $n + 2; $i++){
$di = 'di'.$i;
$data[$di] = $postsFormDB[$i];
}
$data['message'] = $postsFormDB['message'];
return $data;
}
else{
return false;
}
}

public function ajax($param){
$posts = $this->showPosts($param);
if($posts){
print_r($posts); //returns the array to ajax responseText
}
else{
echo("NO!");
}
}

public function ajaxPost(){
if(isset($_POST['username'])&&isset($_POST['status'])){
$username = $_POST['username'];
$posts = $_POST['status'];
$date = date("Y-m-d H:i:s");

$this->load->model('posts');
$insertPost = $this->posts->post($username,$posts,$date);

if($insertPost){
echo($date);
}
else{
echo("false");
}
}
else{
echo("VARIABLES_NOT_SET");
}
}

public function logout(){
$this->session->unset_userdata('logged_in');
session_destroy();
redirect('login', 'refresh');
}
}

?>
Loading