2014-12-21 10:14:58 +00:00
|
|
|
<?php
|
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
2015-05-25 17:59:08 +01:00
|
|
|
* (c) Cachet HQ <support@cachethq.io>
|
2015-04-19 08:52:39 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2015-03-20 18:30:45 -06:00
|
|
|
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
2015-01-01 15:45:04 +00:00
|
|
|
|
2015-03-21 02:21:20 -06:00
|
|
|
use CachetHQ\Cachet\Http\Controllers\AbstractController;
|
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 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
|
|
|
|
2015-03-21 02:21:20 -06:00
|
|
|
class UserController extends AbstractController
|
2014-12-21 10:14:58 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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-07-02 16:40:38 +01:00
|
|
|
'page_title' => 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-04-19 08:52:39 +01:00
|
|
|
if ($enable2FA && !Auth::user()->hasTwoFactor) {
|
2015-01-09 14:21:53 -06:00
|
|
|
$items['google_2fa_secret'] = Google2FA::generateSecretKey();
|
2015-01-23 17:24:34 +00:00
|
|
|
|
|
|
|
segment_track('User Management', [
|
|
|
|
'event' => 'enabled_two_factor',
|
|
|
|
'value' => true,
|
|
|
|
]);
|
2015-04-19 08:52:39 +01:00
|
|
|
} elseif (!$enable2FA) {
|
2015-01-09 14:21:53 -06:00
|
|
|
$items['google_2fa_secret'] = '';
|
2015-01-23 17:24:34 +00:00
|
|
|
|
|
|
|
segment_track('User Management', [
|
|
|
|
'event' => 'enabled_two_factor',
|
|
|
|
'value' => false,
|
|
|
|
]);
|
2015-01-09 14:21:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (trim($passwordChange) === '') {
|
|
|
|
unset($items['password']);
|
|
|
|
}
|
2015-01-09 09:03:07 +00:00
|
|
|
|
2015-01-09 20:21:29 -06:00
|
|
|
$user = Auth::user();
|
|
|
|
$user->update($items);
|
2014-12-21 10:14:58 +00:00
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
if (!$user->isValid()) {
|
2015-01-09 20:21:29 -06:00
|
|
|
return Redirect::back()->withInput(Binput::except('password'))
|
2015-01-14 16:08:42 +00:00
|
|
|
->with('title', sprintf(
|
2015-06-15 20:30:35 +01:00
|
|
|
'%s %s',
|
2015-01-14 16:08:42 +00:00
|
|
|
trans('dashboard.notifications.whoops'),
|
|
|
|
trans('dashboard.team.edit.failure')
|
|
|
|
))
|
2015-01-09 20:21:29 -06:00
|
|
|
->with('errors', $user->getErrors());
|
|
|
|
}
|
|
|
|
|
2015-01-14 16:08:42 +00:00
|
|
|
$successMsg = sprintf(
|
2015-06-15 20:30:35 +01:00
|
|
|
'%s %s',
|
2015-01-14 16:08:42 +00:00
|
|
|
trans('dashboard.notifications.awesome'),
|
|
|
|
trans('dashboard.team.edit.success')
|
|
|
|
);
|
|
|
|
|
|
|
|
return Redirect::back()->with('success', $successMsg);
|
2014-12-21 10:14:58 +00:00
|
|
|
}
|
2015-01-03 17:51:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Regenerates the users API key.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function regenerateApiKey(User $user)
|
|
|
|
{
|
2015-01-23 17:24:34 +00:00
|
|
|
segment_track('User Management', [
|
2015-02-18 03:24:43 -06:00
|
|
|
'event' => 'regenrated_api_token',
|
2015-01-23 17:24:34 +00:00
|
|
|
]);
|
|
|
|
|
2015-01-03 17:51:35 +00:00
|
|
|
$user->api_key = User::generateApiKey();
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
return Redirect::back();
|
|
|
|
}
|
2014-12-21 10:14:58 +00:00
|
|
|
}
|