Skip to content

Commit

Permalink
Merge pull request #940 from LuckyCyborg/master
Browse files Browse the repository at this point in the history
Improve the flash Messages management and fixes on Users module
  • Loading branch information
daveismynamecom committed Jun 5, 2016
2 parents e907dc6 + 6a8c617 commit 46a0cee
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/Modules/Dashboard/Views/Admin/Dashboard/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!-- Main content -->
<section class="content">

<?= Session::message('status'); ?>
<?= Session::getMessages(); ?>

<div class="box box-widget">
<div class="box-body">
Expand Down
30 changes: 21 additions & 9 deletions app/Modules/Users/Controllers/Admin/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,30 @@ public function store()
$validator = $this->validate($input);

if($validator->passes()) {
unset($input['password_confirmation']);

// Encrypt the Password.
$input['password'] = Hash::make($input['password']);
// Encrypt the given Password.
$password = Hash::make($input['password']);

// Create a User Model instance - used with the Extended Auth Driver.
User::create($input);
User::create(array(
'username' => $input['username'],
'password' => $password,
'role_id' => $input['role'],
'realname' => $input['realname'],
'email' => $input['email'],
));

// Create a User Model instance - used with the Database Auth Driver.
// $input['created_at'] = $input['created_at'] = new Carbon();
//
//$this->model->insert($input);
/*
$this->model->insert(rray(
'username' => $input['username'],
'password' => $password,
'role_id' => $input['role'],
'realname' => $input['realname'],
'email' => $input['email'],
'created_at' => new Carbon(),
'updated_at' => new Carbon(),
));
*/

// Prepare the flash message.
$status = __('The User <b>{0}</b> was successfully created.', $input['username']);
Expand Down Expand Up @@ -247,7 +259,7 @@ public function update($id)

// Update the User Model instance.
$user->username = $input['username'];
$user->role = $input['role'];
$user->role_id = $input['role'];
$user->realname = $input['realname'];
$user->email = $input['email'];

Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Views/Admin/Roles/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!-- Main content -->
<section class="content">

<?= Session::message('status'); ?>
<?= Session::getMessages(); ?>

<div class="box box-default">
<div class="box-header with-border">
Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Views/Admin/Roles/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<!-- Main content -->
<section class="content">

<?= Session::message('status'); ?>
<?= Session::getMessages(); ?>

<div class="box box-default">
<div class="box-header with-border">
Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Views/Admin/Roles/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- Main content -->
<section class="content">

<?= Session::message('status'); ?>
<?= Session::getMessages(); ?>

<div class="box box-default">
<div class="box-header with-border">
Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Views/Admin/Roles/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!-- Main content -->
<section class="content">

<?= Session::message('status'); ?>
<?= Session::getMessages(); ?>

<div class="box box-widget">
<div class="box-header with-border">
Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Views/Admin/Users/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<!-- Main content -->
<section class="content">

<?= Session::message('status'); ?>
<?= Session::getMessages(); ?>

<div class="box box-default">
<div class="box-header with-border">
Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Views/Admin/Users/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<!-- Main content -->
<section class="content">

<?= Session::message('status'); ?>
<?= Session::getMessages(); ?>

<div class="box box-default">
<div class="box-header with-border">
Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Views/Admin/Users/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- Main content -->
<section class="content">

<?= Session::message('status'); ?>
<?= Session::getMessages(); ?>

<div class="box box-default">
<div class="box-header with-border">
Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Views/Admin/Users/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!-- Main content -->
<section class="content">

<?= Session::message('status'); ?>
<?= Session::getMessages(); ?>

<div class="box box-default">
<div class="box-header with-border">
Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Views/Admin/Users/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!-- Main content -->
<section class="content">

<?= Session::message('status'); ?>
<?= Session::getMessages(); ?>

<div class="box box-default">
<div class="box-header with-border">
Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Views/Admin/Users/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!-- Main content -->
<section class="content">

<?= Session::message('status'); ?>
<?= Session::getMessages(); ?>

<div class="box box-widget">
<div class="box-header with-border">
Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Views/Authorize/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<section class="content">

<div class="row">
<?php echo Session::message('status');?>
<?php echo Session::getMessages();?>

<div style="margin-top: 50px" class="col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
<div class="panel panel-primary" >
Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Views/Authorize/Remind.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="panel-title"><?= __d('users', 'Reset your password for <b>{0}</b>', SITETITLE); ?></div>
</div>
<div style="padding-top: 30px" class="panel-body" >
<?= Session::message('status'); ?>
<?= Session::getMessages(); ?>

<form method='post' role="form">

Expand Down
2 changes: 1 addition & 1 deletion app/Modules/Users/Views/Authorize/Reset.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="panel-title"><?= __d('users', 'Password Reset'); ?></div>
</div>
<div class="panel-body">
<?= Session::message('status'); ?>
<?= Session::getMessages(); ?>

<form method='post' action="<?= site_url('password/reset'); ?>" role="form">

Expand Down
4 changes: 3 additions & 1 deletion system/Http/RedirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ public function withStatus($message, $type = 'success')
{
$status = array('type' => $type, 'text' => $message);

return $this->with('status', $status);
$this->session->push('status', $status);

return $this;
}

/**
Expand Down
70 changes: 64 additions & 6 deletions system/Support/Facades/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,25 +282,83 @@ public static function instance()
}

/**
* Display a one time Message, then clear it from the Session.
* Flash a array containing a message to the session.
*
* @param string $message
* @param string $type
*
* @return \Http\RedirectResponse
*/
public static function pushStatus($message, $type = 'success')
{
$instance = static::getSessionStore();

$status = array('type' => $type, 'text' => $message);

// Push the status on Session.
$instance->push('status', $status);
}

/**
* Display the one time Messages, then clear them from the Session.
*
* @param string $name default Session name
*
* @return string
*/
public static function message($name = 'success')
public static function getMessages()
{
$instance = static::getSessionStore();

if (! $instance->has($name)) {
if (! $instance->has('status')) {
return null;
}

// Pull the Message from the Session Store.
$message = $instance->remove($name);
$messages = $instance->remove('status');

if (is_array($message)) {
// The Message is structured in the New Style.
//
$content = null;

foreach ($messages as $message) {
$content .= static::createMessage($message);
}

return $content;
}

/**
* Display a one time Message, then clear it from the Session.
*
* @param string $name default Session name
*
* @return string
*/
public static function message($name = null)
{
$instance = static::getSessionStore();

if(is_null($name)) {
foreach (array('info', 'success', 'warning', 'danger') as $key) {
if ($instance->has($key)) {
$name = $key;

break;
}
}
}

if (! is_null($name) && $instance->has($name)) {
// Pull the Message from the Session Store.
$message = $instance->remove($name);

return static::createMessage($message, $name);
}
}

protected static function createMessage($message, $name = null)
{
if(is_array($message)) {
$type = $message['type'];
$message = $message['text'];
} else {
Expand Down

0 comments on commit 46a0cee

Please sign in to comment.