Skip to content

Commit

Permalink
Merge pull request #28 from tanhongit/feature/environment
Browse files Browse the repository at this point in the history
Feature/environment
  • Loading branch information
tanhongit authored Jan 5, 2024
2 parents 0bd3aab + 0bf10ac commit 9b03f2e
Show file tree
Hide file tree
Showing 24 changed files with 227 additions and 101 deletions.
33 changes: 33 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# if you don't want to set the value you can remove the line or comment it out with a hash (#)

PATH_URL=/
PATH_URL_IMG=public/upload/images/
PATH_URL_IMG_PRODUCT=public/upload/products/

DB_HOST=db_server
DB_PORT=3306
DB_USER=root
DB_PASS=root
DB_NAME=new_mvc_shop_db

SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_UNAME
SMTP_PWORD

################### For docker ###################
PHP_VERSION_SELECTED=8.2

APP_NAME

APP_PORT
SSL_PORT

MYSQL_PORT
MYSQL_USER
MYSQL_ROOT_PASS
MYSQL_DB
MYSQL_PASS

PHPMYADMIN_PORT
PHPMYADMIN_UPLOAD_LIMIT
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ vendor
docker/certs
docker/logs
.php-cs-fixer.cache
.env
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
// this file is used by php-cs-fixer to format the code

