Skip to content

Commit 5d71d10

Browse files
committed
version 2.0.0 implement a database layer
* now the check will use a model of the user to verify the data of the user and password
1 parent ac48a13 commit 5d71d10

File tree

7 files changed

+102
-3
lines changed

7 files changed

+102
-3
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# codeigniter-webapp
1+
# codeigniter-login
22

33
Login template for codeigniter repo, this project just use session files, the most simple
44

@@ -31,9 +31,14 @@ git clone --recursive https://gitlab.com/codeigniterpower/codeigniter-login
3131

3232
Then enable the site and visit `http://localhost/codeigniter-login`
3333

34+
## Database
35+
36+
Since version 2.0.0 the project need a database connection, use the files
37+
at [webappdb](webappdb) directory.
38+
3439
## Development
3540

36-
Its just 4 files:
41+
The core core process is just 4 files:
3742

3843
```
3944
webappweb The Applicaions directory of Codeigniter renamed
@@ -51,6 +56,9 @@ Its just 4 files:
5156
/inicion.php Login view page for init the sesion process
5257
```
5358

59+
Since version 2.0.0 a database layer will be necessary so an extra file at `webappweb/models/Usersmodel.php`
60+
its necesary to provide functionality
61+
5462
#### Process simple login
5563

5664
This is the main entry controller, it will load the views of login form page

webappdb/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
The DB
3+
4+
![](codeigniter.png)

webappdb/codeigniter.mwb

5.38 KB
Binary file not shown.

webappdb/codeigniter.png

6.59 KB
Loading

webappdb/codeigniter.sql

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
-- phpMyAdmin SQL Dump
2+
-- version 4.7.4
3+
-- https://www.phpmyadmin.net/
4+
--
5+
-- Host: 127.0.0.1
6+
-- Generation Time: Feb 05, 2018 at 07:10 AM
7+
-- Server version: 10.1.28-MariaDB
8+
-- PHP Version: 7.1.10
9+
10+
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
11+
SET AUTOCOMMIT = 0;
12+
START TRANSACTION;
13+
SET time_zone = "+00:00";
14+
15+
16+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
17+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
18+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
19+
/*!40101 SET NAMES utf8mb4 */;
20+
21+
--
22+
-- Database: `codeigniter`
23+
--
24+
25+
-- --------------------------------------------------------
26+
27+
--
28+
-- Table structure for table `users`
29+
--
30+
31+
CREATE TABLE `users` (
32+
`id` int(11) NOT NULL,
33+
`username` varchar(40) NOT NULL,
34+
`userpass` varchar(40) NOT NULL
35+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
36+
37+
--
38+
-- Dumping data for table `users`
39+
--
40+
41+
INSERT INTO `users` (`id`, `username`, `userpass`) VALUES
42+
(1, 'ndevierte@gmail.com', 'nurhodelta'),
43+
(2, 'gemalyn@gmail.com', 'cepe');
44+
45+
--
46+
-- Indexes for dumped tables
47+
--
48+
49+
--
50+
-- Indexes for table `users`
51+
--
52+
ALTER TABLE `users`
53+
ADD PRIMARY KEY (`id`);
54+
55+
--
56+
-- AUTO_INCREMENT for dumped tables
57+
--
58+
59+
--
60+
-- AUTO_INCREMENT for table `users`
61+
--
62+
ALTER TABLE `users`
63+
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
64+
COMMIT;
65+
66+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
67+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
68+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

webappweb/controllers/Indexauth.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ public function auth($action = 'logout', $username = NULL, $userclave = NULL)
3131

3232
if ( $action == 'login' )
3333
{
34-
$rs_access = array('username'=>$username, 'userclave'=>$userclave);
34+
$this->load->model('usersmodel');
35+
$rs_access = $this->usersmodel->login($username, $userclave);
3536
}
3637

3738
$data = array();
3839
$message = 'Invalid login parameters or session ended';
3940
if($rs_access)
4041
{
4142
$message = 'Session initialized';
43+
$viewtitle = 'index at Pagetest';
4244
$data['message'] = $message;
4345
$this->session->set_userdata('userdata', $rs_access);
4446
$this->session->set_flashdata('error',$message);

webappweb/models/Usersmodel.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
class Usersmodel extends CI_Model
3+
{
4+
function __construct()
5+
{
6+
parent::__construct();
7+
$this->load->database();
8+
}
9+
10+
public function login($username, $password)
11+
{
12+
$query = $this->db->get_where('users', array('username'=>$username, 'userpass'=>$password));
13+
return $query->row_array();
14+
}
15+
16+
}
17+
?>

0 commit comments

Comments
 (0)