Files
librenms-librenms/app/Http/Controllers/Install/MakeUserController.php

86 lines
2.4 KiB
PHP
Raw Normal View History

2020-06-05 14:26:57 -05:00
<?php
/**
* MakeUserController.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2020 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace App\Http\Controllers\Install;
2020-06-06 17:03:32 -05:00
use App\Models\User;
use Illuminate\Http\Request;
2020-06-09 07:24:05 -05:00
use Illuminate\Support\Arr;
2020-06-06 17:03:32 -05:00
2020-06-11 01:06:16 -05:00
class MakeUserController extends InstallationController
2020-06-05 14:26:57 -05:00
{
2020-06-11 01:06:16 -05:00
public function index(Request $request)
2020-06-05 14:26:57 -05:00
{
2020-06-11 01:06:16 -05:00
if (!self::enabled()) {
return redirect()->route('install');
}
2020-06-06 17:03:32 -05:00
if (session('install.database')) {
$user = User::first();
}
if (isset($user)) {
2020-06-07 00:03:57 -05:00
session(['install.user' => true]);
2020-06-11 01:06:16 -05:00
return view('install.user-created', $this->formatData([
2020-06-06 17:03:32 -05:00
'user' => $user,
2020-06-11 01:06:16 -05:00
]));
2020-06-06 17:03:32 -05:00
}
2020-06-11 01:06:16 -05:00
return view('install.make-user', $this->formatData([
2020-06-09 07:24:05 -05:00
'messages' => Arr::wrap(session('message'))
2020-06-11 01:06:16 -05:00
]));
2020-06-06 17:03:32 -05:00
}
public function create(Request $request)
{
$this->validate($request, [
'username' => 'required',
'password' => 'required',
]);
try {
$user = new User($request->only(['username', 'password', 'email']));
2020-06-09 07:24:05 -05:00
$user->level = 10;
2020-06-06 17:03:32 -05:00
$user->setPassword($request->get('password'));
$res = $user->save();
$message = $res ? trans('install.user.success') : trans('install.user.failure');
} catch (\Exception $e) {
$message = $e->getMessage();
}
2020-06-07 10:36:45 -05:00
return redirect()->back()->with('message', $message);
2020-06-05 14:26:57 -05:00
}
2020-06-07 14:53:40 -05:00
2020-06-11 01:58:42 -05:00
public static function enabled(): bool
2020-06-07 14:53:40 -05:00
{
2020-06-11 01:58:42 -05:00
return (bool)session('install.migrate');
2020-06-07 14:53:40 -05:00
}
public static function icon(): string
{
return 'fa-key';
}
2020-06-05 14:26:57 -05:00
}