$finder = Symfony\Component\Finder\Finder::create()
->in([
Expand Down
113 changes: 79 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ Support this project :stuck_out_tongue_winking_eye: :pray:
</p>

# 1. Configuration requirements

- Version PHP 7.2 and above (-> 8.1)
- Web Server: Apache
- Version PHP >= 8.0
- OpenSSL PHP Extension
- Composer (Please install composer before running this project)
- MySQL >= 8.0 (or MariaDB >= 10.0)

# 2. Technology
- Pure PHP language
Expand Down Expand Up @@ -55,59 +57,97 @@ This is the path to the database file for you to download: [`/admin/database/***

Create a new database on **PHPMyAdmin** at your server, then import the .sql file that you just downloaded.

# 5. Request appropriate edits
# 5. Request configuration

After a clone my repository to the local computer, you need to edit some code to be able to connect to the database and help the site works.
Clone the project to your computer:

```bash
git clone https://github.com/tanhongit/new-mvc-shop.git
```

### 5.1 Edit Config
Run composer install:

You need to change the path in the '**config.php**' file to match the location of this source code on your server and must match the domain you registered.
```bash
composer install
```

Path: [`/lib/config/config.php`](https://github.com/TanHongIT/new-mvc-shop/tree/master/lib/config)
Copy the .env.example file to .env:

```php
<?php
define('BASE_URL', 'new-mvc-shop');
define('PATH_URL', '/');
define('PATH_URL_IMG', PATH_URL . 'public/upload/images/');
define('PATH_URL_IMG_PRODUCT', PATH_URL . 'public/upload/products/');
```bash
cp .env.example .env
```
### 5.2 Edit Connect Database

You need to change the connection information to the database after you have cloned my repository so that the website can work.
After a clone my repository to the local computer, you need to edit some code to be able to connect to the database and help the site works.

Path: [`/lib/config/database.php`](https://github.com/TanHongIT/new-mvc-shop/tree/master/lib/config)
## 5.1 Edit Config

This is the path to the database file for you to download: [`/admin/database/***.sql`](https://github.com/TanHongIT/new-mvc-shop/tree/master/admin/database)
You need to change the path in the '**.env**' file to match the location of this source code on your server and must match the domain you registered.

```php
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'chikoi');
```dotenv
PATH_URL=/
PATH_URL_IMG=public/upload/images/
PATH_URL_IMG_PRODUCT=public/upload/products/
```

### 5.2 Edit .htaccess
> **Note:**
>
> The path of the config file that is using these environment variables is located at: [`/lib/config/config.php`](https://github.com/TanHongIT/new-mvc-shop/tree/master/lib/config/config.php)
Change RewriteBase - Recommend the path that matches your host address.
## 5.2 Edit Connect Database

-----------------------------------------------
You need to change the connection information and import sql file to the database after you have cloned my repository so that the website can work.

so we will have:
This is the path to the sql file for you to import to your database:
[`/admin/database/***.sql`](https://github.com/TanHongIT/new-mvc-shop/tree/master/admin/database)

And change the connection information to match your database in .env file:

```dotenv
DB_HOST=db_server
DB_PORT=3306
DB_USER=root
DB_PASS=root
DB_NAME=chikoi
```

> **Note:**
>
> The path of the database config file that is using these environment variables is located at: [`/lib/config/database.php`](https://github.com/TanHongIT/new-mvc-shop/tree/master/lib/config/database.php)
## 5.3 Edit .htaccess

Change RewriteBase - Recommend the path that matches your host address.

So we will have:
```
RewriteBase /
```

-----------------------------------------------

> **Note**: This applies to the case where your project is in a subfolder, and you want it accessible from a subpath URL.
>
>**EXAMPLE**:
>```
>http://localhost/new-mvc-shop/
>```
> So we will have:
> ```
> RewriteBase /new-mvc-shop/
> ```
### 5.4 Edit SMTP Mail
> The third thing:
You need to change the information about **SMTP Mail** to be able to use some functions about user account authentication, change passwords, notify users, ...
```php
define('SMTP_HOST','smtp.gmail.com');
define('SMTP_PORT','465');
define('SMTP_UNAME','add_your_mail');
define('SMTP_PWORD','add_your_application_password_from_your_mail');
Update the following information in the **.env** file:
```dotenv
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_UNAME=add_your_mail
SMTP_PWORD=add_your_application_password_from_your_mail
```
Change the value of the constant **SMTP_UNAME** and **SMTP_PWORD** to match the configuration you added on your Gmail.
Expand All @@ -116,12 +156,15 @@ Tips: https://support.google.com/accounts/answer/185833?hl=en

**Where SMTP_PWORD is the application password for your _gmail.com_ account.**

Path: [`/lib/config/sendmail.php`](https://github.com/TanHongIT/new-mvc-shop/tree/master/lib/config)
> **Note:**
>
> The path of the email config file that is using these environment variables is located at: [`/lib/config/sendmail.php`](https://github.com/TanHongIT/new-mvc-shop/tree/master/lib/config/sendmail.php)

# 6. Demo

1. Front-End: [http://tanhongit.epizy.com/new-mvc-shop/home](http://tanhongit.epizy.com/new-mvc-shop/home)
2. Back-End: [http://tanhongit.epizy.com/new-mvc-shop/admin.php](http://tanhongit.epizy.com/new-mvc-shop/admin.php)
1. Front-End: [https://chikoiquan.tanhongit.com](https://chikoiquan.tanhongit.com)
2. Back-End: [https://chikoiquan.tanhongit.com/admin.php](https://chikoiquan.tanhongit.com/admin.php)

> **_Account login on Backend_**
Expand Down Expand Up @@ -155,6 +198,8 @@ Admin:
**Admin Manager Page**
![Image](https://imgur.com/xOpAmb4.png)

![Image](https://imgur.com/u8lXnsz.png)

---------------------------------------------------------------------------------

<p align="center">
Expand Down
7 changes: 7 additions & 0 deletions admin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

use Dotenv\Dotenv;

require __DIR__ . '/vendor/autoload.php';

$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();

session_start();

require_once('lib/model.php');
Expand Down
1 change: 0 additions & 1 deletion admin/models/feedbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function updateFeedback(): void
function feedbackReplyMail($html, $email)
{
//sendmail
require 'vendor/autoload.php';
include 'lib/config/sendmail.php';
$mail = new PHPMailer(true);

Expand Down
3 changes: 0 additions & 3 deletions admin/models/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ function changePassword($id, $newpassword, $currentPassword)
];
save('users', $options);
//sendmail
require 'vendor/autoload.php';
include 'lib/config/sendmail.php';
$mail = new PHPMailer(true);
$user = getRecord('users', $id);
Expand Down Expand Up @@ -169,7 +168,6 @@ function user_update()
$user_edited = getRecord('users', $userId);
if ($user_edited['user_email'] != $currentEmail) {
//send mail
require 'vendor/autoload.php';
include 'lib/config/sendmail.php';
$email = $user_edited['user_email'];
$mail = new PHPMailer(true);
Expand Down Expand Up @@ -271,7 +269,6 @@ function user_add()
save('users', $user_add);
}
//send mail
require 'vendor/autoload.php';
include 'lib/config/sendmail.php';
$mail = new PHPMailer(true);

Expand Down
8 changes: 5 additions & 3 deletions content/controllers/category/index.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

if (isset($_GET['id'])) {
$categoryId = intval($_GET['id']);
} else {
if (!isset($_GET['id'])) {
show404NotFound();
}

$categoryId = intval($_GET['id']);

$category = getRecord('subcategory', $categoryId);
if (!$category) {
show404NotFound();
}

$categories = getAll('subcategory', [
'select' => 'id, subcategory_name',
'order_by' => 'id ASC',
Expand Down
40 changes: 17 additions & 23 deletions content/controllers/comment/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,26 @@

if (!empty($_POST)) {
global $userNav;

$commentData = [
'id' => 0,
'product_id' => intval($_POST['product_id']),
'email' => escape($_POST['email']),
'author' => escape($_POST['author']),
'content' => escape($_POST['content']),
'createDate' => gmdate('Y-m-d H:i:s', time() + 7 * 3600),
'user_id' => intval($_POST['user_id']),
];

if (isset($userNav)) {
$comment_add = [
'id' => 0,
'product_id' => intval($_POST['product_id']),
'email' => escape($_POST['email']),
'author' => escape($_POST['author']),
'content' => escape($_POST['content']),
'createDate' => gmdate('Y-m-d H:i:s', time() + 7 * 3600),
'user_id' => intval($_POST['user_id']),
'link_image' => escape($_POST['link_image']),
];
} else {
$comment_add = [
'id' => 0,
'product_id' => intval($_POST['product_id']),
'email' => escape($_POST['email']),
'author' => escape($_POST['author']),
'content' => escape($_POST['content']),
'createDate' => gmdate('Y-m-d H:i:s', time() + 7 * 3600),
'user_id' => intval($_POST['user_id']),
];
$commentData['link_image'] = escape($_POST['link_image']);
}
save('comments', $comment_add);

save('comments', $commentData);
echo "<div class='alert alert-success'><strong>Done!</strong> Bạn đã ghi lời bình luận của bạn lại thành công !! <br>Hãy <a href='javascript: history.go(-1)'>Trở lại sản phẩm</a> hoặc <a href='index.php'>Đến trang chủ</a></div>";
}
require('content/views/comment/index.php');

// $input = json_decode(file_get_contents('php://input'), true);

// $productID = $input['productID'];
Expand All @@ -37,7 +31,7 @@
// $author = $input['author'];
// $userID = $input['email'];

// $comment_add = array(
// $commentData = array(
// 'id' => 0,
// 'product_id' => intval($productID),
// 'email' => escape($email),
Expand All @@ -47,7 +41,7 @@
// 'user_id' => intval($userID),
// 'link_image' => escape($link_image)
// );
// save('comments', $comment_add);
// save('comments', $commentData);

// $option = array('product_id' => intval($productID));

Expand Down
2 changes: 2 additions & 0 deletions content/controllers/feedback/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
if (!empty($_POST)) {
feedback_add();
}

if (isset($_GET['product_id'])) {
$productId = intval($_GET['product_id']);
} else {
$productId = 0;
}

$product = getRecord('products', $productId);
if (isset($userNav)) {
$user_action = getRecord('users', $userNav);
Expand Down
4 changes: 3 additions & 1 deletion content/controllers/forgot-password/index.php
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<?php require('content/views/forgot-password/index.php');
<?php

require('content/views/forgot-password/index.php');
1 change: 0 additions & 1 deletion content/controllers/forgot-password/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
$verification_Code = $user['verificationCode'];
}
}
require 'vendor/autoload.php';
include 'lib/config/sendmail.php';
$mail = new PHPMailer(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
save('users', $options);

//send mail
require 'vendor/autoload.php';
include 'lib/config/sendmail.php';
$mail = new PHPMailer(true);

Expand Down
1 change: 0 additions & 1 deletion content/controllers/register/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
// Load Composer's autoloader
$userId = save('users', $user_add);
//send mail
require 'vendor/autoload.php';
include 'lib/config/sendmail.php';
$mail = new PHPMailer(true);

Expand Down
1 change: 0 additions & 1 deletion content/controllers/register/resend.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
}
}
//send mail
require 'vendor/autoload.php';
include 'lib/config/sendmail.php';
$mail = new PHPMailer(true);

Expand Down
Loading

0 comments on commit 9b03f2e

Please sign in to comment.