2015-12-06 18:58:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin;
|
|
|
|
|
2015-12-12 06:21:17 +00:00
|
|
|
use Alert;
|
|
|
|
use Pterodactyl\Models\User;
|
2015-12-14 03:22:16 +00:00
|
|
|
use Pterodactyl\Repositories\UserRepository;
|
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class AccountsController extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller Constructor
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
|
|
|
|
// All routes in this controller are protected by the authentication middleware.
|
|
|
|
$this->middleware('auth');
|
|
|
|
$this->middleware('admin');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIndex(Request $request)
|
|
|
|
{
|
|
|
|
return view('admin.accounts.index', [
|
|
|
|
'users' => User::paginate(20)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getNew(Request $request)
|
|
|
|
{
|
2015-12-12 06:21:17 +00:00
|
|
|
return view('admin.accounts.new');
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getView(Request $request, $id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2015-12-12 06:21:17 +00:00
|
|
|
public function postNew(Request $request)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'username' => 'required|min:4|unique:users,username',
|
|
|
|
'email' => 'required|email|unique:users,email',
|
|
|
|
'password' => 'required|confirmed|regex:((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,})',
|
|
|
|
'password_confirmation' => 'required'
|
|
|
|
]);
|
|
|
|
|
2015-12-14 03:22:16 +00:00
|
|
|
try {
|
|
|
|
|
|
|
|
$user = new UserRepository;
|
|
|
|
$userid = $user->create($request->input('username'), $request->input('email'), $request->input('password'));
|
2015-12-12 06:21:17 +00:00
|
|
|
|
2015-12-14 03:22:16 +00:00
|
|
|
Alert::success('Account has been successfully created.')->flash();
|
|
|
|
return redirect()->route('admin.accounts.view', ['id' => $userid]);
|
2015-12-12 06:21:17 +00:00
|
|
|
|
2015-12-14 03:22:16 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
Alert::danger('An error occured while attempting to add a new user. Please check the logs or try again.')->flash();
|
|
|
|
return redirect()->route('admin.accounts.new');
|
|
|
|
}
|
2015-12-12 06:21:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|