2014-12-21 10:14:58 +00:00
|
|
|
<?php
|
|
|
|
|
2015-01-02 00:18:19 +00:00
|
|
|
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;
|
2015-01-09 09:03:07 +00:00
|
|
|
use PragmaRX\Google2FA\Vendor\Laravel\Facade as Google2FA;
|
2015-01-01 15:45:04 +00:00
|
|
|
|
2014-12-21 10:14:58 +00:00
|
|
|
class DashUserController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Shows the user view.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-21 10:14:58 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showUser()
|
|
|
|
{
|
2015-01-01 10:39:22 +00:00
|
|
|
return View::make('dashboard.user.index')->with([
|
2015-01-05 11:12:34 +00:00
|
|
|
'pageTitle' => trans('dashboard.team.profile').' - '.trans('dashboard.dashboard'),
|
2014-12-21 10:14:58 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-21 10:19:18 +00:00
|
|
|
* Updates the current user.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-21 10:14:58 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function postUser()
|
|
|
|
{
|
2015-01-02 12:05:50 +00:00
|
|
|
$items = Binput::all();
|
2014-12-21 10:14:58 +00:00
|
|
|
|
2015-01-09 14:21:53 -06:00
|
|
|
$passwordChange = array_get($items, 'password');
|
2015-01-09 09:03:07 +00:00
|
|
|
$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']);
|
|
|
|
}
|
2015-01-09 09:03:07 +00:00
|
|
|
|
2014-12-21 10:14:58 +00:00
|
|
|
$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();
|
|
|
|
}
|
2014-12-21 10:14:58 +00:00
|
|
|
}
|