Skip to content

Commit

Permalink
working on flash message
Browse files Browse the repository at this point in the history
  • Loading branch information
Halim authored and Halim committed Nov 8, 2016
1 parent c884fd3 commit 102b32f
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 41 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Articles2Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Articles2Controller extends Controller {
*/

public function __construct() {

$this->middleware('auth');
}

/**
Expand Down
7 changes: 7 additions & 0 deletions app/Http/Controllers/ArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public function store(Requests\ArticleRequest $request) {
$request['users_id'] = Auth::id();
Article::create($request->all());

//Session::flash('flash_message', 'Article has been created!');
flash()->success('Article has been created!');

return redirect('articles');
}

Expand All @@ -112,6 +115,8 @@ public function edit($id) {
public function update($id, Requests\ArticleRequest $request) {
$article = Article::findOrFail($id);
$article->update($request->all());

flash()->success('Article has been updated!');
return redirect('articles');
}

Expand All @@ -124,6 +129,8 @@ public function update($id, Requests\ArticleRequest $request) {
public function destroy($id) {
$article = Article::findOrFail($id);
$article->delete();

flash()->success('Article has been deleted!');
return redirect('articles');
}

Expand Down
62 changes: 47 additions & 15 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
class LoginController extends Controller {
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/

use AuthenticatesUsers;
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/

use AuthenticatesUsers;

/**
* Where to redirect users after login.
Expand All @@ -28,13 +28,45 @@ class LoginController extends Controller
protected $redirectTo = '/home';
protected $redirectAfterLogout = '/login';

// protected $redirectAfterLogout = 'auth/login';

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
public function __construct() {
$this->middleware('guest', ['except' => 'logout']);
}

/**
* Log the user out of the application.
*
*/
public function logout() {
//Illuminate\Support\Facades\Auth::logout();
Auth::logout();
//Session::flash('success', 'You have been successfully logged out!');
flash()->info('Bye', 'You have been successfully logged out!');
return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}

/**
* Log the user out of the application.
*
*/
public function login00000() {
flash()->info('Welcome', 'Welcome you login');
return redirect(property_exists($this, 'redirectTo') ? $this->redirectTo : '/dashboard');
}

// somewhere in controller

public function authenticated($request, $user) {

//flash('Welcome back ' . $user->username . ', you have been logged in');
flash()->overlay('Welcome back ' . $user->username . ', you have been logged in');

}

}
21 changes: 10 additions & 11 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ProfileController extends Controller {
*/

public function __construct() {

$this->middleware('auth');
}

/**
Expand Down Expand Up @@ -62,7 +62,9 @@ public function update() {
]);
*/

flash('Your profile has been updated!')->important();
//flash('Your profile has been updated!');
//flash()->success('Your profile has been updated!');
flash()->overlay('Your profile has been updated!', 'Good Job');

return redirect('profile');

Expand Down Expand Up @@ -98,22 +100,19 @@ public function change_password() {
return back()->withErrors($validator)->withInput();
}
else {
/*if (!$hasher->check($oldPassword, $user->password) || $password != $passwordConf) {
Session::flash('error', 'Check input is correct.');
return View::make('passwords/reset');
}*/
//if (Hash::check($current_password, $user->password) && $user_count == 1) {

//if (Hash::check($current_password, $user->password) && $user_count == 1) {

if(!Hash::check($old_password, $user->password)){
//die('machi kif kif');
Session::flash('error', 'The old password is incorect');
//Session::flash('error', 'The old password is incorect');
flash()->error('The old password is incorect!');

return redirect('password');
}

$password = bcrypt(Request::get('password'));
$user->update(['password' => $password]);

flash()->success('Your password has been updated!');

return redirect('password');
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SettingsController extends Controller {
*/

public function __construct() {

$this->middleware('auth');
}

/**
Expand Down
15 changes: 13 additions & 2 deletions app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//use Illuminate\Support\Facades\Redirect;
//use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Validator;
use Session;

class UsersController extends Controller {
/*
Expand Down Expand Up @@ -51,6 +52,7 @@ public function store(Requests\UsersRequest $request) {
$request['password'] = bcrypt($request['password']);
User::create($request->all());

Session::flash('flash_message', 'User has been created!');
return redirect('users');
}

Expand Down Expand Up @@ -140,9 +142,12 @@ public function show($id) {
public function destroy($id) {
$user = User::findOrFail($id);

//dd($user);

$user->delete();

Session::flash('flash_message', 'User has been deleted!');
//Session::flash('flash_message_important', true);
//Session::flash('error', 'The old password is incorect');

return redirect('users');
}

Expand Down Expand Up @@ -176,6 +181,8 @@ public function update($id) {
}
else {
$user->update(Request::all());

Session::flash('flash_message', 'User has been updated!');
//return Redirect::to('users');
return redirect('users');
}
Expand Down Expand Up @@ -228,6 +235,10 @@ public function update_password($id) {
$user->update(['password' => $password]);
//return Redirect::to('users');
//return redirect('users');

//Session::flash('flash_message', 'Password has been reseted!');
flash()->info('Password has been reseted!');

return view('users.reset_password', compact('user'));
}
}
Expand Down
2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@

'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,

'Flash' => Laracasts\Flash\Flash::class,

],

Expand Down
12 changes: 12 additions & 0 deletions resources/views/includes/flash.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="container">
<div class="col-md-10 col-md-offset-1">
@if(Session::has('flash_message'))
<div class="alert alert-success {{ Session::has('flash_message_important') ? 'alert-important': '' }}">
@if(Session::has('flash_message_important'))
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
@endif
{{ Session::get('flash_message') }}
</div>
@endif
</div>
</div>
14 changes: 5 additions & 9 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,11 @@

<div class="container">
<div class="col-md-10 col-md-offset-1">
@if(Session::has('flash_message'))
<div class="alert alert-success {{ Session::has('flash_message_important') ? 'alert-important': '' }}">
@if(Session::has('flash_message_important'))
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
@endif
{{ Session::get('flash_message') }}
</div>
@endif
@include('flash::message')
</div>
</div>



@yield('content')

Expand All @@ -43,7 +38,8 @@
<script src="/js/app.js"></script>

<script>
$('div.alert').not('.alert-important').delay(1500).slideUp(300);
$('div.alert').not('.alert-important').delay(1500).slideUp(300);
$('#flash-overlay-modal').modal();
</script>

</body>
Expand Down
4 changes: 4 additions & 0 deletions resources/views/users/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<div class="container">
<div class="row">
<div class="col-md-12">

@include('includes.flash')


<h2>Users List <a href="{{ url('users/create') }}" style="float: right;font-size: 18px;">Add User</a></h2>

@if(count($users))
Expand Down
1 change: 1 addition & 0 deletions resources/views/users/reset_password.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">

<div class="panel panel-default">
<div class="panel-heading">Reset Password for user : <strong>{{ $user->username }}</strong>
<a href="{{ url('users') }}" style="float: right;"> Users List</a>
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// autoload.php @generated by Composer

require_once __DIR__ . '/composer' . '/autoload_real.php';
require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInita204dc84e12a110d387420359dd2eee9::getLoader();
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function logout(Request $request)
$request->session()->flush();

$request->session()->regenerate();

die('pass ici');
return redirect('/');
}

Expand Down

0 comments on commit 102b32f

Please sign in to comment.