Cachet/app/Http/Controllers/Admin/UserController.php

108 lines
2.8 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of Cachet.
*
2015-05-25 17:59:08 +01:00
* (c) Cachet HQ <support@cachethq.io>
*
* 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
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;
use PragmaRX\Google2FA\Vendor\Laravel\Facade as Google2FA;
2015-01-01 15:45:04 +00:00
class UserController extends AbstractController
{
/**
* 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([
2015-07-02 16:40:38 +01:00
'page_title' => 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
if ($enable2FA && !Auth::user()->hasTwoFactor) {
2015-01-09 14:21:53 -06:00
$items['google_2fa_secret'] = Google2FA::generateSecretKey();
segment_track('User Management', [
'event' => 'enabled_two_factor',
'value' => true,
]);
} elseif (!$enable2FA) {
2015-01-09 14:21:53 -06:00
$items['google_2fa_secret'] = '';
segment_track('User Management', [
'event' => 'enabled_two_factor',
'value' => false,
]);
2015-01-09 14:21:53 -06:00
}
if (trim($passwordChange) === '') {
unset($items['password']);
}
$user = Auth::user();
$user->update($items);
if (!$user->isValid()) {
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')
))
->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);
}
2015-01-03 17:51:35 +00:00
/**
* Regenerates the users API key.
*
* @return \Illuminate\View\View
*/
public function regenerateApiKey(User $user)
{
segment_track('User Management', [
2015-02-18 03:24:43 -06:00
'event' => 'regenrated_api_token',
]);
2015-01-03 17:51:35 +00:00
$user->api_key = User::generateApiKey();
$user->save();
return Redirect::back();
}
}