Skip to content

Commit

Permalink
added user info to the user page
Browse files Browse the repository at this point in the history
  • Loading branch information
Shemona Singh authored and Shemona Singh committed Dec 5, 2017
1 parent a0ba5f6 commit 680bbb1
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion www/application/config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
|
| $autoload['libraries'] = array('user_agent' => 'ua');
*/
$autoload['libraries'] = array();
$autoload['libraries'] = array('session');

/*
| -------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions www/application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_save_path'] = '/tmp';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
Expand All @@ -402,7 +402,7 @@
*/
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_path'] = '';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;

Expand Down
11 changes: 8 additions & 3 deletions www/application/controllers/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ function __Construct(){
parent::__Construct();
$this->load->database(); // load database
$this->load->model('User_Info_Model'); // load model
session_start();
$this->output->enable_profiler(TRUE);
}

public function index(){

$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');

Expand All @@ -23,11 +25,14 @@ public function index(){
else {
//check if user in db
$user = $this->User_Info_Model->isRegistered();

$data['user'] = $user;
// if yes get user id, launch session, send to home
if($user !== []){
$data['user'] = $user;
redirect('/all_tweets');
$this->session->set_userdata($user);
$data = $this->session->all_userdata();

//$this->load->view('login', $data);
redirect('/User_Tweets');
}
// if no, refresh login
else $this->load->view('login', $data);
Expand Down
1 change: 0 additions & 1 deletion www/application/controllers/User_Tweets.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class User_Tweets extends CI_Controller {

function __Construct(){
parent::__Construct();
//$this->load->library('session');
$this->load->database(); // load database
$this->load->model('User_Tweets_Model'); // load model
$this->output->enable_profiler(TRUE);
Expand Down
2 changes: 1 addition & 1 deletion www/application/models/User_Info_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function isRegistered(){
$this->db->where('username', $username);
$this->db->where('password', $password);
$query = $this->db->get();
$result = $query->result_array();
$result = $query->result_array()[0];
return $result;
}
// register
Expand Down
6 changes: 4 additions & 2 deletions www/application/models/User_Tweets_Model.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
class User_Tweets_Model extends CI_Model {
function getPosts(){

//$this->load->library('session');
//$this->session->all_userdata();

$this->db->select("first_name, last_name, username, tweet, date_time");
$this->db->from('Users, Tweets');
$this->db->where("Users.id = Tweets.user_id and Users.id = $user_id");
$this->db->where("Users.id = Tweets.user_id");
$this->db->where("Users.id = " . $this->session->userdata('id'));
$this->db->order_by('date_time', 'DESC');
$query = $this->db->get();
return $query->result_array();
Expand Down
2 changes: 1 addition & 1 deletion www/application/views/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<div class="home container">
<h1>All Tweets</h1>

<?php echo $id; ?>
<?php $this->load->library('form_validation'); ?>
<?php echo validation_errors(); ?>
<?php echo form_open('all_tweets/search_keyword'); ?>
Expand Down
2 changes: 1 addition & 1 deletion www/application/views/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
echo validation_errors();
echo form_open('login'); ?>
<?php
var_dump($user);
var_dump($username); //var_dump($sesh);
?>

<h1>Twitter</h1>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__ci_last_regenerate|i:1512442454;

0 comments on commit 680bbb1

Please sign in to comment.