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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
4 changes: 2 additions & 2 deletions 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('database', 'session', 'form_validation');

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

/*
| -------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/';

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

/*
|--------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions application/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => '',
'username' => 'root',
'password' => '',
'database' => '',
'database' => 'vietgram',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
Expand Down
2 changes: 1 addition & 1 deletion application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
38 changes: 38 additions & 0 deletions application/controllers/Login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Login extends CI_Controller {

public function __construct()
{
parent::__construct();
$this->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', '<p style="color : red;" class="login__link login__link--small">User Not Found !</p>');
redirect('Login');
}
}
}
}

/* End of file Login.php */
/* Location: ./application/controllers/Login.php */
72 changes: 72 additions & 0 deletions application/controllers/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class User extends CI_Controller {

public function __construct()
{
parent::__construct();
$this->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 */
31 changes: 31 additions & 0 deletions application/models/userM.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class UserM extends CI_Model {
public function login($data)
{
$q = $this->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 */
112 changes: 112 additions & 0 deletions application/views/add-photo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>add photo | Vietgram</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="<?php echo base_url('assets/css/styles.css') ?>">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js"></script>
</head>
<style>
#image-preview{
display:none;
width : 250px;
height : 300px;
}
</style>

<body>
<nav class="navigation">
<div class="navigation__column">
<a href="feed.html">
<img src="<?php echo base_url('assets/images/logo.png')?>" />
</a>
</div>
<div class="navigation__column">
<i class="fa fa-search"></i>
<input type="text" placeholder="Search">
</div>
<div class="navigation__column">
<ul class="navigations__links">
<li class="navigation__list-item">
<a href="explore.html" class="navigation__link">
<i class="fa fa-compass fa-lg"></i>
</a>
</li>
<li class="navigation__list-item">
<a href="#" class="navigation__link">
<i class="fa fa-heart-o fa-lg"></i>
</a>
</li>
<li class="navigation__list-item">
<a href="profile.html" class="navigation__link">
<i class="fa fa-user-o fa-lg"></i>
</a>
</li>
</ul>
</div>
</nav>
<main id="edit-profile">
<div class="edit-profile__container">
<header class="edit-profile__header">
<div class="edit-profile__avatar-container">
<img src="<?php echo base_url('assets/images/avatar.jpg')?>" class="edit-profile__avatar" />
</div>
<h4 class="edit-profile__username"><?php echo $this->session->userdata('username'); ?></h4>
</header>
<form action="<?php echo base_url('user/addPhotoAction')?>" method="post" class="edit-profile__form" enctype="multipart/form-data">
<input type="hidden" id="id" value="1">
<div class="form__row">
<label for="caption" class="form__label">Caption:</label>
<textarea name="caption" id="caption"></textarea>
</div>
<div class="form__row">
<label for="photo" class="form__label">Photo:</label>
<input type="file" id="image-source" name="file" onchange="previewImage();"/>
</div>
<div class="form__row">
<label for="preview" id="preview" class="form__label"></label>
<img id="image-preview" alt="image preview"/>
</div>
<input type="submit" id="submit" name="submit" value="Submit">
<?php echo $this->session->flashdata('success'); ?>
</form>
</div>
</main>
<footer class="footer">
<div class="footer__column">
<nav class="footer__nav">
<ul class="footer__list">
<li class="footer__list-item"><a href="#" class="footer__link">About Us</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">Support</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">Blog</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">Press</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">Api</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">Jobs</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">Privacy</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">Terms</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">Directory</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">Language</a></li>
</ul>
</nav>
</div>
<div class="footer__column">
<span class="footer__copyright">© 2017 Vietgram</span>
</div>
</footer>
</body>
<script>
<script>
function previewImage() {
document.getElementById("image-preview").style.display = "block";
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("image-source").files[0]);
oFReader.onload = function(oFREvent) {
document.getElementById("image-preview").src = oFREvent.target.result;
};
$("#preview").text('Preview:');
};
</html>
Loading