|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Pterodactyl - Panel |
| 4 | + * Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com> |
| 5 | + * Some Modifications (c) 2015 Dylan Seidt <dylan.seidt@gmail.com> |
| 6 | + * |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in all |
| 15 | + * copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | + * SOFTWARE. |
| 24 | + */ |
| 25 | +namespace Pterodactyl\Http\Controllers\Admin; |
| 26 | + |
| 27 | +use Alert; |
| 28 | +use Settings; |
| 29 | +use Mail; |
| 30 | +use Log; |
| 31 | +use Pterodactyl\Models\User; |
| 32 | +use Pterodactyl\Repositories\UserRepository; |
| 33 | +use Pterodactyl\Models\Server; |
| 34 | + |
| 35 | +use Pterodactyl\Exceptions\DisplayException; |
| 36 | +use Pterodactyl\Exceptions\DisplayValidationException; |
| 37 | + |
| 38 | +use Pterodactyl\Http\Controllers\Controller; |
| 39 | +use Illuminate\Http\Request; |
| 40 | + |
| 41 | +class UserController extends Controller |
| 42 | +{ |
| 43 | + |
| 44 | + /** |
| 45 | + * Controller Constructor |
| 46 | + */ |
| 47 | + public function __construct() |
| 48 | + { |
| 49 | + // |
| 50 | + } |
| 51 | + |
| 52 | + public function getIndex(Request $request) |
| 53 | + { |
| 54 | + return view('admin.users.index', [ |
| 55 | + 'users' => User::paginate(20) |
| 56 | + ]); |
| 57 | + } |
| 58 | + |
| 59 | + public function getNew(Request $request) |
| 60 | + { |
| 61 | + return view('admin.users.new'); |
| 62 | + } |
| 63 | + |
| 64 | + public function getView(Request $request, $id) |
| 65 | + { |
| 66 | + return view('admin.users.view', [ |
| 67 | + 'user' => User::findOrFail($id), |
| 68 | + 'servers' => Server::select('servers.*', 'nodes.name as nodeName', 'locations.long as location') |
| 69 | + ->join('nodes', 'servers.node', '=', 'nodes.id') |
| 70 | + ->join('locations', 'nodes.location', '=', 'locations.id') |
| 71 | + ->where('owner', $id) |
| 72 | + ->where('active', 1) |
| 73 | + ->get(), |
| 74 | + ]); |
| 75 | + } |
| 76 | + |
| 77 | + public function deleteUser(Request $request, $id) |
| 78 | + { |
| 79 | + try { |
| 80 | + $repo = new UserRepository; |
| 81 | + $repo->delete($id); |
| 82 | + Alert::success('Successfully deleted user from system.')->flash(); |
| 83 | + return redirect()->route('admin.users'); |
| 84 | + } catch(DisplayException $ex) { |
| 85 | + Alert::danger($ex->getMessage())->flash(); |
| 86 | + } catch (\Exception $ex) { |
| 87 | + Log::error($ex); |
| 88 | + Alert::danger('An exception was encountered while attempting to delete this user.')->flash(); |
| 89 | + } |
| 90 | + return redirect()->route('admin.users.view', $id); |
| 91 | + } |
| 92 | + |
| 93 | + public function postNew(Request $request) |
| 94 | + { |
| 95 | + try { |
| 96 | + $user = new UserRepository; |
| 97 | + $userid = $user->create($request->input('email'), $request->input('password')); |
| 98 | + Alert::success('Account has been successfully created.')->flash(); |
| 99 | + return redirect()->route('admin.users.view', $userid); |
| 100 | + } catch (DisplayValidationException $ex) { |
| 101 | + return redirect()->route('admin.users.new')->withErrors(json_decode($ex->getMessage()))->withInput(); |
| 102 | + } catch (\Exception $ex) { |
| 103 | + Log::error($ex); |
| 104 | + Alert::danger('An error occured while attempting to add a new user.')->flash(); |
| 105 | + return redirect()->route('admin.users.new'); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + public function updateUser(Request $request, $user) |
| 110 | + { |
| 111 | + $data = [ |
| 112 | + 'email' => $request->input('email'), |
| 113 | + 'root_admin' => $request->input('root_admin'), |
| 114 | + 'password_confirmation' => $request->input('password_confirmation'), |
| 115 | + ]; |
| 116 | + |
| 117 | + if ($request->input('password')) { |
| 118 | + $data['password'] = $request->input('password'); |
| 119 | + } |
| 120 | + |
| 121 | + try { |
| 122 | + $repo = new UserRepository; |
| 123 | + $repo->update($user, $data); |
| 124 | + Alert::success('User account was successfully updated.')->flash(); |
| 125 | + } catch (DisplayValidationException $ex) { |
| 126 | + return redirect()->route('admin.users.view', $user)->withErrors(json_decode($ex->getMessage())); |
| 127 | + } catch (\Exception $e) { |
| 128 | + Log::error($e); |
| 129 | + Alert::danger('An error occured while attempting to update this user.')->flash(); |
| 130 | + } |
| 131 | + return redirect()->route('admin.users.view', $user); |
| 132 | + } |
| 133 | + |
| 134 | +} |
0 commit comments