From cf2b33c534158429a026227e582e0e493bd8316c Mon Sep 17 00:00:00 2001 From: Satish Jaiswal Date: Fri, 11 Apr 2014 20:37:51 +0900 Subject: [PATCH 01/12] initial commit --- codeigniter/application/config/autoload.php | 4 +- codeigniter/application/config/config.php | 8 +- codeigniter/application/config/routes.php | 2 +- codeigniter/application/controllers/login.php | 9 + codeigniter/application/controllers/main.php | 18 ++ codeigniter/application/controllers/room.php | 26 ++ .../application/controllers/verifyLogin.php | 47 ++++ .../application/models/DBFunctions.php | 28 +++ codeigniter/application/views/loginForm.php | 224 ++++++++++++++++++ codeigniter/application/views/room.php | 10 + codeigniter/application/views/roomView.php | 1 + 11 files changed, 370 insertions(+), 7 deletions(-) create mode 100644 codeigniter/application/controllers/login.php create mode 100644 codeigniter/application/controllers/main.php create mode 100644 codeigniter/application/controllers/room.php create mode 100644 codeigniter/application/controllers/verifyLogin.php create mode 100644 codeigniter/application/models/DBFunctions.php create mode 100644 codeigniter/application/views/loginForm.php create mode 100644 codeigniter/application/views/room.php create mode 100644 codeigniter/application/views/roomView.php diff --git a/codeigniter/application/config/autoload.php b/codeigniter/application/config/autoload.php index 53129c9..5c9deaf 100644 --- a/codeigniter/application/config/autoload.php +++ b/codeigniter/application/config/autoload.php @@ -52,7 +52,7 @@ | $autoload['libraries'] = array('database', 'session', 'xmlrpc'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('database','session'); /* @@ -64,7 +64,7 @@ | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array(); +$autoload['helper'] = array('url'); /* diff --git a/codeigniter/application/config/config.php b/codeigniter/application/config/config.php index f7f125f..11b2876 100644 --- a/codeigniter/application/config/config.php +++ b/codeigniter/application/config/config.php @@ -69,7 +69,7 @@ | than english. | */ -$config['language'] = 'japanese'; +$config['language'] = 'english'; /* |-------------------------------------------------------------------------- @@ -224,7 +224,7 @@ | MUST set an encryption key. See the user guide for info. | */ -$config['encryption_key'] = ''; +$config['encryption_key'] = 'REALLY_LONG_NUMBER'; /* |-------------------------------------------------------------------------- @@ -279,7 +279,7 @@ | COOKIE data is encountered | */ -$config['global_xss_filtering'] = FALSE; +$config['global_xss_filtering'] = TRUE; /* |-------------------------------------------------------------------------- @@ -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; diff --git a/codeigniter/application/config/routes.php b/codeigniter/application/config/routes.php index 5f9a583..63d8acd 100644 --- a/codeigniter/application/config/routes.php +++ b/codeigniter/application/config/routes.php @@ -38,7 +38,7 @@ | */ -$route['default_controller'] = "welcome"; +$route['default_controller'] = "Main"; $route['404_override'] = ''; diff --git a/codeigniter/application/controllers/login.php b/codeigniter/application/controllers/login.php new file mode 100644 index 0000000..d82eb56 --- /dev/null +++ b/codeigniter/application/controllers/login.php @@ -0,0 +1,9 @@ +load->view('loginForm'); + } +} diff --git a/codeigniter/application/controllers/main.php b/codeigniter/application/controllers/main.php new file mode 100644 index 0000000..1b637b2 --- /dev/null +++ b/codeigniter/application/controllers/main.php @@ -0,0 +1,18 @@ +session->userdata('logged_in')){ + $session_data = $this->session->userdata('logged_in'); + $data['username'] = $session_data['username']; + $this->load->view('roomView', $data); + } + else{ + //If no session, redirect to login page + redirect('login', 'refresh'); + } + } +} diff --git a/codeigniter/application/controllers/room.php b/codeigniter/application/controllers/room.php new file mode 100644 index 0000000..e05ae6b --- /dev/null +++ b/codeigniter/application/controllers/room.php @@ -0,0 +1,26 @@ +session->userdata('logged_in')){ + $session_data = $this->session->userdata('logged_in'); + $data['username'] = $session_data['username']; + $this->load->view('roomView', $data); + } + else{ + //If no session, redirect to login page + redirect('login', 'refresh'); + } + } + + public function logout(){ + $this->session->unset_userdata('logged_in'); + session_destroy(); + redirect('login', 'refresh'); + } +} + +?> diff --git a/codeigniter/application/controllers/verifyLogin.php b/codeigniter/application/controllers/verifyLogin.php new file mode 100644 index 0000000..9efa117 --- /dev/null +++ b/codeigniter/application/controllers/verifyLogin.php @@ -0,0 +1,47 @@ +load->helper('form'); + + $this->load->library('form_validation','url'); + + $this->form_validation->set_rules('username', 'Username', 'trim|xss_clean'); + $this->form_validation->set_rules('password', 'Password', 'trim|xss_clean|callback_check_database'); + + if ($this->form_validation->run() == FALSE) + { + $this->load->view('loginForm'); //if validation fails load the loginForm + } + else + { //if validation passes go to private area + redirect('room','refresh'); + } + } + + public function check_database($password){ + $username=htmlspecialchars($_POST['username']); + + $this->load->model('DBFunctions'); + + $result=$this->DBFunctions->authenticate($username,$password); + + if($result){ + $sess_array = array(); + + foreach($result as $row){ + $sess_array = array('userID' => $row->userID,'username' => $row->username); + $this->session->set_userdata('logged_in', $sess_array); + } + return true; + } + else{ + $this->form_validation->set_message('check_database', 'Invalid username or password!!'); + return false; + } + } + +} +?> \ No newline at end of file diff --git a/codeigniter/application/models/DBFunctions.php b/codeigniter/application/models/DBFunctions.php new file mode 100644 index 0000000..2b2bf76 --- /dev/null +++ b/codeigniter/application/models/DBFunctions.php @@ -0,0 +1,28 @@ + db -> select('userID, username, password'); + $this -> db -> from('authenticate'); + $this -> db -> where('username', $username); + $this -> db -> where('password', $password); + $this -> db -> limit(1); + + $query = $this -> db -> get(); + + if($query -> num_rows() == 1){ + return $query->result(); + } + else{ + return false; + } + } + +} +?> \ No newline at end of file diff --git a/codeigniter/application/views/loginForm.php b/codeigniter/application/views/loginForm.php new file mode 100644 index 0000000..33c1115 --- /dev/null +++ b/codeigniter/application/views/loginForm.php @@ -0,0 +1,224 @@ + + + + + Welcome to Twitter + + + + + + + +
Mini Twitter
+ +
+load->helper('form'); + +//echo any type of errors +echo validation_errors(); +?> +
+ +
+ 'loginForm')); + +//set the label for the usename +echo form_label('Username', 'usernameID', array( 'id' => 'labelUserID')); + +//text input type for usename +echo form_input(array('name' => 'username','id' => 'usernameID')); + +//set the label for the password +echo form_label('Password', 'passwordID', array( 'id' => 'labelPassID')); + +//text input type for usename +echo form_password(array('name' => 'password','id' => 'passwordID')); + +//close the form +echo form_close(); +?> + + + +
+
+
+ + + \ No newline at end of file diff --git a/codeigniter/application/views/room.php b/codeigniter/application/views/room.php new file mode 100644 index 0000000..6ecbf91 --- /dev/null +++ b/codeigniter/application/views/room.php @@ -0,0 +1,10 @@ + + + + +This is room + + + + + \ No newline at end of file diff --git a/codeigniter/application/views/roomView.php b/codeigniter/application/views/roomView.php new file mode 100644 index 0000000..a2d562a --- /dev/null +++ b/codeigniter/application/views/roomView.php @@ -0,0 +1 @@ +Logout \ No newline at end of file From bf6c6e0118ded8c753366a6213ee5bc03b55f991 Mon Sep 17 00:00:00 2001 From: Satish Jaiswal Date: Sun, 20 Apr 2014 18:23:01 +0900 Subject: [PATCH 02/12] secondCommit --- codeigniter/application/config/routes.php | 2 +- codeigniter/application/controllers/login.php | 54 +++- .../application/controllers/register.php | 49 ++++ .../application/controllers/verifyLogin.php | 47 --- .../main.php => libraries/Myclass.php} | 8 +- .../application/models/DBFunctions.php | 21 +- .../views/{loginForm.php => loginView.php} | 22 +- .../application/views/registerView.php | 270 ++++++++++++++++++ codeigniter/application/views/roomView.php | 3 +- 9 files changed, 408 insertions(+), 68 deletions(-) create mode 100644 codeigniter/application/controllers/register.php delete mode 100644 codeigniter/application/controllers/verifyLogin.php rename codeigniter/application/{controllers/main.php => libraries/Myclass.php} (82%) rename codeigniter/application/views/{loginForm.php => loginView.php} (88%) create mode 100644 codeigniter/application/views/registerView.php diff --git a/codeigniter/application/config/routes.php b/codeigniter/application/config/routes.php index 63d8acd..da90aa0 100644 --- a/codeigniter/application/config/routes.php +++ b/codeigniter/application/config/routes.php @@ -38,7 +38,7 @@ | */ -$route['default_controller'] = "Main"; +$route['default_controller'] = "Login"; $route['404_override'] = ''; diff --git a/codeigniter/application/controllers/login.php b/codeigniter/application/controllers/login.php index d82eb56..2adf08b 100644 --- a/codeigniter/application/controllers/login.php +++ b/codeigniter/application/controllers/login.php @@ -2,8 +2,56 @@ class Login extends CI_Controller { - public function index() - { - $this->load->view('loginForm'); + public function index(){ + if($this->session->userdata('logged_in')){ + $session_data = $this->session->userdata('logged_in'); + $data['username'] = $session_data['username']; + $this->load->view('roomView', $data); + } + else{ + //If no session, redirect to login page + $this->load->view('loginView'); + } + } + + public function verifyLogin(){ + $this->load->helper('form'); + + $this->load->library('form_validation','url'); + + $this->form_validation->set_rules('username', 'Username', 'trim|xss_clean'); + $this->form_validation->set_rules('password', 'Password', 'trim|xss_clean|callback_check_database'); + + if ($this->form_validation->run() == FALSE) + { + $this->load->view('loginView'); //if validation fails load the loginForm + } + else + { //if validation passes go to private area + redirect('room','refresh'); + } + } + + public function check_database($raw_password){ + $email = htmlspecialchars($_POST['email']); + $password = sha1(htmlspecialchars($raw_password)); + + $this->load->model('DBFunctions'); + + $result=$this->DBFunctions->authenticate($email,$password); //the authenticate function is in model:DBFunctions + + if($result){ + $sess_array = array(); + + foreach($result as $row){ + $sess_array = array('userID' => $row->userID,'username' => $row->username); + $this->session->set_userdata('logged_in', $sess_array); + } + return true; + } + else{ + $this->form_validation->set_message('check_database', 'Invalid username or password!!'); + return false; + } } } diff --git a/codeigniter/application/controllers/register.php b/codeigniter/application/controllers/register.php new file mode 100644 index 0000000..f1b5780 --- /dev/null +++ b/codeigniter/application/controllers/register.php @@ -0,0 +1,49 @@ +session->userdata('logged_in')){ + $session_data = $this->session->userdata('logged_in'); + $data['username'] = $session_data['username']; + $this->load->view('roomView', $data); + } + else{ + //If no session, redirect to login page + $this->load->view('registerView.php'); + } + + } + + public function verifyRegister(){ + $this->load->helper('form'); + + $this->load->library('form_validation','url'); + + $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean'); + $this->form_validation->set_rules('email', 'Email', 'trim|xss_clean|required|valid_email'); + $this->form_validation->set_rules('password', 'Password', 'trim|xss_clean|required'); + + if ($this->form_validation->run() == FALSE){ + $this->load->view('registerView'); //if validation fails load the registrationForm + } + else{ + $username = htmlspecialchars($_POST['username']); + $email = htmlspecialchars($_POST['email']); + $password =sha1(htmlspecialchars($_POST['password'])); + + $this->load->model('DBFunctions'); + + $result = $this->DBFunctions->register($username,$email,$password); + + if($result){ + $data['message']="

Registration successful! Provide your Username and Password to login.

"; + $this->load->view('loginView',$data); //if registration successful load the loginForm + } + else{ + $data['message']="

Registration unsuccessful! Try it again.

"; + $this->load->view('registerView',$data); //if registration failed load the registerForm + } + } + } +} \ No newline at end of file diff --git a/codeigniter/application/controllers/verifyLogin.php b/codeigniter/application/controllers/verifyLogin.php deleted file mode 100644 index 9efa117..0000000 --- a/codeigniter/application/controllers/verifyLogin.php +++ /dev/null @@ -1,47 +0,0 @@ -load->helper('form'); - - $this->load->library('form_validation','url'); - - $this->form_validation->set_rules('username', 'Username', 'trim|xss_clean'); - $this->form_validation->set_rules('password', 'Password', 'trim|xss_clean|callback_check_database'); - - if ($this->form_validation->run() == FALSE) - { - $this->load->view('loginForm'); //if validation fails load the loginForm - } - else - { //if validation passes go to private area - redirect('room','refresh'); - } - } - - public function check_database($password){ - $username=htmlspecialchars($_POST['username']); - - $this->load->model('DBFunctions'); - - $result=$this->DBFunctions->authenticate($username,$password); - - if($result){ - $sess_array = array(); - - foreach($result as $row){ - $sess_array = array('userID' => $row->userID,'username' => $row->username); - $this->session->set_userdata('logged_in', $sess_array); - } - return true; - } - else{ - $this->form_validation->set_message('check_database', 'Invalid username or password!!'); - return false; - } - } - -} -?> \ No newline at end of file diff --git a/codeigniter/application/controllers/main.php b/codeigniter/application/libraries/Myclass.php similarity index 82% rename from codeigniter/application/controllers/main.php rename to codeigniter/application/libraries/Myclass.php index 1b637b2..fe48186 100644 --- a/codeigniter/application/controllers/main.php +++ b/codeigniter/application/libraries/Myclass.php @@ -1,10 +1,10 @@ session->userdata('logged_in')){ $session_data = $this->session->userdata('logged_in'); $data['username'] = $session_data['username']; diff --git a/codeigniter/application/models/DBFunctions.php b/codeigniter/application/models/DBFunctions.php index 2b2bf76..4b59c64 100644 --- a/codeigniter/application/models/DBFunctions.php +++ b/codeigniter/application/models/DBFunctions.php @@ -7,10 +7,10 @@ function __construct() parent::__construct(); } - public function authenticate($username,$password){ - $this -> db -> select('userID, username, password'); - $this -> db -> from('authenticate'); - $this -> db -> where('username', $username); + public function authenticate($email,$password){ + $this -> db -> select('userID, username,email, password'); + $this -> db -> from('users'); + $this -> db -> where('email', $email); $this -> db -> where('password', $password); $this -> db -> limit(1); @@ -24,5 +24,18 @@ public function authenticate($username,$password){ } } + public function register($username,$email,$password){ + $this->db->set('username',$username); + $this->db->set('email',$email); + $this->db->set('password',$password); + + $this->db->insert('users'); + + if($this->db->affected_rows() == 1){ + return $this->db->affected_rows(); + }else{ + return false; + } + } } ?> \ No newline at end of file diff --git a/codeigniter/application/views/loginForm.php b/codeigniter/application/views/loginView.php similarity index 88% rename from codeigniter/application/views/loginForm.php rename to codeigniter/application/views/loginView.php index 33c1115..4d4ce3b 100644 --- a/codeigniter/application/views/loginForm.php +++ b/codeigniter/application/views/loginView.php @@ -2,7 +2,7 @@ - Welcome to Twitter + Welcome to Twitter::Login + + + + + +
New User Registration
+ +
+load->helper('form'); + +//echo any type of errors +$username_error=form_error('username'); +$email_error=form_error('email'); +$password_error=form_error('password'); + +if($username_error==true && $password_error==true){ + echo("

Username and Password fields are required.

"); +} +else{ + if($username_error==true){ + echo("

Username field is required.

"); + } + elseif($password_error==true){ + echo("

Password field is required.

"); + } + else{ + echo(""); + } +} + +echo($email_error); +?> +
+ +
+ 'registerForm')); + +//set the label for the usename +echo form_label('Username', 'usernameID', array( 'id' => 'labelUserID')); + +//text input type for usename +echo form_input(array('name' => 'username','id' => 'usernameID')); + +//set the label for the usename +echo form_label('Email', 'emailID', array( 'id' => 'labelEmailID')); + +//text input type for usename +echo form_input(array('name' => 'email','id' => 'emailID')); + +//set the label for the password +echo form_label('Password', 'passwordID', array( 'id' => 'labelPassID')); + +//text input type for usename +echo form_password(array('name' => 'password','id' => 'passwordID')); + +//close the form +echo form_close(); +?> + + + +
+
+
+ + + \ No newline at end of file diff --git a/codeigniter/application/views/roomView.php b/codeigniter/application/views/roomView.php index a2d562a..cb5826d 100644 --- a/codeigniter/application/views/roomView.php +++ b/codeigniter/application/views/roomView.php @@ -1 +1,2 @@ -Logout \ No newline at end of file +Logout + \ No newline at end of file From 5406f6a8852145d7bb856ab3fc6b7e21d922f84f Mon Sep 17 00:00:00 2001 From: Satish Jaiswal Date: Sun, 20 Apr 2014 18:38:57 +0900 Subject: [PATCH 03/12] removal of index.php from url --- codeigniter/.htaccess | 3 +++ codeigniter/application/config/config.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 codeigniter/.htaccess diff --git a/codeigniter/.htaccess b/codeigniter/.htaccess new file mode 100644 index 0000000..ae802e3 --- /dev/null +++ b/codeigniter/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine on +RewriteCond $1 !^(index\.php|images|robots\.txt) +RewriteRule ^(.*)$ /index.php/$1 [L] \ No newline at end of file diff --git a/codeigniter/application/config/config.php b/codeigniter/application/config/config.php index 11b2876..7900d53 100644 --- a/codeigniter/application/config/config.php +++ b/codeigniter/application/config/config.php @@ -26,7 +26,7 @@ | variable so that it is blank. | */ -$config['index_page'] = 'index.php'; +$config['index_page'] = ''; /* |-------------------------------------------------------------------------- From 380e9744523525ba295ff2b513decde5888a5954 Mon Sep 17 00:00:00 2001 From: Satish Jaiswal Date: Sat, 26 Apr 2014 21:40:34 +0900 Subject: [PATCH 04/12] fourth commit --- codeigniter/.htaccess | 2 +- codeigniter/application/config/config.php | 2 +- codeigniter/application/config/constants.php | 1 + codeigniter/application/controllers/login.php | 11 +- .../application/controllers/register.php | 57 ++- codeigniter/application/controllers/room.php | 72 ++- codeigniter/application/libraries/Myclass.php | 18 - .../application/models/DBFunctions.php | 26 ++ codeigniter/application/views/loginView.php | 204 +-------- .../application/views/registerView.php | 228 +--------- codeigniter/application/views/room.php | 10 - codeigniter/application/views/roomView.php | 162 ++++++- codeigniter/css/mystyle.css | 411 ++++++++++++++++++ 13 files changed, 756 insertions(+), 448 deletions(-) delete mode 100644 codeigniter/application/libraries/Myclass.php delete mode 100644 codeigniter/application/views/room.php create mode 100644 codeigniter/css/mystyle.css diff --git a/codeigniter/.htaccess b/codeigniter/.htaccess index ae802e3..ba34660 100644 --- a/codeigniter/.htaccess +++ b/codeigniter/.htaccess @@ -1,3 +1,3 @@ RewriteEngine on -RewriteCond $1 !^(index\.php|images|robots\.txt) +RewriteCond $1 !^(index\.php|css|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L] \ No newline at end of file diff --git a/codeigniter/application/config/config.php b/codeigniter/application/config/config.php index 7900d53..b5e76a4 100644 --- a/codeigniter/application/config/config.php +++ b/codeigniter/application/config/config.php @@ -14,7 +14,7 @@ | path to your installation. | */ -$config['base_url'] = ''; +$config['base_url'] = 'http://satishathome.net/'; /* |-------------------------------------------------------------------------- diff --git a/codeigniter/application/config/constants.php b/codeigniter/application/config/constants.php index 4a879d3..48a1b3e 100644 --- a/codeigniter/application/config/constants.php +++ b/codeigniter/application/config/constants.php @@ -1,5 +1,6 @@ session->userdata('logged_in')){ - $session_data = $this->session->userdata('logged_in'); - $data['username'] = $session_data['username']; - $this->load->view('roomView', $data); + redirect('room','refresh'); } else{ //If no session, redirect to login page - $this->load->view('loginView'); + $data['message'] = "NOT_SET"; + $this->load->view('loginView',$data); } } @@ -24,7 +23,8 @@ public function verifyLogin(){ if ($this->form_validation->run() == FALSE) { - $this->load->view('loginView'); //if validation fails load the loginForm + $data['message'] = "LOGIN_FAILED"; + $this->load->view('loginView',$data); //if validation fails load the loginForm } else { //if validation passes go to private area @@ -50,7 +50,6 @@ public function check_database($raw_password){ return true; } else{ - $this->form_validation->set_message('check_database', 'Invalid username or password!!'); return false; } } diff --git a/codeigniter/application/controllers/register.php b/codeigniter/application/controllers/register.php index f1b5780..aef5ee4 100644 --- a/codeigniter/application/controllers/register.php +++ b/codeigniter/application/controllers/register.php @@ -4,13 +4,12 @@ class Register extends CI_Controller { public function index(){ if($this->session->userdata('logged_in')){ - $session_data = $this->session->userdata('logged_in'); - $data['username'] = $session_data['username']; - $this->load->view('roomView', $data); + redirect('room','refresh'); } else{ //If no session, redirect to login page - $this->load->view('registerView.php'); + $data['message'] = "NOT_SET"; + $this->load->view('registerView',$data); } } @@ -23,9 +22,51 @@ public 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'); $this->form_validation->set_rules('password', 'Password', 'trim|xss_clean|required'); - + if ($this->form_validation->run() == FALSE){ - $this->load->view('registerView'); //if validation fails load the registrationForm + //echo any type of errors + $username_error=form_error('username'); + $email_error=form_error('email'); + $password_error=form_error('password'); + + if($username_error==true && $password_error==true){ + $data['message'] = "USERNAME_PASSWORD"; + } + else{ + if($username_error==true){ + $data['message'] = "USERNAME"; + } + elseif($password_error==true){ + $data['message'] = "PASSWORD"; + } + else{ + $data['message'] = "UNKNOWN"; + } + } + + if($email_error==true){ + if($email_error == "

The Email field is required.

"){ + if(isset($data['message'])){ + $data['message'] = $data['message'] . "_EMAIL"; + } + else{ + $data['message'] = "EMAIL"; + } + } + elseif($email_error == "

The Email field must contain a valid email address.

"){ + if(isset($data['message'])){ + $data['message'] = $data['message'] . "_EMAIL_INVALID"; + } + else{ + $data['message'] = "EMAIL_INVALID"; + } + } + else{ + $data['message'] = "UNKNOWN"; + } + } + + $this->load->view('registerView',$data); //if validation fails load the registrationForm } else{ $username = htmlspecialchars($_POST['username']); @@ -37,11 +78,11 @@ public function verifyRegister(){ $result = $this->DBFunctions->register($username,$email,$password); if($result){ - $data['message']="

Registration successful! Provide your Username and Password to login.

"; + $data['message']="REGISTRATION_SUCCESSFUL"; $this->load->view('loginView',$data); //if registration successful load the loginForm } else{ - $data['message']="

Registration unsuccessful! Try it again.

"; + $data['message']="REGISTRATION_FAILED"; $this->load->view('registerView',$data); //if registration failed load the registerForm } } diff --git a/codeigniter/application/controllers/room.php b/codeigniter/application/controllers/room.php index e05ae6b..99448e4 100644 --- a/codeigniter/application/controllers/room.php +++ b/codeigniter/application/controllers/room.php @@ -6,9 +6,15 @@ class Room extends CI_Controller { public function index(){ if($this->session->userdata('logged_in')){ - $session_data = $this->session->userdata('logged_in'); - $data['username'] = $session_data['username']; - $this->load->view('roomView', $data); + + $result = $this->showPosts("1"); + + if($result){ + $this->load->view('roomView',$result); + } + else{ + redirect('room','refresh'); + } } else{ //If no session, redirect to login page @@ -16,6 +22,66 @@ public function index(){ } } + 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('DBFunctions'); + + $result = $this->DBFunctions->posts($page); + + if($result){ + if(!isset($result['message'])){ + $result['message'] = "NOT_SET"; + } + $n = count($result); + array_unshift($result,$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] = $result[$i]; + } + + $data['message'] = $result['message']; + + return $data; + + //$this->load->view('roomView', $data); + + } + else{ + + return false; + + //redirect('room','refresh'); //handling uri entered by the user + } + } + + public function ajax($param){ + + $result = $this->showPosts($param); + + + if($result){ + print_r($result); + } + else{ + echo("NO"); + } + } + + public function more($param){ + + $result = $this->showPosts($param); + + if($result){ + $this->load->view('roomView',$result); + } + else{ + redirect('room','refresh'); + } + } + public function logout(){ $this->session->unset_userdata('logged_in'); session_destroy(); diff --git a/codeigniter/application/libraries/Myclass.php b/codeigniter/application/libraries/Myclass.php deleted file mode 100644 index fe48186..0000000 --- a/codeigniter/application/libraries/Myclass.php +++ /dev/null @@ -1,18 +0,0 @@ -session->userdata('logged_in')){ - $session_data = $this->session->userdata('logged_in'); - $data['username'] = $session_data['username']; - $this->load->view('roomView', $data); - } - else{ - //If no session, redirect to login page - redirect('login', 'refresh'); - } - } -} diff --git a/codeigniter/application/models/DBFunctions.php b/codeigniter/application/models/DBFunctions.php index 4b59c64..f05d10b 100644 --- a/codeigniter/application/models/DBFunctions.php +++ b/codeigniter/application/models/DBFunctions.php @@ -37,5 +37,31 @@ public function register($username,$email,$password){ return false; } } + + public function posts($page){ + $length = 3; + $num_of_rows = $this->db->get('posts')->num_rows(); + + if($length * $page <= $num_of_rows){ + $this->db->select('username,posts,time_of_post'); + $this->db->from('posts'); + $this->db->order_by('time_of_post'); + $this->db->limit($length,$length*($page - 1)); + + $query = $this->db->get(); + + if($query->num_rows()>0){ + return $query->result_array(); + } + else{ + return false; + } + } + else{ + $data = $this->db->get('posts')->result_array(); + $data['message'] = "VIEW_MAX_POST_REACHED"; + return $data; + } + } } ?> \ No newline at end of file diff --git a/codeigniter/application/views/loginView.php b/codeigniter/application/views/loginView.php index 4d4ce3b..8799a71 100644 --- a/codeigniter/application/views/loginView.php +++ b/codeigniter/application/views/loginView.php @@ -1,196 +1,27 @@ - - Welcome to Twitter::Login - - + + +
Mini Twitter
+
+
load->helper('form'); - -//echo any type of errors -echo validation_errors(); - -//echo the message of successful registration, whenever done if(isset($message)){ echo($message); } @@ -198,30 +29,35 @@ function loginform(){ ?>
-
+
+ +
load->helper('form'); //open the form tab and set action to validate function of the login class echo form_open('login/verifyLogin',array('name' => 'loginForm')); //set the label for the email -echo form_label('Email', 'emailID', array( 'id' => 'labelEmailID')); +echo form_label('Email', 'loginemailID', array( 'id' => 'loginlabelEmailID')); //text input type for usename -echo form_input(array('name' => 'email','id' => 'emailID')); +echo form_input(array('name' => 'email','id' => 'loginemailID')); //set the label for the password -echo form_label('Password', 'passwordID', array( 'id' => 'labelPassID')); +echo form_label('Password', 'loginpasswordID', array( 'id' => 'loginlabelPassID')); //text input type for usename -echo form_password(array('name' => 'password','id' => 'passwordID')); +echo form_password(array('name' => 'password','id' => 'loginpasswordID')); //close the form echo form_close(); ?> - - - + +
+ +
diff --git a/codeigniter/application/views/registerView.php b/codeigniter/application/views/registerView.php index de69e09..31bcf3c 100644 --- a/codeigniter/application/views/registerView.php +++ b/codeigniter/application/views/registerView.php @@ -1,197 +1,10 @@ - - Welcome to Twitter::Registration - - + + + + + + + +
+ +Logout +
+ + + +
+ + + +
+ +
+ + + +
+ + + +
+
+ +
+
+
+
"); + echo("

". + ${'di'.$i}['username']. + "". + ${'di'.$i}['time_of_post'] + + ."

"); + echo("

".${'di'.$i}['posts']."

"); + echo("
"); +} +?> +
+
+ +
+ +
+ see more.."); + echo("see more.."); + } + else{ + echo("recent only.."); + } + ?> + + +
+ +
+ +
+ + + +
+ + + \ No newline at end of file diff --git a/codeigniter/css/mystyle.css b/codeigniter/css/mystyle.css new file mode 100644 index 0000000..a68613e --- /dev/null +++ b/codeigniter/css/mystyle.css @@ -0,0 +1,411 @@ +@charset "utf-8"; +/* CSS Document */ + +body{ + margin:0px 0px 0px 0px; +} + +/* ----------------------------------------------LOGO CSS------------------------------------------- */ + +#logoID{ + background:#F5F5F5; + width:100%; + height:70px; + border-bottom:1px #E5E5E5 solid; + font-family:"Arial Black", Gadget, sans-serif; + font-size:xx-large; + font-weight:bold; + padding:20px 0px 0px 20px; +} + +/* ----------------------------------------------SPACER CSS------------------------------------------- */ + +#spacerID{ + padding-top:5px; + padding-bottom:5px; + padding-left:10px; + padding-right:10px; +} + +/* ----------------------------------------------MESSAGE CSS------------------------------------------- */ + +#msgID{ + background:#FFC; + font-weight:bold; + text-align:center; + font-size:12px; + width:100%; + border:1px #69C solid; + font-family:Arial, Helvetica, sans-serif; + padding:10px 10px 10px 10px; +} + +/* ----------------------------------------------LOGIN FORM CSS------------------------------------------- */ + +#loginFormID{ + background:#F5F5F5; + width:300px; + height:250px; + position:relative; + left:40%; + border:1px #E5E5E5 solid; +} + +/* ----------------------------------------------LOGIN EMAIL CSS------------------------------------------- */ + +#loginlabelEmailID{ + position:absolute; + top: 20px; + width:36px; + left: 90px; + padding:5px 5px 5px 5px; + font-family:Arial, Helvetica, sans-serif; + font-size:smaller; + color:#B40313; + font-weight:bold; +} + +#loginemailID{ + position:absolute; + top: 53px; + border:2px #B40313 solid; + width:160px; + left: 89px; + padding:5px 5px 5px 5px; +} + +/* ----------------------------------------------LOGIN PASSWORD CSS------------------------------------------- */ + +#loginlabelPassID{ + position:absolute; + left: 90px; + top: 86px; + width: 60px; + padding:5px 5px 5px 5px; + font-family:Arial, Helvetica, sans-serif; + font-size:smaller; + color:#B40313; + font-weight:bold; +} + + +#loginpasswordID{ + position:absolute; + border:2px #B40313 solid; + left: 89px; + top: 117px; + width: 160px; + padding:5px 5px 5px 5px; +} + +/* ----------------------------------------------LOGIN LOGIN BUTTON CSS------------------------------------------- */ + +#loginloginbuttonID a{ + position:absolute; + left: 105px; + top: 160px; + width: 50px; + height: 20px; + text-align:center; + font:11px arial; + color: #FFFFFF; + font-weight:bold; + padding-top:8px; + padding-bottom:2px; + padding-left:5px; + padding-right:5px; + text-decoration: none; + background-color:#B40313; +} +#loginloginbuttonID a:hover{ + color:#ffffff; + background:#DE909D; +} + +/* ----------------------------------------------LOGIN REGISTER BUTTON CSS------------------------------------------- */ + +#loginregisterbuttonID a{ + position:absolute; + left: 177px; + top: 160px; + width: 50px; + height: 20px; + text-align:center; + font:11px arial; + color: #FFFFFF; + font-weight:bold; + padding-top:8px; + padding-bottom:2px; + padding-left:5px; + padding-right:5px; + text-decoration: none; + background-color:#B40313; +} +#loginregisterbuttonID a:hover{ + color:#ffffff; + background:#DE909D; +} + +/* ----------------------------------------------LOGIN FORGOT PASSWORD CSS------------------------------------------- */ + +#loginforgotpassID a{ + position:absolute; + left: 119px; + top: 198px; + font-family:Georgia, "Times New Roman", Times, serif; + font-size:smaller; + color:#B40313; +} +#loginforgotpassID a:hover{ + text-decoration:none; +} + + +/* ----------------------------------------------REGISTER FORM CSS------------------------------------------- */ + +#registerFormID{ + background:#F5F5F5; + width:300px; + height:300px; + position:relative; + left:40%; + border:1px #E5E5E5 solid; +} + +/* ----------------------------------------------REGISTER USERNAME CSS------------------------------------------- */ + +#usernameID{ + position:absolute; + top: 46px; + border:2px #B40313 solid; + width:160px; + left: 89px; + padding:5px 5px 5px 5px; +} + +#labelUserID{ + position:absolute; + top: 20px; + width:36px; + left: 90px; + padding:5px 5px 5px 5px; + font-family:Arial, Helvetica, sans-serif; + font-size:smaller; + color:#B40313; + font-weight:bold; +} + +/* ----------------------------------------------REGISTER EMAIL CSS------------------------------------------- */ + +#emailID{ + position:absolute; + top: 111px; + border:2px #B40313 solid; + width:160px; + left: 89px; + padding:5px 5px 5px 5px; +} + +#labelEmailID{ + position:absolute; + top: 78px; + width:36px; + left: 90px; + padding:5px 5px 5px 5px; + font-family:Arial, Helvetica, sans-serif; + font-size:smaller; + color:#B40313; + font-weight:bold; +} + +/* ----------------------------------------------REGISTER PASSWORD CSS------------------------------------------- */ + +#passwordID{ + position:absolute; + border:2px #B40313 solid; + left: 89px; + top: 175px; + width: 160px; + padding:5px 5px 5px 5px; +} + +#labelPassID{ + position:absolute; + left: 90px; + top: 144px; + width: 60px; + padding:5px 5px 5px 5px; + font-family:Arial, Helvetica, sans-serif; + font-size:smaller; + color:#B40313; + font-weight:bold; +} + +/* ----------------------------------------------REGISTER LOGIN BUTTON CSS------------------------------------------- */ + +#loginbuttonID a{ + position:absolute; + left: 105px; + top: 218px; + width: 50px; + height: 20px; + text-align:center; + font:11px arial; + color: #FFFFFF; + font-weight:bold; + padding-top:8px; + padding-bottom:2px; + padding-left:5px; + padding-right:5px; + text-decoration: none; + background-color:#B40313; +} +#loginbuttonID a:hover{ + color:#ffffff; + background:#DE909D; +} + +/* ----------------------------------------------REGISTER REGISTER BUTTON CSS------------------------------------------- */ + +#registerbuttonID a{ + position:absolute; + left: 177px; + top: 217px; + width: 50px; + height: 20px; + text-align:center; + font:11px arial; + color: #FFFFFF; + font-weight:bold; + padding-top:8px; + padding-bottom:2px; + padding-left:5px; + padding-right:5px; + text-decoration: none; + background-color:#B40313; +} +#registerbuttonID a:hover{ + color:#ffffff; + background:#DE909D; +} + +/* ----------------------------------------------REGISTER FORGOT PASSWORD CSS------------------------------------------- */ + +#forgotpassID a{ + position:absolute; + left: 119px; + top: 256px; + font-family:Georgia, "Times New Roman", Times, serif; + font-size:smaller; + color:#B40313; +} +#forgotpassID a:hover{ + text-decoration:none; +} + +/* ----------------------------------------------ROOM CSS------------------------------------------- */ + +#roomMenuID{ + color:#FFFFFF; + text-align:right; + font:11px arial; + font-weight:bold; + padding-top:10px; + padding-bottom:10px; + padding-left:20px; + padding-right:20px; + text-decoration: none; + background-color:#B40313; + text-transform:capitalize; +} + +#roomMenuID a{ + color:#FFFFFF; + text-align:right; + font:11px arial; + font-weight:bold; + padding-top:10px; + padding-bottom:10px; + padding-left:20px; + padding-right:50px; + text-decoration: none; + background-color:#B40313; + text-transform:capitalize; +} + +#roomBodyID{ + background:#F5F5F5; + width:100%; + height:100%; + border:1px #E5E5E5 solid; +} + +#statusInputID{ + background:#FFFFFF; + width:40%; + height:100px; + position:relative; + left:30%; + border:1px #E5E5E5 solid; +} + +#statusDisplayID{ + background:#FFFFFF; + width:40%; + position:relative; + left:30%; + border:1px #E5E5E5 solid; + padding-bottom:0px; + padding-left:10px; + padding-right:10px; + padding-top:0px; +} + +#statusByAjaxID{ + background:#FFFFFF; + width:40%; + position:relative; + left:30%; + border:1px #E5E5E5 solid; + padding-bottom:0px; + padding-left:10px; + padding-right:10px; + padding-top:0px; +} + +#morePostID a{ + position:relative; + left:48%; + width: 100px; + height: 20px; + text-align:center; + font:11px arial; + color: #FFFFFF; + font-weight:bold; + padding-top:10px; + padding-bottom:10px; + padding-left:25px; + padding-right:25px; + text-decoration: none; + background-color:#B40313; +} + +#morePostID a:hover{ + color:#ffffff; + background:#DE909D; +} + +p.usernameClass{ + text-transform:capitalize; + font-weight:bold; +} + +h7.dateClass{ + text-align:right; + float:right; + font-weight:normal; + color:#999; + font-style:italic; + font-size:small; +} + From ac9e8210a6faea26ab9bce89a3e8e27f31105ec4 Mon Sep 17 00:00:00 2001 From: Satish Jaiswal Date: Sun, 27 Apr 2014 01:30:18 +0900 Subject: [PATCH 05/12] pegination complete --- codeigniter/application/config/constants.php | 1 + codeigniter/application/controllers/room.php | 6 +- .../application/models/DBFunctions.php | 28 ++++---- codeigniter/application/views/roomView.php | 66 ++++++++++++------- codeigniter/css/mystyle.css | 14 ++-- 5 files changed, 68 insertions(+), 47 deletions(-) diff --git a/codeigniter/application/config/constants.php b/codeigniter/application/config/constants.php index 48a1b3e..551c340 100644 --- a/codeigniter/application/config/constants.php +++ b/codeigniter/application/config/constants.php @@ -1,6 +1,7 @@ db->get('posts')->num_rows(); - - if($length * $page <= $num_of_rows){ - $this->db->select('username,posts,time_of_post'); - $this->db->from('posts'); - $this->db->order_by('time_of_post'); - $this->db->limit($length,$length*($page - 1)); + $this->db->select('username,posts,time_of_post'); + $this->db->from('posts'); + $this->db->order_by('time_of_post'); + $this->db->limit(LENGTH,LENGTH*($page - 1)); - $query = $this->db->get(); + $query = $this->db->get(); - if($query->num_rows()>0){ - return $query->result_array(); + if($query->num_rows()>=0){ + if($query->num_rowsresult_array(); + $data['message'] = "MAX_VIEW_REACHED"; } else{ - return false; + $data = $query->result_array(); } + + return $data; } else{ - $data = $this->db->get('posts')->result_array(); - $data['message'] = "VIEW_MAX_POST_REACHED"; - return $data; + return false; } } } diff --git a/codeigniter/application/views/roomView.php b/codeigniter/application/views/roomView.php index 9fea958..c096bab 100644 --- a/codeigniter/application/views/roomView.php +++ b/codeigniter/application/views/roomView.php @@ -68,7 +68,35 @@ function ajaxPegination(str) { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var rawData = xmlhttp.responseText; var data = getData(rawData); - document.getElementById("statusByAjaxID").innerHTML=rawData; + + var numberOfPosts = rawData.split("Array").length-2; + var page = parseInt(data[0][2]) + 1; + var message = data[numberOfPosts + 1][0]; + + document.getElementById("see_moreID").href = "javascript:ajaxPegination(" + page + ")"; + + document.getElementById("msgID").innerHTML = message; + + if(message == "MAX_VIEW_REACHED"){ + document.getElementById("see_moreID").href = ""; + document.getElementById("see_moreID").innerHTML = "recent only..."; + } + + var arrayDiv = new Array(); + + var length = ; + var increment = length * (parseInt(data[0][2]) - 2); + for(var k = 0; k < numberOfPosts; k++){ + var dText="

" + data[k+1][0]+""+data[k+1][2]+"

"+data[k+1][1]+"

"; + var br = document.createElement('br'); + arrayDiv[increment] = document.createElement('div'); + arrayDiv[increment].id = 'statusDisplayID' + increment; + arrayDiv[increment].className = 'statusDisplayClass'; + statusByAjaxID.appendChild(arrayDiv[increment]); + statusByAjaxID.appendChild(br); + document.getElementById("statusDisplayID" + increment).innerHTML = dText; + increment++; + } console.log(data); } } @@ -111,10 +139,11 @@ function ajaxPegination(str) {
-
+
+
+
-
-
+
"); } ?> -
-
- -
+ +
+
+ +
-
- see more.."); - echo("see more.."); - } - else{ - echo("recent only.."); - } - ?> - - -
+
+
+see more..");?> +
+
-
-
diff --git a/codeigniter/css/mystyle.css b/codeigniter/css/mystyle.css index a68613e..5e16060 100644 --- a/codeigniter/css/mystyle.css +++ b/codeigniter/css/mystyle.css @@ -351,9 +351,9 @@ body{ #statusDisplayID{ background:#FFFFFF; - width:40%; + width:53.4%; position:relative; - left:30%; + left:22%; border:1px #E5E5E5 solid; padding-bottom:0px; padding-left:10px; @@ -361,11 +361,9 @@ body{ padding-top:0px; } -#statusByAjaxID{ +.statusDisplayClass{ background:#FFFFFF; - width:40%; position:relative; - left:30%; border:1px #E5E5E5 solid; padding-bottom:0px; padding-left:10px; @@ -373,6 +371,12 @@ body{ padding-top:0px; } +#statusByAjaxID{ + width:55%; + position:relative; + left:22%; +} + #morePostID a{ position:relative; left:48%; From c4630c8a8f573ed1bae540230427d3224752fd68 Mon Sep 17 00:00:00 2001 From: Satish Jaiswal Date: Tue, 29 Apr 2014 01:54:58 +0900 Subject: [PATCH 06/12] fixed some issues --- codeigniter/.htaccess | 2 +- codeigniter/application/config/constants.php | 8 +- codeigniter/application/controllers/login.php | 71 ++++--- .../application/controllers/register.php | 97 ++++----- codeigniter/application/controllers/room.php | 87 ++++---- .../application/models/DBFunctions.php | 40 +++- codeigniter/application/views/loginView.php | 13 +- .../application/views/registerView.php | 18 +- codeigniter/application/views/roomView.php | 200 +++++++++++------- codeigniter/css/mystyle.css | 98 +++++++-- codeigniter/js/myjavascript.js | 101 +++++++++ 11 files changed, 485 insertions(+), 250 deletions(-) create mode 100644 codeigniter/js/myjavascript.js diff --git a/codeigniter/.htaccess b/codeigniter/.htaccess index ba34660..8fbdab9 100644 --- a/codeigniter/.htaccess +++ b/codeigniter/.htaccess @@ -1,3 +1,3 @@ RewriteEngine on -RewriteCond $1 !^(index\.php|css|images|robots\.txt) +RewriteCond $1 !^(index\.php|css|js|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L] \ No newline at end of file diff --git a/codeigniter/application/config/constants.php b/codeigniter/application/config/constants.php index 551c340..32c3b3d 100644 --- a/codeigniter/application/config/constants.php +++ b/codeigniter/application/config/constants.php @@ -1,7 +1,11 @@ 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'); } - else{ - //If no session, redirect to login page - $data['message'] = "NOT_SET"; - $this->load->view('loginView',$data); - } + } + + public function index(){ + $data['message'] = "NOT_SET"; + $this->load->view('loginView',$data); } public function verifyLogin(){ @@ -19,38 +27,33 @@ public function verifyLogin(){ $this->load->library('form_validation','url'); $this->form_validation->set_rules('username', 'Username', 'trim|xss_clean'); - $this->form_validation->set_rules('password', 'Password', 'trim|xss_clean|callback_check_database'); + $this->form_validation->set_rules('password', 'Password', 'trim|xss_clean'); - if ($this->form_validation->run() == FALSE) - { - $data['message'] = "LOGIN_FAILED"; - $this->load->view('loginView',$data); //if validation fails load the loginForm + if ($this->form_validation->run() == FALSE){ //if form validation fails, redirect to login page with message + $data['message'] = LOGIN_FAILED; + $this->load->view('loginView',$data); } - else - { //if validation passes go to private area - redirect('room','refresh'); - } - } - - public function check_database($raw_password){ - $email = htmlspecialchars($_POST['email']); - $password = sha1(htmlspecialchars($raw_password)); - - $this->load->model('DBFunctions'); + else{ //if form validation passes, get data and check database + $email = htmlspecialchars($_POST['email']); + $password = sha1(htmlspecialchars($_POST['password'])); + + $this->load->model('DBFunctions'); - $result=$this->DBFunctions->authenticate($email,$password); //the authenticate function is in model:DBFunctions + $result=$this->DBFunctions->authenticate($email,$password); //the authenticate function is in model:DBFunctions - if($result){ - $sess_array = array(); + if($result){ //if user exists create session and redirect to room + $sess_array = array(); - foreach($result as $row){ - $sess_array = array('userID' => $row->userID,'username' => $row->username); - $this->session->set_userdata('logged_in', $sess_array); + foreach($result as $row){ + $sess_array = array('userID' => $row->userID,'username' => $row->username); + $this->session->set_userdata('logged_in', $sess_array); + } + redirect('room','refresh'); } - return true; - } - else{ - return false; - } + else{ // if user does not exist, redirect to login page with message + $data['message'] = LOGIN_FAILED; + $this->load->view('loginView',$data); + } + } } } diff --git a/codeigniter/application/controllers/register.php b/codeigniter/application/controllers/register.php index aef5ee4..e45e6e3 100644 --- a/codeigniter/application/controllers/register.php +++ b/codeigniter/application/controllers/register.php @@ -1,17 +1,24 @@ before(); + return call_user_func_array(array($this, $method), $args); + } + show_404(); + } + + private function before() { if($this->session->userdata('logged_in')){ redirect('room','refresh'); } - else{ - //If no session, redirect to login page - $data['message'] = "NOT_SET"; - $this->load->view('registerView',$data); - } - + } + + public function index(){ + $data['message'] = "NOT_SET"; + $this->load->view('registerView',$data); } public function verifyRegister(){ @@ -23,68 +30,36 @@ public function verifyRegister(){ $this->form_validation->set_rules('email', 'Email', 'trim|xss_clean|required|valid_email'); $this->form_validation->set_rules('password', 'Password', 'trim|xss_clean|required'); - if ($this->form_validation->run() == FALSE){ - //echo any type of errors - $username_error=form_error('username'); - $email_error=form_error('email'); - $password_error=form_error('password'); - - if($username_error==true && $password_error==true){ - $data['message'] = "USERNAME_PASSWORD"; - } - else{ - if($username_error==true){ - $data['message'] = "USERNAME"; - } - elseif($password_error==true){ - $data['message'] = "PASSWORD"; - } - else{ - $data['message'] = "UNKNOWN"; - } - } - - if($email_error==true){ - if($email_error == "

The Email field is required.

"){ - if(isset($data['message'])){ - $data['message'] = $data['message'] . "_EMAIL"; - } - else{ - $data['message'] = "EMAIL"; - } - } - elseif($email_error == "

The Email field must contain a valid email address.

"){ - if(isset($data['message'])){ - $data['message'] = $data['message'] . "_EMAIL_INVALID"; - } - else{ - $data['message'] = "EMAIL_INVALID"; - } - } - else{ - $data['message'] = "UNKNOWN"; - } - } - - $this->load->view('registerView',$data); //if validation fails load the registrationForm + if ($this->form_validation->run() == FALSE){ // if form validation fails, get form errors and set messages, redirect to register + $data['message'] = "VALIDATION_ERRORS"; + $this->load->view('registerView',$data); //if validation fails load the registrationForm + } - else{ + else{ //if form validation passes, get data,check duplicate,do redirects $username = htmlspecialchars($_POST['username']); $email = htmlspecialchars($_POST['email']); $password =sha1(htmlspecialchars($_POST['password'])); $this->load->model('DBFunctions'); - $result = $this->DBFunctions->register($username,$email,$password); + $isUserExists = $this->DBFunctions->userExists($email); //check if user exists - if($result){ - $data['message']="REGISTRATION_SUCCESSFUL"; - $this->load->view('loginView',$data); //if registration successful load the loginForm + if($isUserExists){ // if exists ask for new username and send to register + $data['message'] = USER_EXISTS; + $this->load->view('registerView',$data); } - else{ - $data['message']="REGISTRATION_FAILED"; - $this->load->view('registerView',$data); //if registration failed load the registerForm + else{ // if doesnot exis, create this user + $isEnteredIntoDatabase = $this->DBFunctions->register($username,$email,$password); // entering data into database + + if($isEnteredIntoDatabase){ + $data['message']=REGISTRATION_SUCCESSFUL; + $this->load->view('loginView',$data); //if registration successful load the loginForm + } + else{ + $data['message']=REGISTRATION_FAILED; + $this->load->view('registerView',$data); //if registration failed load the registerForm + } } } - } + } } \ No newline at end of file diff --git a/codeigniter/application/controllers/room.php b/codeigniter/application/controllers/room.php index ecb04ab..4b7df47 100644 --- a/codeigniter/application/controllers/room.php +++ b/codeigniter/application/controllers/room.php @@ -3,22 +3,34 @@ 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(){ - if($this->session->userdata('logged_in')){ - - $result = $this->showPosts("1"); + $posts = $this->showPosts("1"); - if($result){ - $this->load->view('roomView',$result); - } - else{ - redirect('room','refresh'); - } + if($posts){ //if result exists send the result to room for display + $this->load->view('roomView',$posts); } - else{ - //If no session, redirect to login page - redirect('login', 'refresh'); + else{ + $data['message'] = "NO_POSTS_YET"; + $this->load->view('roomView',$data); } } @@ -27,56 +39,55 @@ public function showPosts($parameter){ $session_data = $this->session->userdata('logged_in'); $this->load->model('DBFunctions'); + $postsFormDB = $this->DBFunctions->getPosts($page); - $result = $this->DBFunctions->posts($page); - - if($result){ - if(!isset($result['message'])){ - $result['message'] = "NOT_SET"; + if($postsFormDB){ + if(!isset($postsFormDB['message'])){ + $postsFormDB['message'] = "NOT_SET"; } - $n = count($result); - array_unshift($result,$session_data['username'],$n + 2,$page); + $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] = $result[$i]; + $data[$di] = $postsFormDB[$i]; } - - $data['message'] = $result['message']; - + $data['message'] = $postsFormDB['message']; return $data; - - //$this->load->view('roomView', $data); - } else{ return false; - redirect('room','refresh'); //handling uri entered by the user } } public function ajax($param){ - - $result = $this->showPosts($param); - - - if($result){ - print_r($result); + $posts = $this->showPosts($param); + if($posts){ + print_r($posts); //returns the array to ajax responseText } else{ echo("NO!"); } } - public function more($param){ + public function ajaxPost(){ + if(isset($_POST['username'])&&isset($_POST['status'])){ + $username = $_POST['username']; + $posts = $_POST['status']; + $date = date("Y-m-d H:i:s"); - $result = $this->showPosts($param); + $this->load->model('DBFunctions'); + $insertPost = $this->DBFunctions->post($username,$posts,$date); - if($result){ - $this->load->view('roomView',$result); + if($insertPost){ + echo($date); + } + else{ + echo("false"); + } } else{ - redirect('room','refresh'); + echo("VARIABLES_NOT_SET"); } } diff --git a/codeigniter/application/models/DBFunctions.php b/codeigniter/application/models/DBFunctions.php index 45079d9..ca68c29 100644 --- a/codeigniter/application/models/DBFunctions.php +++ b/codeigniter/application/models/DBFunctions.php @@ -24,6 +24,22 @@ public function authenticate($email,$password){ } } + public function userExists($email){ + $this->db->select('email'); + $this->db->from('users'); + $this->db->where('email',$email); + $this->db->limit(1); + + $query = $this->db->get(); + + if($query->num_rows == 1){ + return true; + } + else{ + return false; + } + } + public function register($username,$email,$password){ $this->db->set('username',$username); $this->db->set('email',$email); @@ -38,23 +54,37 @@ public function register($username,$email,$password){ } } - public function posts($page){ + public function post($username,$posts,$date){ + $this->db->set('username',$username); + $this->db->set('posts',$posts); + $this->db->set('time_of_post',$date); + + $this->db->insert('posts'); + + if($this->db->affected_rows() == 1){ + return true; + } + else{ + return false; + } + } + + public function getPosts($page){ $this->db->select('username,posts,time_of_post'); $this->db->from('posts'); - $this->db->order_by('time_of_post'); + $this->db->order_by('time_of_post','DESC'); $this->db->limit(LENGTH,LENGTH*($page - 1)); $query = $this->db->get(); - if($query->num_rows()>=0){ + if($query->num_rows()>0){ if($query->num_rowsresult_array(); $data['message'] = "MAX_VIEW_REACHED"; } else{ - $data = $query->result_array(); + $data = $query->result_array(); //when MAX_VIEW_NOT_REACHED message is not set } - return $data; } else{ diff --git a/codeigniter/application/views/loginView.php b/codeigniter/application/views/loginView.php index 8799a71..d944b69 100644 --- a/codeigniter/application/views/loginView.php +++ b/codeigniter/application/views/loginView.php @@ -20,13 +20,8 @@ function loginform(){
-
- +
"> +
@@ -59,7 +54,9 @@ function loginform(){
-
+ +
+
diff --git a/codeigniter/application/views/registerView.php b/codeigniter/application/views/registerView.php index 31bcf3c..a4dfd8a 100644 --- a/codeigniter/application/views/registerView.php +++ b/codeigniter/application/views/registerView.php @@ -18,11 +18,18 @@ function registerform(){
-
+
"> load->helper('form'); + +//set the error delimiters, the default one add

+ +if(isset($message)&&$message != "VALIDATION_ERRORS"){ + echo($message); } +echo validation_errors(); ?>
@@ -30,9 +37,6 @@ function registerform(){
load->helper('form'); - //open the form tab and set action to validate function of the login class echo form_open('register/verifyRegister',array('name' => 'registerForm')); @@ -61,7 +65,9 @@ function registerform(){
-
+ +
+
diff --git a/codeigniter/application/views/roomView.php b/codeigniter/application/views/roomView.php index c096bab..cb41aa1 100644 --- a/codeigniter/application/views/roomView.php +++ b/codeigniter/application/views/roomView.php @@ -4,33 +4,51 @@ Room - + - -
- + Logout
+ - -
- - - -
- -
- - - -
- - - +
+
+
+ + + + +
- +
+ +
-
+
+ +
+
"); @@ -158,23 +198,21 @@ function ajaxPegination(str) { echo("
"); } ?> - +
- +
- +
see more..");?>

-
+ +
- - -
- +
\ No newline at end of file diff --git a/codeigniter/css/mystyle.css b/codeigniter/css/mystyle.css index 5e16060..0b04174 100644 --- a/codeigniter/css/mystyle.css +++ b/codeigniter/css/mystyle.css @@ -2,14 +2,17 @@ /* CSS Document */ body{ - margin:0px 0px 0px 0px; + margin-bottom:0px; + margin-left:15%; + margin-right:15%; + margin-top:0px; } /* ----------------------------------------------LOGO CSS------------------------------------------- */ #logoID{ - background:#F5F5F5; - width:100%; + background:#B40313; + color:#FFFFFF; height:70px; border-bottom:1px #E5E5E5 solid; font-family:"Arial Black", Gadget, sans-serif; @@ -34,7 +37,6 @@ body{ font-weight:bold; text-align:center; font-size:12px; - width:100%; border:1px #69C solid; font-family:Arial, Helvetica, sans-serif; padding:10px 10px 10px 10px; @@ -47,7 +49,7 @@ body{ width:300px; height:250px; position:relative; - left:40%; + left:36%; border:1px #E5E5E5 solid; } @@ -168,7 +170,7 @@ body{ width:300px; height:300px; position:relative; - left:40%; + left:36%; border:1px #E5E5E5 solid; } @@ -319,6 +321,21 @@ body{ text-transform:capitalize; } +#footerID{ + color:#FFFFFF; + text-align:center; + font:11px arial; + font-weight:bold; + height:50px; + padding-top:10px; + padding-bottom:10px; + padding-left:20px; + padding-right:20px; + text-decoration: none; + background-color:#B40313; + text-transform:capitalize; +} + #roomMenuID a{ color:#FFFFFF; text-align:right; @@ -341,14 +358,36 @@ body{ } #statusInputID{ - background:#FFFFFF; - width:40%; + width:50%; height:100px; position:relative; - left:30%; - border:1px #E5E5E5 solid; + left:24.5%; + border:0px #E5E5E5 solid; +} + +#postButtonID a{ + position:relative; + left:46%; + width: 100px; + height: 20px; + text-align:center; + font:11px arial; + color: #FFFFFF; + font-weight:bold; + padding-top:10px; + padding-bottom:10px; + padding-left:25px; + padding-right:25px; + text-decoration: none; + background-color:#B40313; } +#postButtonID a:hover{ + color:#ffffff; + background:#DE909D; +} + + #statusDisplayID{ background:#FFFFFF; width:53.4%; @@ -363,7 +402,9 @@ body{ .statusDisplayClass{ background:#FFFFFF; + width:53.4%; position:relative; + left:22%; border:1px #E5E5E5 solid; padding-bottom:0px; padding-left:10px; @@ -372,14 +413,12 @@ body{ } #statusByAjaxID{ - width:55%; - position:relative; - left:22%; + } #morePostID a{ position:relative; - left:48%; + left:45%; width: 100px; height: 20px; text-align:center; @@ -413,3 +452,34 @@ h7.dateClass{ font-size:small; } + +/*---------------------------------------------------------------------GLOWING TEXTAREA-----------------------------------------------------------*/ + +textarea#textAreaID{ + resize:none; + color:#666; + font-size:14px; + -moz-border-radius: 8px; -webkit-border-radius: 8px; + margin:5px 0px 10px 0px; + padding:10px; + height:70px; + width:450px; + border:#999 1px solid; + font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif; + transition: all 0.25s ease-in-out; + -webkit-transition: all 0.25s ease-in-out; + -moz-transition: all 0.25s ease-in-out; + box-shadow: 0 0 5px rgba(81, 203, 238, 0); + -webkit-box-shadow: 0 0 5px rgba(81, 203, 238, 0); + -moz-box-shadow: 0 0 5px rgba(81, 203, 238, 0); +} + +textarea#styleid:focus{ + color:#000; + outline:none; + border:#35a5e5 1px solid; + font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif; + box-shadow: 0 0 5px rgba(81, 203, 238, 1); + -webkit-box-shadow: 0 0 5px rgba(81, 203, 238, 1); + -moz-box-shadow: 0 0 5px rgba(81, 203, 238, 1); +} \ No newline at end of file diff --git a/codeigniter/js/myjavascript.js b/codeigniter/js/myjavascript.js new file mode 100644 index 0000000..ef5da59 --- /dev/null +++ b/codeigniter/js/myjavascript.js @@ -0,0 +1,101 @@ +// JavaScript Document +function appendAtEnd(data,numberOfPosts){ + var arrayDiv = new Array(); //to hold div element + + var length = ; + var increment = length * (parseInt(data[0][2]) - 2); + for(var k = 0; k < numberOfPosts; k++){ + var dText="

" + data[k+1][0]+""+data[k+1][2]+"

"+data[k+1][1]+"

"; + var br = document.createElement('br'); + arrayDiv[increment] = document.createElement('div'); + arrayDiv[increment].id = 'statusDisplayID' + increment; + arrayDiv[increment].className = 'statusDisplayClass'; + statusByAjaxID.appendChild(arrayDiv[increment]); + statusByAjaxID.appendChild(br); + document.getElementById("statusDisplayID" + increment).innerHTML = dText; + increment++; + } + return true; +} + +function getData(rawData,numberOfPosts){ + var arraySeparated = new Array(); + var data = new Array(); + + var tableColumn = ["username","posts","time_of_post"]; //only in case if the table contains any other columns + var numCol = tableColumn.length; + + for(var i = 0; i <= numberOfPosts + 1; i++){ + arraySeparated[i] = rawData.split("Array")[i].split("=>"); //a 2-dimensional dirty but yet useful array + } + + for(var i = 0;i <3; i++){ //loop=3 because index=1 of arraySeparated contains LOGGED_IN_USER,TOTAL_DISPLAYING,PAGE + data[i] = arraySeparated[1][i + 1].substring(1,arraySeparated[1][i + 1].indexOf("\n")); + } + for(var j = 2; j <= numberOfPosts+1; j++){ //index 2 to numberOfPosts+1 contains all the posts fetched in one time + for(var k = 1; k <= numCol; k++){ + data[i] = arraySeparated[j][k].substring(1,arraySeparated[j][k].indexOf("\n")); + i++; + } + } + data[i] = arraySeparated[j-1][k].substring(1,arraySeparated[j-1][k].indexOf("\n")); //the last index contains message + + //objectification of the data + var post = new Array(); + + post[0] = new Array(); + for(var j=0; j < 3;j++){ + post[0][j] = data[j]; + } + for(var i = 1;i <= numberOfPosts; i++){ + post[i] = new Array(); + for(var k=0; k < numCol; k++){ + post[i][k] = data[j]; + j++; + } + } + post[i] = new Array(); + post[i][0] = data[j]; + + return post; +} + +function ajaxPegination(str) { + if (str=="") { + document.getElementById("statusDisplayID").innerHTML=""; + return; + } + if (window.XMLHttpRequest) { + // code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } else { // code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + var rawData = xmlhttp.responseText; + + var numberOfPosts = rawData.split("Array").length-2; //number of posts is 2 lesser + + var data = new Array(); //converting string type responseText into array + var data = getData(rawData,numberOfPosts); + + var page = parseInt(data[0][2]) + 1; //to fetch next particular size of data from database + var message = data[numberOfPosts + 1][0]; //this checks if last entry has reached by MAX_VIEW_REACHED + + document.getElementById("see_moreID").href = "javascript:ajaxPegination(" + page + ")"; //pegination link + + document.getElementById("msgID").innerHTML = message; //message + + if(message == "MAX_VIEW_REACHED"){ //if max view reached pegination link changes + document.getElementById("see_moreID").href = ""; + document.getElementById("see_moreID").innerHTML = "recent only..."; + } + + appendAtEnd(data,numberOfPosts); //to append the posts at the end + //console.log(data); + } + } + xmlhttp.open("GET",""+str,true); + xmlhttp.send(); +} \ No newline at end of file From fff7bb40c99142e93c0bc2534ae32c6feabe11da Mon Sep 17 00:00:00 2001 From: Satish Jaiswal Date: Fri, 2 May 2014 10:56:16 +0900 Subject: [PATCH 07/12] empty posts addressed --- codeigniter/application/config/constants.php | 2 +- codeigniter/application/controllers/room.php | 1 - codeigniter/application/views/roomView.php | 16 +++++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/codeigniter/application/config/constants.php b/codeigniter/application/config/constants.php index 32c3b3d..5628995 100644 --- a/codeigniter/application/config/constants.php +++ b/codeigniter/application/config/constants.php @@ -1,7 +1,7 @@ showPosts("1"); - if($posts){ //if result exists send the result to room for display $this->load->view('roomView',$posts); } diff --git a/codeigniter/application/views/roomView.php b/codeigniter/application/views/roomView.php index cb41aa1..743b60e 100644 --- a/codeigniter/application/views/roomView.php +++ b/codeigniter/application/views/roomView.php @@ -159,7 +159,16 @@ function postStatusByAjax(){
- +session->userdata('logged_in'); + echo($session_data['username']); +} + +?> Logout
@@ -186,6 +195,7 @@ function postStatusByAjax(){
"); echo("

". @@ -197,6 +207,10 @@ function postStatusByAjax(){ echo("

".${'di'.$i}['posts']."

"); echo("
"); } +} +else{ + echo("No posts entered!"); +} ?>
From 9e482991d4848f9c9975841de26087fa9815f06d Mon Sep 17 00:00:00 2001 From: Satish Jaiswal Date: Fri, 2 May 2014 10:59:45 +0900 Subject: [PATCH 08/12] empty posts addressed2 --- codeigniter/application/views/roomView.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/codeigniter/application/views/roomView.php b/codeigniter/application/views/roomView.php index 743b60e..c73b9af 100644 --- a/codeigniter/application/views/roomView.php +++ b/codeigniter/application/views/roomView.php @@ -220,7 +220,13 @@ function postStatusByAjax(){
-see more..");?> +see more.."); +}else { + echo(" "); +} +?>

From 81c41bc0601fe50442d36bf15456e0680517e477 Mon Sep 17 00:00:00 2001 From: Satish Jaiswal Date: Fri, 2 May 2014 15:42:06 +0900 Subject: [PATCH 09/12] writing neat codes1 --- codeigniter/application/config/constants.php | 3 +- codeigniter/application/controllers/login.php | 44 ++++++--------- .../application/controllers/register.php | 41 ++++++++++---- codeigniter/application/models/posts.php | 49 +++++++++++++++++ codeigniter/application/models/users.php | 55 +++++++++++++++++++ codeigniter/application/views/loginView.php | 2 +- .../application/views/registerView.php | 11 ++-- codeigniter/application/views/roomView.php | 24 +------- codeigniter/css/mystyle.css | 12 ++++ 9 files changed, 175 insertions(+), 66 deletions(-) create mode 100644 codeigniter/application/models/posts.php create mode 100644 codeigniter/application/models/users.php diff --git a/codeigniter/application/config/constants.php b/codeigniter/application/config/constants.php index 5628995..11e0ec1 100644 --- a/codeigniter/application/config/constants.php +++ b/codeigniter/application/config/constants.php @@ -3,9 +3,10 @@ define('DEFAULT_STATUS',"express yourself"); define('LENGTH',2); define('LOGIN_FAILED',"Username or password is incorrect."); -define('USER_EXISTS',"This email has already been registered."); +define('USER_EXISTS'," has already been registered. Please try with new email."); define('REGISTRATION_SUCCESSFUL',"You have been registered. Please login."); define('REGISTRATION_FAILED',"Registration failed due to some unknown reasons."); +define('NO_MESSAGE'," "); /* |-------------------------------------------------------------------------- | File and Directory Modes diff --git a/codeigniter/application/controllers/login.php b/codeigniter/application/controllers/login.php index 83b9123..f6235e7 100644 --- a/codeigniter/application/controllers/login.php +++ b/codeigniter/application/controllers/login.php @@ -17,43 +17,35 @@ private function before() { } public function index(){ - $data['message'] = "NOT_SET"; + $data['message'] = NO_MESSAGE; $this->load->view('loginView',$data); } - public function verifyLogin(){ + private function verifyLogin(){ $this->load->helper('form'); - $this->load->library('form_validation','url'); - $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 + if ($this->form_validation->run() == FALSE) { //if form validation fails, redirect to login page with message $data['message'] = LOGIN_FAILED; - $this->load->view('loginView',$data); - } - else{ //if form validation passes, get data and check database + 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 + } - $this->load->model('DBFunctions'); - - $result=$this->DBFunctions->authenticate($email,$password); //the authenticate function is in model:DBFunctions - - if($result){ //if user exists create session and redirect to room - $sess_array = array(); - - foreach($result as $row){ - $sess_array = array('userID' => $row->userID,'username' => $row->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); - } - } + 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); + } } } diff --git a/codeigniter/application/controllers/register.php b/codeigniter/application/controllers/register.php index e45e6e3..9063cb6 100644 --- a/codeigniter/application/controllers/register.php +++ b/codeigniter/application/controllers/register.php @@ -17,30 +17,31 @@ private function before() { } public function index(){ - $data['message'] = "NOT_SET"; + $data['message'] = NO_MESSAGE; $this->load->view('registerView',$data); } - public function verifyRegister(){ + private function verifyRegister(){ $this->load->helper('form'); $this->load->library('form_validation','url'); $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean'); - $this->form_validation->set_rules('email', 'Email', 'trim|xss_clean|required|valid_email'); + $this->form_validation->set_rules('email', 'Email', 'trim|xss_clean|required|valid_email|callback_userExists'); $this->form_validation->set_rules('password', 'Password', 'trim|xss_clean|required'); if ($this->form_validation->run() == FALSE){ // if form validation fails, get form errors and set messages, redirect to register $data['message'] = "VALIDATION_ERRORS"; $this->load->view('registerView',$data); //if validation fails load the registrationForm - } - else{ //if form validation passes, get data,check duplicate,do redirects - $username = htmlspecialchars($_POST['username']); + } else { //if form validation passes, get data,check duplicate,do redirects + + redirect('room','refresh'); + /*$username = htmlspecialchars($_POST['username']); $email = htmlspecialchars($_POST['email']); $password =sha1(htmlspecialchars($_POST['password'])); - $this->load->model('DBFunctions'); + $this->load->model('posts'); $isUserExists = $this->DBFunctions->userExists($email); //check if user exists @@ -59,7 +60,27 @@ public function verifyRegister(){ $data['message']=REGISTRATION_FAILED; $this->load->view('registerView',$data); //if registration failed load the registerForm } - } - } - } + }*/ + } + } + + public function userExists($email){ + $this->load->model('users'); + if($this->users->userExists($email)){ //if userExists then validation is false + $this->form_validation->set_message('userExists', ''.$email.''. USER_EXISTS); + return false; + } + $username = htmlspecialchars($_POST['username']); + $password =sha1(htmlspecialchars($_POST['password'])); + if($this->users->register($username,$email,$password)){ + $sess_array = array(); + $sess_array = array('userid' => $singleRowResult['userid'],'username' => $singleRowResult['username']); + $this->session->set_userdata('logged_in', $sess_array); + return true; + } + else{ + $this->form_validation->set_message('userExists' , REGISTRATION_FAILED); + return false; + } + } } \ No newline at end of file diff --git a/codeigniter/application/models/posts.php b/codeigniter/application/models/posts.php new file mode 100644 index 0000000..eb644ca --- /dev/null +++ b/codeigniter/application/models/posts.php @@ -0,0 +1,49 @@ +db->select('username,posts,time_of_post'); + $this->db->from('posts'); + $this->db->order_by('time_of_post','DESC'); + $this->db->limit(LENGTH,LENGTH*($page - 1)); + + $query = $this->db->get(); + + if($query->num_rows()>0){ + if($query->num_rowsresult_array(); + $data['message'] = "MAX_VIEW_REACHED"; + } + else{ + $data = $query->result_array(); //when MAX_VIEW_NOT_REACHED message is not set + } + return $data; + } + else{ + return false; + } + } + + public function post($username,$posts,$date){ + $this->db->set('username',$username); + $this->db->set('posts',$posts); + $this->db->set('time_of_post',$date); + + $this->db->insert('posts'); + + if($this->db->affected_rows() == 1){ + return true; + } + else{ + return false; + } + } + +} +?> \ No newline at end of file diff --git a/codeigniter/application/models/users.php b/codeigniter/application/models/users.php new file mode 100644 index 0000000..5186437 --- /dev/null +++ b/codeigniter/application/models/users.php @@ -0,0 +1,55 @@ + db -> select('userid, username,email, password'); + $this -> db -> from('users'); + $this -> db -> where('email', $email); + $this -> db -> where('password', $password); + + $query = $this -> db -> get(); + + if($query -> num_rows() == 1){ + return $query->row_array(); + } + else{ + return false; + } + } + + public function userExists($email){ + $this->db->select('email'); + $this->db->from('users'); + $this->db->where('email',$email); + + $query = $this->db->get(); + + if($query->num_rows == 1){ + return true; + } + else{ + return false; + } + } + + public function register($username,$email,$password){ + $this->db->set('username',$username); + $this->db->set('email',$email); + $this->db->set('password',$password); + + $this->db->insert('users'); + + if($this->db->affected_rows() == 1){ + return true; + }else{ + return false; + } + } +} +?> \ No newline at end of file diff --git a/codeigniter/application/views/loginView.php b/codeigniter/application/views/loginView.php index d944b69..3cfa396 100644 --- a/codeigniter/application/views/loginView.php +++ b/codeigniter/application/views/loginView.php @@ -20,7 +20,7 @@ function loginform(){
-
"> +
">
diff --git a/codeigniter/application/views/registerView.php b/codeigniter/application/views/registerView.php index a4dfd8a..63f8a84 100644 --- a/codeigniter/application/views/registerView.php +++ b/codeigniter/application/views/registerView.php @@ -18,18 +18,17 @@ function registerform(){
-
"> +
"> load->helper('form'); -//set the error delimiters, the default one add

- -if(isset($message)&&$message != "VALIDATION_ERRORS"){ - +if(isset($message) && $message != "VALIDATION_ERRORS"){ echo($message); } -echo validation_errors(); +if(validation_errors()){ + echo validation_errors(); +} ?>
diff --git a/codeigniter/application/views/roomView.php b/codeigniter/application/views/roomView.php index c73b9af..cb41aa1 100644 --- a/codeigniter/application/views/roomView.php +++ b/codeigniter/application/views/roomView.php @@ -159,16 +159,7 @@ function postStatusByAjax(){
-session->userdata('logged_in'); - echo($session_data['username']); -} - -?> + Logout
@@ -195,7 +186,6 @@ function postStatusByAjax(){
"); echo("

". @@ -207,10 +197,6 @@ function postStatusByAjax(){ echo("

".${'di'.$i}['posts']."

"); echo("
"); } -} -else{ - echo("No posts entered!"); -} ?>
@@ -220,13 +206,7 @@ function postStatusByAjax(){
-see more.."); -}else { - echo(" "); -} -?> +see more..");?>

diff --git a/codeigniter/css/mystyle.css b/codeigniter/css/mystyle.css index 0b04174..ee6d47e 100644 --- a/codeigniter/css/mystyle.css +++ b/codeigniter/css/mystyle.css @@ -412,6 +412,18 @@ body{ padding-top:0px; } +#NoPostID{ + background:#FFFFFF; + width:53.4%; + position:relative; + left:22%; + border:1px #E5E5E5 solid; + padding-bottom:0px; + padding-left:10px; + padding-right:10px; + padding-top:0px; +} + #statusByAjaxID{ } From 326bd3198b8dc1aacb74ed62cc186abf7103c6d1 Mon Sep 17 00:00:00 2001 From: Satish Jaiswal Date: Tue, 6 May 2014 21:42:36 +0900 Subject: [PATCH 10/12] algorithm changed --- codeigniter/application/config/autoload.php | 4 +- codeigniter/application/config/constants.php | 3 - codeigniter/application/controllers/login.php | 7 +- .../application/controllers/register.php | 76 ++----- codeigniter/application/controllers/room.php | 64 +++--- .../application/controllers/room_1.php | 100 +++++++++ codeigniter/application/models/posts.php | 22 +- codeigniter/application/models/users.php | 15 -- codeigniter/application/views/loginView.php | 20 +- .../application/views/registerView.php | 37 +--- codeigniter/application/views/roomView.php | 197 +++++++----------- codeigniter/css/mystyle.css | 30 ++- 12 files changed, 272 insertions(+), 303 deletions(-) create mode 100644 codeigniter/application/controllers/room_1.php diff --git a/codeigniter/application/config/autoload.php b/codeigniter/application/config/autoload.php index 5c9deaf..a5768a2 100644 --- a/codeigniter/application/config/autoload.php +++ b/codeigniter/application/config/autoload.php @@ -52,7 +52,7 @@ | $autoload['libraries'] = array('database', 'session', 'xmlrpc'); */ -$autoload['libraries'] = array('database','session'); +$autoload['libraries'] = array('database','session','form_validation'); /* @@ -64,7 +64,7 @@ | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array('url'); +$autoload['helper'] = array('url','form'); /* diff --git a/codeigniter/application/config/constants.php b/codeigniter/application/config/constants.php index 11e0ec1..7b0fb45 100644 --- a/codeigniter/application/config/constants.php +++ b/codeigniter/application/config/constants.php @@ -3,9 +3,6 @@ define('DEFAULT_STATUS',"express yourself"); define('LENGTH',2); define('LOGIN_FAILED',"Username or password is incorrect."); -define('USER_EXISTS'," has already been registered. Please try with new email."); -define('REGISTRATION_SUCCESSFUL',"You have been registered. Please login."); -define('REGISTRATION_FAILED',"Registration failed due to some unknown reasons."); define('NO_MESSAGE'," "); /* |-------------------------------------------------------------------------- diff --git a/codeigniter/application/controllers/login.php b/codeigniter/application/controllers/login.php index f6235e7..d7d80f5 100644 --- a/codeigniter/application/controllers/login.php +++ b/codeigniter/application/controllers/login.php @@ -22,8 +22,6 @@ public function index(){ } private function verifyLogin(){ - $this->load->helper('form'); - $this->load->library('form_validation','url'); $this->form_validation->set_rules('username', 'Username', 'trim|xss_clean'); $this->form_validation->set_rules('password', 'Password', 'trim|xss_clean'); @@ -37,13 +35,12 @@ private function verifyLogin(){ $singleRowResult=$this->users->authenticate($email,$password); //the authenticate function is in model:users } - if($singleRowResult){ //if user exists create session and redirect to room + 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 + } else { // if user does not exist, redirect to login page with message $data['message'] = LOGIN_FAILED; $this->load->view('loginView',$data); } diff --git a/codeigniter/application/controllers/register.php b/codeigniter/application/controllers/register.php index 9063cb6..023c9b1 100644 --- a/codeigniter/application/controllers/register.php +++ b/codeigniter/application/controllers/register.php @@ -17,70 +17,32 @@ private function before() { } public function index(){ - $data['message'] = NO_MESSAGE; - $this->load->view('registerView',$data); + $this->load->view('registerView'); } private function verifyRegister(){ - $this->load->helper('form'); - - $this->load->library('form_validation','url'); - $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean'); - $this->form_validation->set_rules('email', 'Email', 'trim|xss_clean|required|valid_email|callback_userExists'); + $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'); - - if ($this->form_validation->run() == FALSE){ // if form validation fails, get form errors and set messages, redirect to register - $data['message'] = "VALIDATION_ERRORS"; - $this->load->view('registerView',$data); //if validation fails load the registrationForm - - } else { //if form validation passes, get data,check duplicate,do redirects - - redirect('room','refresh'); - /*$username = htmlspecialchars($_POST['username']); - $email = htmlspecialchars($_POST['email']); + $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'])); - - $this->load->model('posts'); - - $isUserExists = $this->DBFunctions->userExists($email); //check if user exists - - if($isUserExists){ // if exists ask for new username and send to register - $data['message'] = USER_EXISTS; - $this->load->view('registerView',$data); + $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!"); } - else{ // if doesnot exis, create this user - $isEnteredIntoDatabase = $this->DBFunctions->register($username,$email,$password); // entering data into database - - if($isEnteredIntoDatabase){ - $data['message']=REGISTRATION_SUCCESSFUL; - $this->load->view('loginView',$data); //if registration successful load the loginForm - } - else{ - $data['message']=REGISTRATION_FAILED; - $this->load->view('registerView',$data); //if registration failed load the registerForm - } - }*/ - } - } - - public function userExists($email){ - $this->load->model('users'); - if($this->users->userExists($email)){ //if userExists then validation is false - $this->form_validation->set_message('userExists', ''.$email.''. USER_EXISTS); - return false; - } - $username = htmlspecialchars($_POST['username']); - $password =sha1(htmlspecialchars($_POST['password'])); - if($this->users->register($username,$email,$password)){ - $sess_array = array(); - $sess_array = array('userid' => $singleRowResult['userid'],'username' => $singleRowResult['username']); - $this->session->set_userdata('logged_in', $sess_array); - return true; - } - else{ - $this->form_validation->set_message('userExists' , REGISTRATION_FAILED); - return false; } } } \ No newline at end of file diff --git a/codeigniter/application/controllers/room.php b/codeigniter/application/controllers/room.php index 661bcb9..d07fc4b 100644 --- a/codeigniter/application/controllers/room.php +++ b/codeigniter/application/controllers/room.php @@ -1,7 +1,5 @@ showPosts("1"); if($posts){ //if result exists send the result to room for display - $this->load->view('roomView',$posts); + $data['jsonObject'] = $posts; + $this->load->view('roomView',$data); } else{ $data['message'] = "NO_POSTS_YET"; @@ -35,64 +33,52 @@ public function index(){ 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('DBFunctions'); - $postsFormDB = $this->DBFunctions->getPosts($page); + $this->load->model('posts'); + $postsFromDB = $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{ + if ($postsFromDB) { + return json_encode($postsFromDB); + } else { return false; } } - public function ajax($param){ + public function ajaxDisplay($param){ $posts = $this->showPosts($param); if($posts){ - print_r($posts); //returns the array to ajax responseText + print_r($posts); //returns the JSON Object Array to ajax responseText } else{ - echo("NO!"); + echo("[{\"message\":\"OUT_OF_INDEX\"}]"); } } public function ajaxPost(){ - if(isset($_POST['username'])&&isset($_POST['status'])){ - $username = $_POST['username']; + $session_data = $this->session->userdata('logged_in'); + if(isset($_POST['status'])){ + $userid = $session_data['userid']; + $username = $session_data['username']; $posts = $_POST['status']; - $date = date("Y-m-d H:i:s"); + $time_of_post = date("Y-m-d H:i:s"); - $this->load->model('DBFunctions'); - $insertPost = $this->DBFunctions->post($username,$posts,$date); + $this->load->model('posts'); + $insertPost = $this->posts->post($userid,$username,$posts,$time_of_post); + } else { + echo("VARIABLES_NOT_SET_IN_AJAXPOST"); + } - if($insertPost){ - echo($date); - } - else{ - echo("false"); - } + if($insertPost){ + echo($time_of_post); } else{ - echo("VARIABLES_NOT_SET"); + echo("POST_NOT_INSERTED"); } } public function logout(){ $this->session->unset_userdata('logged_in'); - session_destroy(); + $this->session->sess_destroy(); redirect('login', 'refresh'); } } diff --git a/codeigniter/application/controllers/room_1.php b/codeigniter/application/controllers/room_1.php new file mode 100644 index 0000000..97fdb6d --- /dev/null +++ b/codeigniter/application/controllers/room_1.php @@ -0,0 +1,100 @@ +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'); + } +} + +?> diff --git a/codeigniter/application/models/posts.php b/codeigniter/application/models/posts.php index eb644ca..7c85038 100644 --- a/codeigniter/application/models/posts.php +++ b/codeigniter/application/models/posts.php @@ -8,32 +8,28 @@ function __construct() } public function getPosts($page){ + $session_data = $this->session->userdata('logged_in'); + $userid = $session_data['userid']; $this->db->select('username,posts,time_of_post'); $this->db->from('posts'); + $this->db->where('userid',$userid); $this->db->order_by('time_of_post','DESC'); $this->db->limit(LENGTH,LENGTH*($page - 1)); $query = $this->db->get(); - if($query->num_rows()>0){ - if($query->num_rowsresult_array(); - $data['message'] = "MAX_VIEW_REACHED"; - } - else{ - $data = $query->result_array(); //when MAX_VIEW_NOT_REACHED message is not set - } - return $data; - } - else{ + if ($query->num_rows()>0) { + return $query->result_array(); + } else { return false; } } - public function post($username,$posts,$date){ + public function post($userid,$username,$posts,$time_of_post){ + $this->db->set('userid',$userid); $this->db->set('username',$username); $this->db->set('posts',$posts); - $this->db->set('time_of_post',$date); + $this->db->set('time_of_post',$time_of_post); $this->db->insert('posts'); diff --git a/codeigniter/application/models/users.php b/codeigniter/application/models/users.php index 5186437..c12bceb 100644 --- a/codeigniter/application/models/users.php +++ b/codeigniter/application/models/users.php @@ -23,21 +23,6 @@ public function authenticate($email,$password){ } } - public function userExists($email){ - $this->db->select('email'); - $this->db->from('users'); - $this->db->where('email',$email); - - $query = $this->db->get(); - - if($query->num_rows == 1){ - return true; - } - else{ - return false; - } - } - public function register($username,$email,$password){ $this->db->set('username',$username); $this->db->set('email',$email); diff --git a/codeigniter/application/views/loginView.php b/codeigniter/application/views/loginView.php index 3cfa396..00fe022 100644 --- a/codeigniter/application/views/loginView.php +++ b/codeigniter/application/views/loginView.php @@ -28,25 +28,11 @@ function loginform(){
load->helper('form'); - -//open the form tab and set action to validate function of the login class -echo form_open('login/verifyLogin',array('name' => 'loginForm')); - -//set the label for the email +echo form_open('login/verifyLogin',array('name' => 'loginForm')); echo form_label('Email', 'loginemailID', array( 'id' => 'loginlabelEmailID')); - -//text input type for usename -echo form_input(array('name' => 'email','id' => 'loginemailID')); - -//set the label for the password +echo form_input(array('name'=> 'email','id'=> 'loginemailID')); echo form_label('Password', 'loginpasswordID', array( 'id' => 'loginlabelPassID')); - -//text input type for usename -echo form_password(array('name' => 'password','id' => 'loginpasswordID')); - -//close the form +echo form_password(array('name'=> 'password','id'=> 'loginpasswordID')); echo form_close(); ?> diff --git a/codeigniter/application/views/registerView.php b/codeigniter/application/views/registerView.php index 63f8a84..0864592 100644 --- a/codeigniter/application/views/registerView.php +++ b/codeigniter/application/views/registerView.php @@ -18,46 +18,23 @@ function registerform(){
-
"> -load->helper('form'); - -if(isset($message) && $message != "VALIDATION_ERRORS"){ - echo($message); -} -if(validation_errors()){ - echo validation_errors(); -} -?> +
"> +
'registerForm')); - -//set the label for the usename echo form_label('Username', 'usernameID', array( 'id' => 'labelUserID')); - -//text input type for usename -echo form_input(array('name' => 'username','id' => 'usernameID')); - -//set the label for the usename +echo form_input(array('name'=> 'username','id' => 'usernameID','value'=>set_value('username'))); echo form_label('Email', 'emailID', array( 'id' => 'labelEmailID')); - -//text input type for usename -echo form_input(array('name' => 'email','id' => 'emailID')); - -//set the label for the password +echo form_input(array('name'=> 'email','id'=> 'emailID','value'=>set_value('email'))); echo form_label('Password', 'passwordID', array( 'id' => 'labelPassID')); - -//text input type for usename -echo form_password(array('name' => 'password','id' => 'passwordID')); - -//close the form +echo form_password(array('name'=> 'password','id'=> 'passwordID','value'=>set_value('password'))); +echo form_label('Confirm Password', 'confirmPasswordID', array( 'id' => 'labelConfirmPassID')); +echo form_password(array('name'=> 'confirmPassword','id'=> 'confirmPasswordID','value'=>set_value('confirmPassword'))); echo form_close(); ?> diff --git a/codeigniter/application/views/roomView.php b/codeigniter/application/views/roomView.php index cb41aa1..261c46e 100644 --- a/codeigniter/application/views/roomView.php +++ b/codeigniter/application/views/roomView.php @@ -1,3 +1,4 @@ +session->userdata('logged_in');?> @@ -7,13 +8,34 @@
- + Logout
@@ -170,12 +125,13 @@ function postStatusByAjax(){
-
+load->helper('form'); +echo form_open('room/post',array('name' => 'statusInputForm')); +?> - - -
+

@@ -186,27 +142,32 @@ function postStatusByAjax(){
"); - echo("

". - ${'di'.$i}['username']. - "". - ${'di'.$i}['time_of_post'] - - ."

"); - echo("

".${'di'.$i}['posts']."

"); - echo("
"); +if(isset($message) && $message == "NO_POSTS_YET"){ + echo("
"); + echo("

".$message."

"); +} +else{ + $data = json_decode($jsonObject); + for($i = 0; $i < LENGTH; $i++){ + if(isset($data[$i]->username)){ + echo("
"); + echo("

".$data[$i]->username."".$data[$i]->time_of_post."

"); + echo("

".$data[$i]->posts."

"); + echo("
"); + } + } } ?>
- +

-see more..");?> +see more..");?> +

diff --git a/codeigniter/css/mystyle.css b/codeigniter/css/mystyle.css index ee6d47e..80041f0 100644 --- a/codeigniter/css/mystyle.css +++ b/codeigniter/css/mystyle.css @@ -168,7 +168,7 @@ body{ #registerFormID{ background:#F5F5F5; width:300px; - height:300px; + height:360px; position:relative; left:36%; border:1px #E5E5E5 solid; @@ -243,12 +243,34 @@ body{ font-weight:bold; } +/* ----------------------------------------------REGISTER CONFIRM PASSWORD CSS------------------------------------------- */ + +#confirmPasswordID{ + position:absolute; + border:2px #B40313 solid; + left: 89px; + top: 238px; + width: 160px; + padding:5px 5px 5px 5px; +} + +#labelConfirmPassID{ + position:absolute; + left: 90px; + top: 210px; + padding:5px 5px 5px 5px; + font-family:Arial, Helvetica, sans-serif; + font-size:smaller; + color:#B40313; + font-weight:bold; +} + /* ----------------------------------------------REGISTER LOGIN BUTTON CSS------------------------------------------- */ #loginbuttonID a{ position:absolute; left: 105px; - top: 218px; + top: 285px; width: 50px; height: 20px; text-align:center; @@ -272,7 +294,7 @@ body{ #registerbuttonID a{ position:absolute; left: 177px; - top: 217px; + top: 285px; width: 50px; height: 20px; text-align:center; @@ -296,7 +318,7 @@ body{ #forgotpassID a{ position:absolute; left: 119px; - top: 256px; + top: 320px; font-family:Georgia, "Times New Roman", Times, serif; font-size:smaller; color:#B40313; From 30ce41c07ae0c7901445bb5abdfded57567dccf2 Mon Sep 17 00:00:00 2001 From: Satish Jaiswal Date: Fri, 9 May 2014 11:03:57 +0900 Subject: [PATCH 11/12] coding standard left --- codeigniter/application/controllers/room.php | 5 +- codeigniter/application/views/loginView.php | 19 +- .../application/views/registerView.php | 16 +- codeigniter/application/views/roomView.php | 202 +++++++++--------- codeigniter/codeigniter.sql | 54 +++++ codeigniter/css/mystyle.css | 2 +- 6 files changed, 181 insertions(+), 117 deletions(-) create mode 100644 codeigniter/codeigniter.sql diff --git a/codeigniter/application/controllers/room.php b/codeigniter/application/controllers/room.php index d07fc4b..17ce436 100644 --- a/codeigniter/application/controllers/room.php +++ b/codeigniter/application/controllers/room.php @@ -44,8 +44,9 @@ public function showPosts($parameter){ } } - public function ajaxDisplay($param){ - $posts = $this->showPosts($param); + public function ajaxDisplay(){ + $page = $_POST['page']; + $posts = $this->showPosts($page); if($posts){ print_r($posts); //returns the JSON Object Array to ajax responseText } diff --git a/codeigniter/application/views/loginView.php b/codeigniter/application/views/loginView.php index 00fe022..6649420 100644 --- a/codeigniter/application/views/loginView.php +++ b/codeigniter/application/views/loginView.php @@ -6,13 +6,16 @@ - - + + @@ -28,14 +31,14 @@ function loginform(){
'loginForm')); +echo form_open('login/verifyLogin',array('name' => 'loginForm','id'=>'loginFID')); echo form_label('Email', 'loginemailID', array( 'id' => 'loginlabelEmailID')); echo form_input(array('name'=> 'email','id'=> 'loginemailID')); echo form_label('Password', 'loginpasswordID', array( 'id' => 'loginlabelPassID')); echo form_password(array('name'=> 'password','id'=> 'loginpasswordID')); echo form_close(); ?> - +
diff --git a/codeigniter/application/views/registerView.php b/codeigniter/application/views/registerView.php index 0864592..14a7d35 100644 --- a/codeigniter/application/views/registerView.php +++ b/codeigniter/application/views/registerView.php @@ -6,11 +6,15 @@ - + @@ -26,7 +30,7 @@ function registerform(){
'registerForm')); +echo form_open('register/verifyRegister',array('name' => 'registerForm','id'=>'registerFID')); echo form_label('Username', 'usernameID', array( 'id' => 'labelUserID')); echo form_input(array('name'=> 'username','id' => 'usernameID','value'=>set_value('username'))); echo form_label('Email', 'emailID', array( 'id' => 'labelEmailID')); @@ -38,7 +42,7 @@ function registerform(){ echo form_close(); ?> - +
diff --git a/codeigniter/application/views/roomView.php b/codeigniter/application/views/roomView.php index 261c46e..fe74d49 100644 --- a/codeigniter/application/views/roomView.php +++ b/codeigniter/application/views/roomView.php @@ -7,112 +7,110 @@ - + -
Logout @@ -129,21 +127,25 @@ function makeItBlank(){ $this->load->helper('form'); echo form_open('room/post',array('name' => 'statusInputForm')); ?> - +

- +
-
- +
"); + echo(""); + echo("
"); echo("

".$message."

"); } else{ @@ -166,7 +168,7 @@ function makeItBlank(){
-see more..");?> +see more..");?>

diff --git a/codeigniter/codeigniter.sql b/codeigniter/codeigniter.sql new file mode 100644 index 0000000..dbfff36 --- /dev/null +++ b/codeigniter/codeigniter.sql @@ -0,0 +1,54 @@ +-- phpMyAdmin SQL Dump +-- version 4.1.14 +-- http://www.phpmyadmin.net +-- +-- Host: localhost +-- Generation Time: May 08, 2014 at 12:56 AM +-- Server version: 5.5.37-log +-- PHP Version: 5.4.27 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Database: `codeigniter` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `posts` +-- + +CREATE TABLE IF NOT EXISTS `posts` ( + `postid` int(11) NOT NULL AUTO_INCREMENT, + `userid` varchar(50) NOT NULL, + `username` varchar(50) NOT NULL, + `posts` text NOT NULL, + `time_of_post` datetime NOT NULL, + PRIMARY KEY (`postid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `users` +-- + +CREATE TABLE IF NOT EXISTS `users` ( + `userid` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(50) NOT NULL, + `email` varchar(50) NOT NULL, + `password` varchar(50) NOT NULL, + PRIMARY KEY (`userid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/codeigniter/css/mystyle.css b/codeigniter/css/mystyle.css index 80041f0..2c14d0e 100644 --- a/codeigniter/css/mystyle.css +++ b/codeigniter/css/mystyle.css @@ -493,7 +493,7 @@ textarea#textAreaID{ resize:none; color:#666; font-size:14px; - -moz-border-radius: 8px; -webkit-border-radius: 8px; + -moz-border-radius: 0px; -webkit-border-radius: 0px; margin:5px 0px 10px 0px; padding:10px; height:70px; From 6780f3a7f41fb66204b48f72577399572e419d8f Mon Sep 17 00:00:00 2001 From: Satish Jaiswal Date: Fri, 9 May 2014 12:17:28 +0900 Subject: [PATCH 12/12] code standard left --- codeigniter/application/controllers/room.php | 21 +++++++++++++----- codeigniter/application/models/posts.php | 23 ++++++++++++++++++-- codeigniter/application/views/roomView.php | 18 ++++++++++----- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/codeigniter/application/controllers/room.php b/codeigniter/application/controllers/room.php index 17ce436..d6354c1 100644 --- a/codeigniter/application/controllers/room.php +++ b/codeigniter/application/controllers/room.php @@ -20,7 +20,7 @@ private function before() { } public function index(){ - $posts = $this->showPosts("1"); + $posts = $this->showInitialPosts(); if($posts){ //if result exists send the result to room for display $data['jsonObject'] = $posts; $this->load->view('roomView',$data); @@ -31,11 +31,22 @@ public function index(){ } } + public function showInitialPosts(){ + $this->load->model('posts'); + $postsFromDB = $this->posts->getInitialPosts(); + + if ($postsFromDB) { + return json_encode($postsFromDB); + } else { + return false; + } + } + public function showPosts($parameter){ - $page = (int) $parameter; //type casting the parameter to integer will cause page to be 0 is it contains alphabets + $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($page); + $postsFromDB = $this->posts->getPosts($postid); if ($postsFromDB) { return json_encode($postsFromDB); @@ -45,8 +56,8 @@ public function showPosts($parameter){ } public function ajaxDisplay(){ - $page = $_POST['page']; - $posts = $this->showPosts($page); + $postid = $_POST['postid']; + $posts = $this->showPosts($postid); if($posts){ print_r($posts); //returns the JSON Object Array to ajax responseText } diff --git a/codeigniter/application/models/posts.php b/codeigniter/application/models/posts.php index 7c85038..9dbe08d 100644 --- a/codeigniter/application/models/posts.php +++ b/codeigniter/application/models/posts.php @@ -7,14 +7,33 @@ function __construct() parent::__construct(); } + public function getInitialPosts(){ + $session_data = $this->session->userdata('logged_in'); + $userid = $session_data['userid']; + $this->db->select('postid,username,posts,time_of_post'); + $this->db->from('posts'); + $this->db->where('userid',$userid); + $this->db->order_by('time_of_post','DESC'); + $this->db->limit(LENGTH); + + $query = $this->db->get(); + + if ($query->num_rows()>0) { + return $query->result_array(); + } else { + return false; + } + } + public function getPosts($page){ $session_data = $this->session->userdata('logged_in'); $userid = $session_data['userid']; - $this->db->select('username,posts,time_of_post'); + $this->db->select('postid,username,posts,time_of_post'); $this->db->from('posts'); $this->db->where('userid',$userid); + $this->db->where('postid <',$page); $this->db->order_by('time_of_post','DESC'); - $this->db->limit(LENGTH,LENGTH*($page - 1)); + $this->db->limit(LENGTH); $query = $this->db->get(); diff --git a/codeigniter/application/views/roomView.php b/codeigniter/application/views/roomView.php index fe74d49..f41563b 100644 --- a/codeigniter/application/views/roomView.php +++ b/codeigniter/application/views/roomView.php @@ -45,18 +45,20 @@ type: "POST", dataType: "text", url: "room/ajaxDisplay/", - data: {"page":$("#pageID").val(),"security->get_csrf_token_name()); ?>":"security->get_csrf_hash());?>"}, + data: {"postid":$("#lastPostID").val(),"security->get_csrf_token_name()); ?>":"security->get_csrf_hash());?>"}, success: function (data, status) { - console.log(data); var arrayOfPostAsJSONObject = JSON.parse(data); //getting the responseText from the server var numberOfPosts = arrayOfPostAsJSONObject.length; if(arrayOfPostAsJSONObject[0].message == "OUT_OF_INDEX"){ $("#morePostID").hide(); }else{ - var page = parseInt($("#pageID").val()) + 1; - $("#pageID").val(page); + var postid = arrayOfPostAsJSONObject[arrayOfPostAsJSONObject.length - 1].postid; + //console.log(arrayOfPostAsJSONObject[1]); + //console.log(data.length); + console.log(postid); + $("#lastPostID").val(postid); if(numberOfPosts < ){ //if max view reached pegination link changes $("#morePostID").hide(); } @@ -150,6 +152,7 @@ function (xhr, desc, err) { } else{ $data = json_decode($jsonObject); + $postid = $data[count($data)-1]->postid; for($i = 0; $i < LENGTH; $i++){ if(isset($data[$i]->username)){ echo("
"); @@ -169,7 +172,12 @@ function (xhr, desc, err) {
see more..");?> - +