Cachet/src/Http/Controllers/DashUserController.php

68 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace CachetHQ\Cachet\Http\Controllers;
2015-01-01 15:45:04 +00:00
2015-01-03 17:51:35 +00:00
use CachetHQ\Cachet\Models\User;
2015-01-02 12:05:50 +00:00
use GrahamCampbell\Binput\Facades\Binput;
2015-01-01 16:18:24 +00:00
use Illuminate\Routing\Controller;
2015-01-01 15:45:04 +00:00
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
use PragmaRX\Google2FA\Vendor\Laravel\Facade as Google2FA;
2015-01-01 15:45:04 +00:00
class DashUserController extends Controller
{
/**
* Shows the user view.
2014-12-29 23:07:46 +00:00
*
* @return \Illuminate\View\View
*/
public function showUser()
{
2015-01-01 10:39:22 +00:00
return View::make('dashboard.user.index')->with([
'pageTitle' => trans('dashboard.team.profile').' - '.trans('dashboard.dashboard'),
]);
}
/**
2014-12-21 10:19:18 +00:00
* Updates the current user.
2014-12-29 23:07:46 +00:00
*
* @return \Illuminate\View\View
*/
public function postUser()
{
2015-01-02 12:05:50 +00:00
$items = Binput::all();
2015-01-09 14:21:53 -06:00
$passwordChange = array_get($items, 'password');
$enable2FA = (bool) array_pull($items, 'google2fa');
// Let's enable/disable auth
2015-01-09 14:21:53 -06:00
if ($enable2FA && ! Auth::user()->hasTwoFactor) {
$items['google_2fa_secret'] = Google2FA::generateSecretKey();
} elseif (! $enable2FA) {
$items['google_2fa_secret'] = '';
}
if (trim($passwordChange) === '') {
unset($items['password']);
}
$updated = Auth::user()->update($items);
return Redirect::back()->with('updated', $updated);
}
2015-01-03 17:51:35 +00:00
/**
* Regenerates the users API key.
*
* @return \Illuminate\View\View
*/
public function regenerateApiKey(User $user)
{
$user->api_key = User::generateApiKey();
$user->save();
return Redirect::back();
}
}