Commit eba99a42 by tetiana yaremko

created Auth_model (for login)

authentication process is implemented
 Created  register_model
 Registration is implemented
 improved login view
parent 230de041
...@@ -89,7 +89,7 @@ $autoload['drivers'] = array(); ...@@ -89,7 +89,7 @@ $autoload['drivers'] = array();
| |
| $autoload['helper'] = array('url', 'file'); | $autoload['helper'] = array('url', 'file');
*/ */
$autoload['helper'] = array('url'); $autoload['helper'] = array('url', 'asset', 'form');
/* /*
| ------------------------------------------------------------------- | -------------------------------------------------------------------
......
...@@ -23,7 +23,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); ...@@ -23,7 +23,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
| a PHP script and you can easily do that on your own. | a PHP script and you can easily do that on your own.
| |
*/ */
$config['base_url'] = 'http://localhost/ci'; $config['base_url'] = 'http://localhost/webapp/ci';
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
...@@ -377,10 +377,10 @@ $config['encryption_key'] = ''; ...@@ -377,10 +377,10 @@ $config['encryption_key'] = '';
| except for 'cookie_prefix' and 'cookie_httponly', which are ignored here. | except for 'cookie_prefix' and 'cookie_httponly', which are ignored here.
| |
*/ */
$config['sess_driver'] = 'files'; $config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session'; $config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200; $config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL; $config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE; $config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300; $config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE; $config['sess_regenerate_destroy'] = FALSE;
......
...@@ -83,3 +83,11 @@ defined('EXIT_USER_INPUT') OR define('EXIT_USER_INPUT', 7); // invalid user ...@@ -83,3 +83,11 @@ defined('EXIT_USER_INPUT') OR define('EXIT_USER_INPUT', 7); // invalid user
defined('EXIT_DATABASE') OR define('EXIT_DATABASE', 8); // database error defined('EXIT_DATABASE') OR define('EXIT_DATABASE', 8); // database error
defined('EXIT__AUTO_MIN') OR define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code defined('EXIT__AUTO_MIN') OR define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
defined('EXIT__AUTO_MAX') OR define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code defined('EXIT__AUTO_MAX') OR define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code
define('ERR_NONE', 0);
define('ERR_INVALID_EMAIL', 1);
define('ERR_INVALID_PASSWORD', 2);
...@@ -78,7 +78,7 @@ $db['default'] = array( ...@@ -78,7 +78,7 @@ $db['default'] = array(
'hostname' => 'localhost', 'hostname' => 'localhost',
'username' => 'root', 'username' => 'root',
'password' => '', 'password' => '',
'database' => 'ci', 'database' => 'mydb',
'dbdriver' => 'mysqli', 'dbdriver' => 'mysqli',
'dbprefix' => '', 'dbprefix' => '',
'pconnect' => FALSE, 'pconnect' => FALSE,
......
<?php <?php
class Auth extends CI_Controller { class Auth extends CI_Controller {
function __construct () {
parent::__construct();
}
public function logged_in_check()
{
if ($this->session->userdata("logged_in")) {
redirect("home/products");
}
}
public function logout() { public function logout() {
unset($_SESSION); $this->session->unset_userdata("logged_in");
session_destroy(); $this->session->sess_destroy();
redirect("auth/login", "refresh"); redirect("auth/login");
} }
public function login() { public function login()
{
$this->form_validation->set_rules('username', 'Username', 'required'); /*
$this->form_validation->set_rules('password', 'Password', 'required|min_length[8]'); $this->form_validation->set_rules('email', 'Email', 'required');
if($this->form_validation->run()==TRUE) { $this->form_validation->set_rules('password', 'Password', 'required|min_length[8]');
$username=$_POST['username']; if($this->form_validation->run()==TRUE) {
$password=md5($_POST['password']); $email=$_POST['email'];
$this->db->select('*'); $password=md5($_POST['password']);
$this->db->from('users'); $this->db->select('*');
$this->db->where(array('username'=>$username, 'password'=>$password)); $this->db->from('users');
$query=$this->db->get(); $this->db->where(array('email'=>$email, 'password'=>$password));
$user=$query->row(); $query=$this->db->get();
$user=$query->row();
if($user->email) {
if($user->email) {
//$this->session->set_flashdata("success", " You are logged in");
$_SESSION['user_logged']=TRUE; //$this->session->set_flashdata("success", " You are logged in");
$_SESSION['username'] =$user->username; $_SESSION['user_logged']=TRUE;
//$_SESSION['email'] =$email->email;
redirect("home/products", "refresh");
redirect("home/products", "refresh");
} else {
} else {
$this->session->set_flashdata("error", "This account doesn't exist");
redirect("auth/login", "refresh"); $this->session->set_flashdata("error", "This account doesn't exist");
} redirect("auth/login", "refresh");
}
}
*/
/* $this->load->view('templates/header');
$this->load->view('login1');
}
public function check_login () {
$this->form_validation->set_rules('email', 'Email', 'trim|required');
$this->form_validation->set_rules('password', 'Password', 'trim|required|trim|callback_verifyUser');
if($this->form_validation->run()==false) {
//$this->load->view('templates/header');
$this->load->view('login1');
}
/* elseif ($this->verifyUser()==false) {
$this->load->view('login1');
}
else
{
//$_SESSION['user_logged']=TRUE;
redirect("home/products", "refresh");
}
} }
$this->load->view('templates/header'); public function verifyUser () {
$this->load->view('login'); $email=$this->input->post('email');
$password=$this->input->post('password');
$this->load->model('Auth_model');
if($this->Auth_model->login($email, $password)) {
$_SESSION['user_logged']=TRUE;
return true;
} else {
$this->form_validation->set_message('verifyUser', 'Incorrect');
return false;
}
*/
$this->logged_in_check();
$this->form_validation->set_rules("email", "Email", "trim|required");
$this->form_validation->set_rules("password", "Password", "trim|required");
if ($this->form_validation->run() == true)
{
$this->load->model('auth_model', 'auth');
$status=$this->auth->validate();
if($status==ERR_INVALID_EMAIL) {
$this->session->set_flashdata("error", "Email is not valid");
}
elseif ($status==ERR_INVALID_PASSWORD) {
$this->session->set_flashdata("error", "Password is not valid");
}
else {
$this->session->set_userdata($this->auth->get_data());
$this->session->set_userdata("logged_in",true);
redirect("home/products");
}
}
$this->load->view('templates/header');
$this->load->view('login1');
} }
public function register() { public function register() {
if(isset ($_POST['register'])) { if(isset ($_POST['register'])) {
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('email', 'Email', 'required'); $this->form_validation->set_rules('email', 'Email', 'required|is_unique[users.email]');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[8]'); $this->form_validation->set_rules('password', 'Password', 'required|min_length[8]');
$this->form_validation->set_rules('password2', 'Confirm password', 'required|min_length[8]|matches[password]'); $this->form_validation->set_rules('password2', 'Confirm password', 'required|min_length[8]|matches[password]');
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('surname', 'Surname', 'required');
$this->form_validation->set_rules('country', 'Country field', 'required'); $this->form_validation->set_rules('country', 'Country field', 'required');
$this->form_validation->set_rules('city', 'City field', 'required'); $this->form_validation->set_rules('city', 'City field', 'required');
$this->form_validation->set_rules('street', 'Street field', 'required'); $this->form_validation->set_rules('street', 'Street field', 'required');
$this->form_validation->set_rules('zip', 'ZIP field', 'required');
$this->form_validation->set_rules('building', 'Building field', 'required');
$this->form_validation->set_rules('phone', 'Phone field', 'required'); $this->form_validation->set_rules('phone', 'Phone field', 'required');
if($this->form_validation->run()==TRUE) { if($this->form_validation->run()==TRUE) {
echo 'form validated';
/*
$data = array( $data = array(
'username' =>$_POST['username'],
'email' =>$_POST['email'], 'email' =>$_POST['email'],
'password' =>md5($_POST['password']), 'password' =>md5($_POST['password']),
'name' =>$_POST['name'],
'surname' =>$_POST['surrname'],
'country' =>$_POST['country'], 'country' =>$_POST['country'],
'city' =>$_POST['city'], 'city' =>$_POST['city'],
'street' =>$_POST['street'], 'street' =>$_POST['street'],
'building' =>$_POST['building'],
'zip' =>$_POST['zip'],
'phone' =>$_POST['phone'] 'phone' =>$_POST['phone']
); );
$this->db->insert('users', $data); $this->db->insert('users', $data);
//$this->session->set_flashdata("success", "Your account has been registered.You can login now"); //$this->session->set_flashdata("success", "Your account has been registered.You can login now"); */
$this->load->model('Register_model', 'reg');
$this->reg->register_user();
redirect("register_successful/registration_complete", "refresh"); redirect("register_successful/registration_complete", "refresh");
} }
...@@ -84,3 +165,4 @@ class Auth extends CI_Controller { ...@@ -84,3 +165,4 @@ class Auth extends CI_Controller {
} }
} }
...@@ -8,22 +8,33 @@ class Home extends CI_Controller { ...@@ -8,22 +8,33 @@ class Home extends CI_Controller {
{ {
parent::__construct(); parent::__construct();
if($_SESSION['user_logged']==FALSE) {
redirect("auth/login");
}
} }
public function products() public function products()
{ {
if($_SESSION['user_logged']==FALSE) { /*if($_SESSION['user_logged']==true) {
//redirect("home/products");
redirect("auth/login"); $this->load->view('templates/header');
$this->load->view('templates/home_t');
} }
$this->load->view('templates/header'); else
$this->load->view('products'); {
redirect("auth/login");
}
*/
if ($this->session->userdata("logged_in")) {
$this->load->view('templates/header');
$this->load->view('templates/home_t');
}
else {
redirect("auth/login");
}
} }
......
<?php <?php
class Auth_model extends CI_Model { class Auth_model extends CI_Model {
/*var $u_id;
var $email;
var $name;
public function __construct (){ public function __construct (){
parent::__construct(); parent::__construct();
} }
public function login($email, $password) {
$this->db->select('u_id, name, 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)
{
//$rows = $query->result();
/*$this->u_id = $rows[0]->u_id;
$this->email = $rows[0]->email;
$this->name = $rows[0]->name;
return true;
}
else
{
return false;
}
}
*/
private $_data=array();
public function validate() {
$email =$this->input->post('email');
$password =md5($this->input->post('password'));
$this->db->select('u_id, name, email, password');
$this->db->from('users');
$this->db->where('email', $email);
$query = $this->db->get();
if($query->num_rows()==1) {
$row=$query->result();
if($row[0]->password==$password)
{
unset($row['password']);
$this->_data=$row;
return ERR_NONE;
}
return ERR_INVALID_PASSWORD;
} else {
return ERR_INVALID_EMAIL;
}
}
public function get_data()
{
return $this->_data;
}
} }
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link href=" <?php echo base_url();?>assets/css/bootstrap.min.css" rel="stylesheet">
<title>Login Page</title>
</head>
<body>
<div class="row justify-content-center">
<div class ="col-lg-4 col-lg-offset-8">
<h1>Login Page</h1>
<p>Fill in the details:</p>
<?php if(isset($_SESSION['success'])) {?>
<div class="alert alert-success"> <?php echo $_SESSION['success'];?></div>
<?php
} ?>
<?php echo validation_errors('<div class="alert alert-danger">','</div>'); ?>
<form action="" method="post">
<div class="form-group">
<label> Username:</label>
<input class="form-control" name="username" id="username" type="text" >
</div>
<div class="form-group">
<label> Password:</label>
<input class="form-control" name="password" id="password" type="password">
</div>
<div class="text-center">
<button class="btn btn-primary" name="login">Login</button>
</div>
</form>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src="<?php echo base_url();?>assets/js/bootstrap.min.js"></script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<title>Login Page</title>
</head>
<style>
body {
background-color: #eee;
font-size: 0.9rem;
color: #444444;
}
.auth-section {
font-family: Helvetica;
margin: auto;
background-color: white;
height: 78%;
margin-top: 190px;
width:1000px;
display: flex;
flex-direction: row;
border-shadow:1px 1px 1px rgba(0, 0, 0, 0.9);
padding-top: 100px;
}
.signup, .reg{
width: 50%;
height: 300px;
display: flex;
flex-direction: column;
padding: 25px 60px;
}
h3 {
font-weight: 600;
margin-bottom: 25px;
}
.reg {
align-items: center;
}
.signup {
border-right: 1px solid #cccccc;
}
.form-group {
display: flex;
flex-direction: column;
}
input {
width: 100%;
padding: .1em .2em;
border: 1px solid #ccc;
background: #fdfcfc;
margin: 0;
color: #444;
font-size: 1em;
line-height: 1.8;
border-radius: 2px;
margin-bottom: 0;
}
label {
margin:0;
}
.btn{
font-weight: 500;
font-family: inherit;
cursor: pointer;
width: 90px;
font-family: inherit;
padding: .5em 1em;
background: #000;
color: #fff;
border: 2px solid #000;
letter-spacing: 1.3px;
border-radius: 0;
}
.btn:hover {
border: 2px solid #000;
color: #000;
background-color: #fff;
}
.signup btn {
display: inline-block;;
}
.forgot {
display: inline-block;
float: right;
color: #999999;
font-family: inherit;
}
.forgot:hover{
color: #999999;
}
.input-error {
padding: 0;
margin-top: 0;
font-size: 0.9rem;
font-family: inherit;
}
</style>
<body>
<div class="auth-section">
<div class="signup">
<h3>Existing customer</h3>
<?php $error = $this->session->flashdata("error")?>
<div class="alert alert-<?php echo $error ? 'warning' : 'info' ?> alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<?php echo $error ? $error : 'Enter your username and password' ?>
</div>
<?php echo form_open(); ?>
<?php $error =form_error("email", "<p class='text-danger'>", '</p>');?>
<div class="form-group <?php echo $error ? 'has-error' : '' ?>">
<label for="email">Email</label>
<input type="email" value="<?php echo set_value("email") ?>" name="email"/>
<div class="input-error"> <?php echo $error; ?> </div>
</div>
<?php $error =form_error("password", "<p class='text-danger'>", '</p>');?>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password"/>
<div class="input-error"> <?php echo $error; ?> </div>
</div>
<input class="btn" type="submit" value="Login" name="submit"/>
<a href="#" class="forgot open">Forgot your password?</a>
</form>
</div>
<div class="reg">
<h3>New Customer</h3>
<p>Click Next to provide us with your details</p>
<a href="<?php echo base_url(); ?>index.php/auth/register"><button class="btn">Next</button></a>
</div>
</div>
</body>
</html>
</body>
...@@ -15,21 +15,15 @@ ...@@ -15,21 +15,15 @@
<div class ="col-lg-4 col-lg-offset-8"> <div class ="col-lg-4 col-lg-offset-8">
<h1>Register Page</h1> <h1>Register Page</h1>
<p>Fill in the details:</p> <p>Fill in the details:</p>
<?php if(isset($_SESSION['success'])) {?>
<div class="alert alert-success"> <?php echo $_SESSION['success'];?></div>
<?php
} ?>
<?php echo validation_errors('<div class="alert alert-danger">','</div>'); ?> <?php echo validation_errors('<div class="alert alert-danger">','</div>'); ?>
<form action="" method="post"> <form action="" method="post">
<div class="form-group">
<label> Username:</label>
<input class="form-control" name="username" id="username" type="text" >
</div>
<div class="form-group"> <div class="form-group">
<label> Email:</label> <label> Email:</label>
<input class="form-control" name="email" id="email" type="text"> <input class="form-control" name="email" id="email" type="text">
</div> </div>
<div class="form-group"> <div class="form-group">
<label> Password:</label> <label> Password:</label>
<input class="form-control" name="password" id="password" type="password"> <input class="form-control" name="password" id="password" type="password">
...@@ -37,9 +31,16 @@ ...@@ -37,9 +31,16 @@
<div class="form-group"> <div class="form-group">
<label> Confirm password:</label> <label> Confirm password:</label>
<input class="form-control" name="password2" id="password" type="password" > <input class="form-control" name="password2" id="password" type="password" >
</div> </div>
<div class="form-group">
<div class="form-group"> <label> Name:</label>
<input class="form-control" name="name" id="name" type="text" >
</div>
<div class="form-group">
<label> Surname:</label>
<input class="form-control" name="surname" id="surname" type="text" >
</div>
<div class="form-group">
<label> Country:</label> <label> Country:</label>
<input class="form-control" name="country" id="country" type="text" > <input class="form-control" name="country" id="country" type="text" >
</div> </div>
...@@ -52,9 +53,19 @@ ...@@ -52,9 +53,19 @@
<label> Street:</label> <label> Street:</label>
<input class="form-control" name="street" id="street" type="text" > <input class="form-control" name="street" id="street" type="text" >
</div> </div>
<div class="form-group">
<div class="form-group"> <label> ZIP:</label>
<input class="form-control" name="zip" id="zip" type="text" >
</div>
<div class="form-group">
<label> Building:</label>
<input class="form-control" name="building" id="building" type="text" >
</div>
<div class="form-group">
<label> Phone:</label> <label> Phone:</label>
<input class="form-control" name="phone" id="phone" type="text" > <input class="form-control" name="phone" id="phone" type="text" >
</div> </div>
......
<html> <html>
<head> <head>
<title>retro record</title> <title>retro record</title>
<link rel="stylesheet" href="<?php echo base_url(); ?>asset/css/stylee.css" type="text/css">
<link rel="stylesheet" href="<?php echo base_url(); ?>asset/css/bootstrap.min.css" type="text/css">
</head> </head>
<body> <body>
<nav class="navbar navbar-inverse "> <header class="header-section" >
<div class="container"> <div class="container-fluid" id="header-top">
<div class="navbar-header pull-left"> <div class="inner-header">
<a class="navbar-brand" href="#">Retrorecord</a> <div class="logo">
</div> <a href="<?php echo base_url(); ?>index.php/home/products"><img src="<?= asset_url('img/logo.gif')?>" alt=""></a>
<div id="navbar"> </div>
<ul class="nav navbar-nav navbar-right"> <div class="header-right">
<li class="dropdown pull-right">
<li><a href="<?php echo base_url(); ?>index.php/home/products">Home</a></li> <img src="<?= asset_url('img/icons/man.png')?>" alt="">
<li><a href="<?php echo base_url(); ?>index.php/auth/login">Log in</a></li> <a href="#">
<li><a href="<?php echo base_url(); ?>index.php/auth/register">Register</a></li> <img src="<?= asset_url('img/icons/bag.png')?>" alt="">
<li><a href="<?php echo base_url(); ?>index.php/auth/logout">Logout</a></li> <span>2</span>
</li> </a>
</ul> </div>
</div> <div class="user-access">
</div> <a href="<?php echo base_url(); ?>index.php/auth/register">Register</a>
</nav> <a href="<?php echo base_url(); ?>index.php/auth/login" class="in">Log in</a>
</body> <a href="<?php echo base_url(); ?>index.php/auth/logout" class="out">Log Out</a>
</div>
<nav class="main-menu mobile-menu">
<ul>
<li><a href="">About</a></li>
<li><a href="">Contact</a></li>
</ul>
</nav>
</div>
</div>
<div class="container">
<nav>
<ul id="navigation" class="navigation">
<li id="cat_johnnycashreissues" class="cat_level_0">
<a href="">Metal</a>
</li>
<li id="cat_preorders" class="cat_level_0">
<a href="">Pop</a>
</li>
<li id="cat_newreleases" class="cat_level_0">
<a href="">Soundtracks</a>
</li>
<li id="cat_sovexclusives" class="cat_level_0">
<a href="/">Jazz & Classical</a>
</li>
<li id="cat_colouredvinyl" class="cat_level_0">
<a href="/">Soul & RNB</a>
</li>
<li id="cat_limitededition" class="cat_level_0">
<a href="">Hip Hop & Rap</a>
</li>
<li id="cat_merchandise" class="cat_level_0">
<a href="">Compilations</a>
</li>
<li id="cat_genres" class="cat_level_0">
<a class="parent-cat parent-cat-0" href="/">Dance & Electronica</a>
</li>
<li id="cat_sale" class="cat_level_0">
<a class="parent-cat parent-cat-0" href="">Ska + Reggae</a>
</ul>
</nav>
</div>
</header>
<!-- Header Info Begin -->
<script src="<?php echo base_url(); ?>asset/js/jquery-3.3.1.min.js"></script>
<script src="<?php echo base_url(); ?>asset/js/bootstrap.min.js"></script>
</body>
</html> </html>
...@@ -21,7 +21,15 @@ USE `mydb` ; ...@@ -21,7 +21,15 @@ USE `mydb` ;
-- Table `mydb`.`users` -- Table `mydb`.`users`
-- ----------------------------------------------------- -- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`users` ; DROP TABLE IF EXISTS `mydb`.`users` ;
CREATE TABLE IF NOT EXISTS `ci_sessions` (
`id` varchar(128) NOT NULL,
`ip_address` varchar(45) NOT NULL ,
`timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
`data` blob NOT NULL,
KEY `ci_sessions_timestamp` (`timestamp`)
);
ALTER TABLE ci_sessions ADD PRIMARY KEY (id);
CREATE TABLE IF NOT EXISTS `mydb`.`users` ( CREATE TABLE IF NOT EXISTS `mydb`.`users` (
`u_id` INT NULL AUTO_INCREMENT, `u_id` INT NULL AUTO_INCREMENT,
`email` VARCHAR(45) NULL, `email` VARCHAR(45) NULL,
...@@ -34,7 +42,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`users` ( ...@@ -34,7 +42,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`users` (
`zip` VARCHAR(45) NULL, `zip` VARCHAR(45) NULL,
`building` VARCHAR(45) NULL, `building` VARCHAR(45) NULL,
PRIMARY KEY (`u_id`), PRIMARY KEY (`u_id`),
UNIQUE INDEX `username_UNIQUE` (`email` ASC) VISIBLE) UNIQUE INDEX `username_UNIQUE` (`email` ASC) )
ENGINE = InnoDB; ENGINE = InnoDB;
...@@ -64,7 +72,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`cart` ( ...@@ -64,7 +72,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`cart` (
`id` INT NOT NULL AUTO_INCREMENT, `id` INT NOT NULL AUTO_INCREMENT,
`user_id` INT NULL, `user_id` INT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
INDEX `usr_id_idx` (`user_id` ASC) VISIBLE, INDEX `usr_id_idx` (`user_id` ASC) ,
CONSTRAINT `usr_id` CONSTRAINT `usr_id`
FOREIGN KEY (`user_id`) FOREIGN KEY (`user_id`)
REFERENCES `mydb`.`users` (`u_id`) REFERENCES `mydb`.`users` (`u_id`)
...@@ -83,7 +91,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`prod_in_cart` ( ...@@ -83,7 +91,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`prod_in_cart` (
`c_id` INT NOT NULL, `c_id` INT NOT NULL,
`p_id` INT NOT NULL, `p_id` INT NOT NULL,
PRIMARY KEY (`c_id`, `p_id`), PRIMARY KEY (`c_id`, `p_id`),
INDEX `p_id_fk_idx` (`p_id` ASC) VISIBLE, INDEX `p_id_fk_idx` (`p_id` ASC) ,
CONSTRAINT `c_id_fk` CONSTRAINT `c_id_fk`
FOREIGN KEY (`c_id`) FOREIGN KEY (`c_id`)
REFERENCES `mydb`.`cart` (`id`) REFERENCES `mydb`.`cart` (`id`)
...@@ -120,8 +128,8 @@ CREATE TABLE IF NOT EXISTS `mydb`.`transaction` ( ...@@ -120,8 +128,8 @@ CREATE TABLE IF NOT EXISTS `mydb`.`transaction` (
`id_status` INT NULL, `id_status` INT NULL,
`t_time` DATE NULL, `t_time` DATE NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
INDEX `id_user_fk_idx` (`id_user` ASC) VISIBLE, INDEX `id_user_fk_idx` (`id_user` ASC) ,
INDEX `id_status_fk_idx` (`id_status` ASC) VISIBLE, INDEX `id_status_fk_idx` (`id_status` ASC) ,
CONSTRAINT `id_user_fk` CONSTRAINT `id_user_fk`
FOREIGN KEY (`id_user`) FOREIGN KEY (`id_user`)
REFERENCES `mydb`.`users` (`u_id`) REFERENCES `mydb`.`users` (`u_id`)
...@@ -146,7 +154,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`trans_products` ( ...@@ -146,7 +154,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`trans_products` (
`num_of_pr` INT NULL, `num_of_pr` INT NULL,
`price` FLOAT(5,2) NULL, `price` FLOAT(5,2) NULL,
PRIMARY KEY (`id_trans`, `id_prod`), PRIMARY KEY (`id_trans`, `id_prod`),
INDEX `id_prod_fk_idx` (`id_prod` ASC) VISIBLE, INDEX `id_prod_fk_idx` (`id_prod` ASC) ,
CONSTRAINT `id_trans_fk` CONSTRAINT `id_trans_fk`
FOREIGN KEY (`id_trans`) FOREIGN KEY (`id_trans`)
REFERENCES `mydb`.`transaction` (`id`) REFERENCES `mydb`.`transaction` (`id`)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment