Skip to content

Commit e159d54

Browse files
committed
Forgot password
1 parent 461998f commit e159d54

15 files changed

Lines changed: 386 additions & 105 deletions

File tree

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
1-
# Codeigniter Admin Panel ( Startup Kit )
1+
# CI Admin ( Startup Kit )
22

3-
[![](https://user-images.githubusercontent.com/6220995/72037880-95b78580-32c5-11ea-994c-8165e8a717e6.png)](https://user-images.githubusercontent.com/6220995/72037880-95b78580-32c5-11ea-994c-8165e8a717e6.png)
3+
CI Admin is Powerfull Codeigniter Admin Panel for starting a new project with Codeigniter Framework. It is developed for custom CodeIgniter projects. It’s cover most common features that needed for nowadays project. It will make your development task more easier then before. We are working hard to create many free features on this project.
4+
5+
The main objective is to speed up web development effort by providing configurable and ready modules. Configurations can be made easily using the Control Panel, or programmatically. Use Admin Lite Admin Panel to create your own web application with the following benefits.
6+
7+
[![](https://user-images.githubusercontent.com/6220995/72045524-4df02880-32dc-11ea-8fec-3d76a7a4f891.png)](https://user-images.githubusercontent.com/6220995/72045524-4df02880-32dc-11ea-8fec-3d76a7a4f891.png)
48

59
### Features
610

711
- Support Laravel equivalent
812
- Support Route naming conventions
913
- User Login Registration
1014
- Forget Password
11-
15+
- Message Helpers (success., info, warning, error)
16+
- Responsive Design With Bootstrap based HTML template.
17+
- Pagination
18+
- Secure Authentication
19+
- Structured & Clean Code
1220

1321
### Installation
1422

15-
git clone https://github.com/jaydeepakbari/Codeigniter-Admin-Panel.git
16-
cd Codeigniter-Admin-Panel
23+
git clone https://github.com/jaydeepakbari/CI-admin.git
24+
cd CI-admin
1725
composer install
1826

1927
### Database SQL
2028

2129
Find file inside database folder and import in your project database
2230

2331
### Default Admin Login
24-
32+
`Username : [email protected] Password : 111111`
2533

26-
### Credits
34+
### Libraries used :
2735

2836
- [ingeniasoftware/luthier-ci](https://github.com/ingeniasoftware/luthier-ci "ingeniasoftware/luthier-ci")
2937
- [tabler/tabler](https://github.com/tabler/tabler "tabler/tabler")

application/config/email.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php defined('BASEPATH') OR exit('No direct script access allowed');
2+
3+
$config = array(
4+
'protocol' => 'smtp', // 'mail', 'sendmail', or 'smtp'
5+
'smtp_host' => 'smtp.example.com',
6+
'smtp_port' => 465,
7+
'smtp_user' => '[email protected]',
8+
'smtp_pass' => '12345!',
9+
'smtp_crypto' => 'ssl', //can be 'ssl' or 'tls' for example
10+
'mailtype' => 'text', //plaintext 'text' mails or 'html'
11+
'smtp_timeout' => '4', //in seconds
12+
'charset' => 'iso-8859-1',
13+
'wordwrap' => TRUE
14+
);

application/controllers/admin/Authentication.php

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
defined('BASEPATH') OR exit('No direct script access allowed');
33
use Model\User;
4+
use Model\PasswordReset;
5+
46

57
class Authentication extends CI_Controller {
68
public function index(){
@@ -9,7 +11,20 @@ public function index(){
911
redirect(route('admin.dashboard'));
1012
}
1113

12-
$this->load->view('admin/auth/login');
14+
View::load('admin/auth/login',[],'auth');
15+
}
16+
17+
public function forget_form(){
18+
if(Auth::check()){ redirect(route('admin.dashboard')); }
19+
20+
View::load('admin/auth/forgot-email',[],'auth');
21+
}
22+
23+
public function reset_password_form($token){
24+
if(Auth::check()){ redirect(route('admin.dashboard')); }
25+
26+
$data['token'] = $token;
27+
View::load('admin/auth/reset-password',$data,'auth');
1328
}
1429

1530
public function logout(){
@@ -35,7 +50,7 @@ public function check_login(){
3550
} else if(!$user->status){
3651
$json['errors']['email'] = 'User must be active for login';
3752
} else if(!bcrypt_check($data['password'], $user->password)){
38-
$json['errors']['email'] = 'User must be active for login';
53+
$json['errors']['email'] = 'Invalid Email Address or Password';
3954
} else {
4055
$this->session->set_userdata('login_admin', $user->id);
4156
$json['redirect'] = route("admin.dashboard");
@@ -44,4 +59,98 @@ public function check_login(){
4459

4560
View::json($json);
4661
}
62+
63+
public function forget_form_check(){
64+
$json = array();
65+
66+
$this->form_validation->set_rules('email', 'Email Address', 'required');
67+
$data = $this->input->post(NULL,true);
68+
if($this->form_validation->run() == FALSE){
69+
$json['errors'] = $this->form_validation->error_array();
70+
}
71+
72+
if (!isset($json['errors'])) {
73+
$user = User::where("email","like",$data['email'])->first();
74+
if(!$user){
75+
$json['errors']['email'] = 'Invalid Email Address or Password';
76+
} else if(!$user->status){
77+
$json['errors']['email'] = 'User must be active for reset password';
78+
} else {
79+
PasswordReset::where('email','like',$this->input->post('email') )->delete();
80+
81+
$newToken = new PasswordReset();
82+
$newToken->token = token(20);
83+
$newToken->email = $this->input->post('email');
84+
$newToken->save();
85+
86+
$this->load->config('email');
87+
$this->load->library('email');
88+
89+
$from = $this->config->item('smtp_user');
90+
$to = $this->input->post('email');
91+
$subject = 'Reset Password Notification';
92+
$message = "<p>Hello!</p><br>
93+
<p>You are receiving this email because we received a password reset request for your account.</p>
94+
95+
<a href='". route('admin.reset_password_form',['token' => $newToken->token]) ."'>Reset Password</a>
96+
<p>This password reset link will expire in 60 minutes.</p>
97+
98+
<p>If you did not request a password reset, no further action is required.</p>
99+
100+
<br>
101+
<b>Thanks</b>
102+
";
103+
104+
$this->email->set_newline("\r\n");
105+
$this->email->from($from);
106+
$this->email->to($to);
107+
$this->email->subject($subject);
108+
$this->email->message($message);
109+
110+
111+
if ($this->email->send()) {
112+
set_message('success', 'An email has been sent to your email address. Please check its inbox to continue reseting password.');
113+
$json['redirect'] = route('admin.forget_form');
114+
} else {
115+
show_error($this->email->print_debugger());
116+
}
117+
}
118+
}
119+
120+
View::json($json);
121+
}
122+
123+
public function reset_password_check(){
124+
$json = array();
125+
126+
$this->form_validation->set_rules('password', 'Password', 'required');
127+
$this->form_validation->set_rules('token', 'token', 'required');
128+
$this->form_validation->set_rules('c_password', 'Confirm Password', 'required|matches[password]');
129+
130+
$data = $this->input->post(NULL,true);
131+
if($this->form_validation->run() == FALSE){
132+
$json['errors'] = $this->form_validation->error_array();
133+
}
134+
135+
if (!isset($json['errors'])) {
136+
$token = PasswordReset::where('token',$data['token'])->first();
137+
if(!$token){
138+
$json['errors']['password'] = 'Invalid token..';
139+
} else{
140+
$user = User::where('email',$token->email)->first();
141+
if(!$user){
142+
$json['errors']['password'] = 'Invalid token..';
143+
} else {
144+
$user->password = bcrypt_hash($data['password']);
145+
$user->save();
146+
147+
set_message('success', 'Password reset successfully');
148+
PasswordReset::where('email','like',$user->email )->delete();
149+
$json['redirect'] = route('admin.login');
150+
}
151+
}
152+
}
153+
154+
View::json($json);
155+
}
47156
}

application/controllers/admin/UserController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function submit_form($user_id = 0){
5555
}
5656

5757
$user->save();
58+
set_message('success', 'User save successfully');
5859
$json['redirect'] = route("admin.user.list");
5960
}
6061

@@ -64,6 +65,7 @@ public function submit_form($user_id = 0){
6465

6566
public function destory($user_id){
6667
User::where("id",$user_id)->delete();
68+
set_message('success', 'User deleted successfully');
6769
redirect(route('admin.user.list'));
6870
}
6971

@@ -73,6 +75,8 @@ public function destory_multiple(){
7375
if(is_array($ids) && $ids){
7476
User::whereIn("id",$ids)->delete();
7577
}
78+
79+
set_message('success', 'User deleted successfully');
7680
redirect(route('admin.user.list'));
7781
}
7882
}

application/core/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public static function user(){
2020

2121
public static function check(){
2222
self::initClass();
23-
return self::$user->id > 0;
23+
return (self::$user && self::$user->id) > 0 ? true : false;
2424
}
2525
}

application/helpers/util_helper.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ function makePaginate(&$query, $config){
4040
$query->paginate = $ci->pagination->create_links();
4141
}
4242

43+
function set_message($type, $message){
44+
$ci = &get_instance();
45+
$ci->session->set_flashdata($type, $message);
46+
}
47+
4348
function bcrypt_hash($password, $work_factor = 8){
4449
if (! function_exists('openssl_random_pseudo_bytes')) {
4550
throw new Exception('Bcrypt requires openssl PHP extension');
@@ -66,4 +71,10 @@ function bcrypt_check($password, $stored_hash, $legacy_handler = NULL){
6671
return crypt($password, $stored_hash) == $stored_hash;
6772
}
6873

69-
function bcrypt_is_legacy_hash($hash) { return substr($hash, 0, 4) != '$2a$'; }
74+
function bcrypt_is_legacy_hash($hash) { return substr($hash, 0, 4) != '$2a$'; }
75+
76+
function token($length_of_string=10){
77+
$str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
78+
79+
return substr(str_shuffle($str_result),0, $length_of_string);
80+
}

application/helpers/view_helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
class View{
33
function __construct(){}
44

5-
public static function load($file, $data = array()){
5+
public static function load($file, $data = array(), $layout = 'dashboard'){
66
$ci = &get_instance();
77
$data['content'] = $ci->load->view($file, $data, true);
88

9-
$ci->load->view('admin/layout/dashboard', $data);
9+
$ci->load->view('admin/layout/'. $layout, $data);
1010
}
1111

1212
public static function json($json = array()){
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace Model;
3+
use \Illuminate\Database\Eloquent\Model as Eloquent;
4+
5+
class PasswordReset extends Eloquent {
6+
const UPDATED_AT = null;
7+
}

application/routes/web.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
/* BACKEND ROUTES */
88
Route::get('/admin/login', 'admin/Authentication@index')->name('admin.login');
99
Route::get('/admin/logout', 'admin/Authentication@logout')->name('admin.logout');
10-
Route::post('/admin/login', 'admin/Authentication/check_login@index')->name('admin.check_login');
10+
Route::post('/admin/login', 'admin/Authentication@check_login')->name('admin.check_login');
11+
Route::get('/admin/forgot-password', 'admin/Authentication@forget_form')->name('admin.forget_form');
12+
Route::post('/admin/forgot-password', 'admin/Authentication@forget_form_check')->name('admin.forget_form_check');
13+
Route::get('/admin/reset-password/{token}', 'admin/Authentication@reset_password_form')->name('admin.reset_password_form');
14+
Route::post('/admin/reset-password', 'admin/Authentication@reset_password_check')->name('admin.reset_password_check');
1115

1216
Route::group('admin',['namespace' => 'admin','middleware' => ['CheckIfLogin']], function(){
1317
Route::get('/', 'dashboard@index')->name('admin.dashboard');
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<div class="d-flex h-auto min-h-full justify-content-center">
2+
<div class="d-flex align-items-center justify-content-center flex-fill">
3+
<div class="container">
4+
<div class="row">
5+
<div class="col col-login mx-auto">
6+
<div class="text-center mb-4 mt-4">
7+
<img src="<?= base_url('assets/admin/img/logo-black.png') ?>" class="w-50" alt="">
8+
</div>
9+
<?php if($message = $this->session->flashdata('success')){ ?>
10+
<div class="alert alert-success alert-dismissible" role='alert'>
11+
<h3>Email Sent!</h3>
12+
<p><?= $message ?></p>
13+
</div>
14+
<?php } ?>
15+
<form class="card" action="<?= route('admin.forget_form_check') ?>" id="forgot_form" method="post">
16+
17+
<div class="card-body p-5">
18+
<div class="card-title">Forgot password</div>
19+
<p class="text-muted">Enter your email address and your password will be reset and emailed to you.</p>
20+
<div class="mb-2">
21+
<label class="form-label" for="exampleInputEmail1">Email address</label>
22+
<input type="email" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
23+
</div>
24+
<div class="form-footer">
25+
<button type="submit" class="btn btn-submit btn-primary btn-block">Send confirmation link</button>
26+
</div>
27+
</div>
28+
29+
</form>
30+
<div class="text-center text-muted">
31+
Have account yet? <a href="<?= route('admin.login') ?>">Sign in</a>
32+
</div>
33+
</div>
34+
</div>
35+
</div>
36+
</div>
37+
</div>
38+
39+
<script type="text/javascript">
40+
$("#forgot_form").submit(function(){
41+
$this = $(this);
42+
$.ajax({
43+
url:$this.attr("action"),
44+
type:'POST',
45+
dataType:'json',
46+
data:$this.serialize(),
47+
beforeSend:function(){ $this.find('.btn-submit').btn("loading"); },
48+
complete:function(){ $this.find('.btn-submit').btn("reset"); },
49+
success:function(json){
50+
json_callback(json,$this);
51+
},
52+
})
53+
return false;
54+
})
55+
</script>

0 commit comments

Comments
 (0)