From 43fe7c8fa4c1e37bbf92910cb4b7dcfdbcb00573 Mon Sep 17 00:00:00 2001 From: Virgil-Adrian Teaca Date: Sun, 5 Jun 2016 16:54:14 +0200 Subject: [PATCH] Improve the flash Messages management and fixes on Users module --- .../Dashboard/Views/Admin/Dashboard/Index.php | 2 +- app/Modules/Users/Controllers/Admin/Users.php | 30 +++++--- .../Users/Views/Admin/Roles/Create.php | 2 +- app/Modules/Users/Views/Admin/Roles/Edit.php | 2 +- app/Modules/Users/Views/Admin/Roles/Index.php | 2 +- app/Modules/Users/Views/Admin/Roles/Show.php | 2 +- .../Users/Views/Admin/Users/Create.php | 2 +- app/Modules/Users/Views/Admin/Users/Edit.php | 2 +- app/Modules/Users/Views/Admin/Users/Index.php | 2 +- .../Users/Views/Admin/Users/Profile.php | 2 +- .../Users/Views/Admin/Users/Search.php | 2 +- app/Modules/Users/Views/Admin/Users/Show.php | 2 +- app/Modules/Users/Views/Authorize/Login.php | 2 +- app/Modules/Users/Views/Authorize/Remind.php | 2 +- app/Modules/Users/Views/Authorize/Reset.php | 2 +- system/Http/RedirectResponse.php | 4 +- system/Support/Facades/Session.php | 70 +++++++++++++++++-- 17 files changed, 102 insertions(+), 30 deletions(-) diff --git a/app/Modules/Dashboard/Views/Admin/Dashboard/Index.php b/app/Modules/Dashboard/Views/Admin/Dashboard/Index.php index af194d0df5..e1a6221ebd 100644 --- a/app/Modules/Dashboard/Views/Admin/Dashboard/Index.php +++ b/app/Modules/Dashboard/Views/Admin/Dashboard/Index.php @@ -8,7 +8,7 @@
- +
diff --git a/app/Modules/Users/Controllers/Admin/Users.php b/app/Modules/Users/Controllers/Admin/Users.php index a032824f98..6752ac4776 100644 --- a/app/Modules/Users/Controllers/Admin/Users.php +++ b/app/Modules/Users/Controllers/Admin/Users.php @@ -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 {0} was successfully created.', $input['username']); @@ -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']; diff --git a/app/Modules/Users/Views/Admin/Roles/Create.php b/app/Modules/Users/Views/Admin/Roles/Create.php index acf1552f73..6b97aae595 100644 --- a/app/Modules/Users/Views/Admin/Roles/Create.php +++ b/app/Modules/Users/Views/Admin/Roles/Create.php @@ -10,7 +10,7 @@
- +
diff --git a/app/Modules/Users/Views/Admin/Roles/Edit.php b/app/Modules/Users/Views/Admin/Roles/Edit.php index 47494749bf..5de38a819d 100644 --- a/app/Modules/Users/Views/Admin/Roles/Edit.php +++ b/app/Modules/Users/Views/Admin/Roles/Edit.php @@ -24,7 +24,7 @@
- +
diff --git a/app/Modules/Users/Views/Admin/Roles/Index.php b/app/Modules/Users/Views/Admin/Roles/Index.php index 1207ff5aba..e771e45afc 100644 --- a/app/Modules/Users/Views/Admin/Roles/Index.php +++ b/app/Modules/Users/Views/Admin/Roles/Index.php @@ -9,7 +9,7 @@
- +
diff --git a/app/Modules/Users/Views/Admin/Roles/Show.php b/app/Modules/Users/Views/Admin/Roles/Show.php index 8c1f1ebadd..9f073d9709 100644 --- a/app/Modules/Users/Views/Admin/Roles/Show.php +++ b/app/Modules/Users/Views/Admin/Roles/Show.php @@ -10,7 +10,7 @@
- +
diff --git a/app/Modules/Users/Views/Admin/Users/Create.php b/app/Modules/Users/Views/Admin/Users/Create.php index c489ef8cb2..1a8353be71 100644 --- a/app/Modules/Users/Views/Admin/Users/Create.php +++ b/app/Modules/Users/Views/Admin/Users/Create.php @@ -16,7 +16,7 @@
- +
diff --git a/app/Modules/Users/Views/Admin/Users/Edit.php b/app/Modules/Users/Views/Admin/Users/Edit.php index 90a6f46e74..2623ed494d 100644 --- a/app/Modules/Users/Views/Admin/Users/Edit.php +++ b/app/Modules/Users/Views/Admin/Users/Edit.php @@ -26,7 +26,7 @@
- +
diff --git a/app/Modules/Users/Views/Admin/Users/Index.php b/app/Modules/Users/Views/Admin/Users/Index.php index d6a61924e3..9b25cb7549 100644 --- a/app/Modules/Users/Views/Admin/Users/Index.php +++ b/app/Modules/Users/Views/Admin/Users/Index.php @@ -9,7 +9,7 @@
- +
diff --git a/app/Modules/Users/Views/Admin/Users/Profile.php b/app/Modules/Users/Views/Admin/Users/Profile.php index 3a25f51d26..d302e26a93 100644 --- a/app/Modules/Users/Views/Admin/Users/Profile.php +++ b/app/Modules/Users/Views/Admin/Users/Profile.php @@ -10,7 +10,7 @@
- +
diff --git a/app/Modules/Users/Views/Admin/Users/Search.php b/app/Modules/Users/Views/Admin/Users/Search.php index b9e36b6a31..b3d758d5f5 100644 --- a/app/Modules/Users/Views/Admin/Users/Search.php +++ b/app/Modules/Users/Views/Admin/Users/Search.php @@ -10,7 +10,7 @@
- +
diff --git a/app/Modules/Users/Views/Admin/Users/Show.php b/app/Modules/Users/Views/Admin/Users/Show.php index 1c1403501e..5dd0bbfb0f 100644 --- a/app/Modules/Users/Views/Admin/Users/Show.php +++ b/app/Modules/Users/Views/Admin/Users/Show.php @@ -10,7 +10,7 @@
- +
diff --git a/app/Modules/Users/Views/Authorize/Login.php b/app/Modules/Users/Views/Authorize/Login.php index 51c5bf0cc1..baa9d09cc3 100644 --- a/app/Modules/Users/Views/Authorize/Login.php +++ b/app/Modules/Users/Views/Authorize/Login.php @@ -6,7 +6,7 @@
- +
diff --git a/app/Modules/Users/Views/Authorize/Remind.php b/app/Modules/Users/Views/Authorize/Remind.php index 93e6b01d43..a034615072 100644 --- a/app/Modules/Users/Views/Authorize/Remind.php +++ b/app/Modules/Users/Views/Authorize/Remind.php @@ -9,7 +9,7 @@
{0}', SITETITLE); ?>
- +
diff --git a/app/Modules/Users/Views/Authorize/Reset.php b/app/Modules/Users/Views/Authorize/Reset.php index 06f4375e16..91ccf7c9f5 100644 --- a/app/Modules/Users/Views/Authorize/Reset.php +++ b/app/Modules/Users/Views/Authorize/Reset.php @@ -9,7 +9,7 @@
- + diff --git a/system/Http/RedirectResponse.php b/system/Http/RedirectResponse.php index 38ee6c1304..8730b7512a 100644 --- a/system/Http/RedirectResponse.php +++ b/system/Http/RedirectResponse.php @@ -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; } /** diff --git a/system/Support/Facades/Session.php b/system/Support/Facades/Session.php index 173e25d6e8..7eef7c62b8 100644 --- a/system/Support/Facades/Session.php +++ b/system/Support/Facades/Session.php @@ -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 {