forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountsController.php
More file actions
68 lines (51 loc) · 1.76 KB
/
AccountsController.php
File metadata and controls
68 lines (51 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Pterodactyl\Http\Controllers\Admin;
use Alert;
use Pterodactyl\Models\User;
use Pterodactyl\Repositories\UserRepository;
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)
{
return view('admin.accounts.new');
}
public function getView(Request $request, $id)
{
//
}
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'
]);
try {
$user = new UserRepository;
$userid = $user->create($request->input('username'), $request->input('email'), $request->input('password'));
Alert::success('Account has been successfully created.')->flash();
return redirect()->route('admin.accounts.view', ['id' => $userid]);
} 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');
}
}
}