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

86 lines
2.3 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-05 14:26:57 -05:00
class MakeUserController extends \App\Http\Controllers\Controller
{
2020-06-06 17:03:32 -05:00
use UsesDatabase;
public function __invoke(Request $request)
2020-06-05 14:26:57 -05:00
{
2020-06-06 17:03:32 -05:00
if ($request->method() == 'POST') {
$this->create($request);
}
if (session('install.database')) {
2020-06-07 14:53:40 -05:00
$this->configureDatabase();
2020-06-06 17:03:32 -05:00
$user = User::first();
}
if (isset($user)) {
2020-06-07 00:03:57 -05:00
session(['install.user' => true]);
2020-06-06 17:03:32 -05:00
return view('install.user-created', [
'user' => $user,
]);
}
return view('install.make-user');
}
public function create(Request $request)
{
$this->validate($request, [
'username' => 'required',
'password' => 'required',
]);
try {
2020-06-07 14:53:40 -05:00
$this->configureDatabase();
2020-06-06 17:03:32 -05:00
$user = new User($request->only(['username', 'password', 'email']));
$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-08 09:21:31 -05:00
public static function enabled()
2020-06-07 14:53:40 -05:00
{
2020-06-08 09:21:31 -05:00
return 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
}