diff --git a/.htaccess b/.htaccess new file mode 100644 index 00000000000..9e25198b5a4 --- /dev/null +++ b/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*)$ index.php/$1 [L] \ No newline at end of file diff --git a/application/config/autoload.php b/application/config/autoload.php index 7cdc9013c11..8ca9eb60505 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -58,7 +58,7 @@ | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('database', 'session', 'form_validation'); /* | ------------------------------------------------------------------- @@ -89,7 +89,7 @@ | | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array(); +$autoload['helper'] = array('url', 'file'); /* | ------------------------------------------------------------------- diff --git a/application/config/config.php b/application/config/config.php index 10315220e04..6a12e48e2ac 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -23,7 +23,7 @@ | a PHP script and you can easily do that on your own. | */ -$config['base_url'] = ''; +$config['base_url'] = 'http://localhost/CodeIgniter/'; /* |-------------------------------------------------------------------------- @@ -35,7 +35,7 @@ | variable so that it is blank. | */ -$config['index_page'] = 'index.php'; +$config['index_page'] = ''; /* |-------------------------------------------------------------------------- diff --git a/application/config/database.php b/application/config/database.php index 0088ef1403b..526c26d97cb 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -76,9 +76,9 @@ $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', - 'username' => '', + 'username' => 'root', 'password' => '', - 'database' => '', + 'database' => 'vietgram', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, diff --git a/application/config/routes.php b/application/config/routes.php index 1b45740d7c7..aaea762ed3c 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -49,6 +49,6 @@ | Examples: my-controller/index -> my_controller/index | my-controller/my-method -> my_controller/my_method */ -$route['default_controller'] = 'welcome'; +$route['default_controller'] = 'Login'; $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; diff --git a/application/controllers/Login.php b/application/controllers/Login.php new file mode 100644 index 00000000000..c787316de6b --- /dev/null +++ b/application/controllers/Login.php @@ -0,0 +1,38 @@ +load->model('userM'); + $this->load->library(''); + } + public function index() + { + $this->form_validation->set_rules('username', 'Username', 'trim|required'); + $this->form_validation->set_rules('password', 'Password', 'trim|required'); + if ($this->form_validation->run() == FALSE) { + $this->load->view('view_login'); + } else { + $data['username'] = $this->input->post('username'); + $data['password'] = $this->input->post('password'); + $q = $this->userM->login($data); + if ($q == 1) { + $array = array( + 'id' = 1, + 'username' => $data['username'] + ); + $this->session->set_userdata($array); + redirect('User'); + }else{ + $this->session->set_flashdata('error', '
User Not Found !
'); + redirect('Login'); + } + } + } +} + +/* End of file Login.php */ +/* Location: ./application/controllers/Login.php */ \ No newline at end of file diff --git a/application/controllers/User.php b/application/controllers/User.php new file mode 100644 index 00000000000..3a27d230fb3 --- /dev/null +++ b/application/controllers/User.php @@ -0,0 +1,72 @@ +load->model('userM'); + } + public function index() + { + $data['feed'] = $this->userM->getPost(); + $this->load->view('feed',$data); + } + public function profile() + { + $data['user'] = $this->userM->getUser(1)->row(); + $this->load->view('profile', $data); + } + public function editProfile() + { + $this->form_validation->set_rules('username', 'Username', 'trim|required'); + $data['user'] = $this->userM->getUser(1)->row(); + $this->load->view('edit-profile', $data); + } + public function editProfileAction() + { + $user['name'] = $this->input->post('full-name'); + $user['username'] = $this->input->post('username'); + $user['website'] = $this->input->post('website'); + $user['bio'] = $this->input->post('bio'); + $user['email'] = $this->input->post('email'); + $user['phone_number'] = $this->input->post('phone'); + $user['gender'] = $this->input->post('gender'); + $this->userM->updateUser(1,$user); + $this->session->set_flashdata('success', 'Profile Updated !'); + redirect('user/editProfile'); + } + public function addPhoto() + { + $this->load->view('add-photo'); + } + public function addPhotoAction() + { + + $config['upload_path'] = './uploads/'; + $config['allowed_types'] = 'gif|jpg|png'; + $config['max_size'] = '100'; + $config['max_width'] = '1024'; + $config['max_height'] = '768'; + + $this->load->library('upload', $config); + + if ( ! $this->upload->do_upload('file')){ + $error = array('error' => $this->upload->display_errors()); + print_r($error); + } + else{ + $data = array('upload_data' => $this->upload->data()); + $poto['caption'] = $this->input->post('caption'); + $poto['url'] = 'uploads/'.$data['upload_data']['file_name']; + $this->userM->uploadPhoto($poto); + $this->session->set_flashdata('success', 'upload success !'); + redirect('user/addPhoto'); + } + } + +} + +/* End of file User.php */ +/* Location: ./application/controllers/User.php */ \ No newline at end of file diff --git a/application/models/userM.php b/application/models/userM.php new file mode 100644 index 00000000000..5274f0c2eeb --- /dev/null +++ b/application/models/userM.php @@ -0,0 +1,31 @@ +db->query("SELECT * FROM `user` WHERE `username`='".$data['username']."' AND `password`='".md5($data['password'])."'"); + return $q->num_rows(); + } + public function getUser($id) + { + $q = $this->db->query("SELECT * FROM `profile` WHERE `id_profile`='$id'"); + return $q; + } + public function updateUser($id, $data) + { + $this->db->where('id_profile', $id); + $this->db->update('profile', $data); + } + public function uploadPhoto($data) + { + $this->db->insert('photo', $data); + } + public function getPost() + { + return $this->db->query("SELECT * FROM `photo`")->result(); + } +} + +/* End of file userM.php */ +/* Location: ./application/models/userM.php */ \ No newline at end of file diff --git a/application/views/add-photo.php b/application/views/add-photo.php new file mode 100644 index 00000000000..0fc0524cb35 --- /dev/null +++ b/application/views/add-photo.php @@ -0,0 +1,112 @@ + + + + + + + +