Less use of Binput::all()

This commit is contained in:
James Brooks
2015-08-31 19:32:06 +01:00
parent 75588db98e
commit 60e9a64a3e
2 changed files with 19 additions and 20 deletions

View File

@@ -96,19 +96,18 @@ class TeamController extends Controller
*/
public function postUpdateUser(User $user)
{
$items = Binput::all();
$passwordChange = array_get($items, 'password');
if (trim($passwordChange) === '') {
unset($items['password']);
}
$userData = array_filter(Binput::only([
'username',
'email',
'password',
'level',
]));
try {
$user->update($items);
$user->update($userData);
} catch (ValidationException $e) {
return Redirect::route('dashboard.team.edit', ['id' => $user->id])
->withInput(Binput::except('password'))
->withInput($userData)
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))
->withErrors($e->getMessageBag());
}

View File

@@ -40,27 +40,27 @@ class UserController extends Controller
*/
public function postUser()
{
$items = Binput::all();
$userData = array_filter(Binput::only([
'username',
'email',
'password',
'google2fa',
]));
$passwordChange = array_get($items, 'password');
$enable2FA = (bool) array_pull($items, 'google2fa');
$enable2FA = (bool) array_pull($userData, 'google2fa');
// Let's enable/disable auth
if ($enable2FA && !Auth::user()->hasTwoFactor) {
$items['google_2fa_secret'] = Google2FA::generateSecretKey();
$userData['google_2fa_secret'] = Google2FA::generateSecretKey();
} elseif (!$enable2FA) {
$items['google_2fa_secret'] = '';
}
if (trim($passwordChange) === '') {
unset($items['password']);
$userData['google_2fa_secret'] = '';
}
try {
Auth::user()->update($items);
Auth::user()->update($userData);
} catch (ValidationException $e) {
return Redirect::route('dashboard.user')
->withInput(Binput::except('password'))
->withInput($userData)
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))
->withErrors($e->getMessageBag());
}