2626
2727use DB ;
2828use Validator ;
29- use Pterodactyl \Models ;
29+ use Pterodactyl \Models \User ;
30+ use Pterodactyl \Models \Server ;
31+ use Pterodactyl \Models \Subuser ;
32+ use Pterodactyl \Models \Permission ;
3033use Pterodactyl \Services \UuidService ;
34+ use GuzzleHttp \Exception \TransferException ;
3135use Pterodactyl \Exceptions \DisplayException ;
3236use Pterodactyl \Exceptions \DisplayValidationException ;
3337
@@ -57,7 +61,7 @@ class SubuserRepository
5761 */
5862 public function create ($ sid , array $ data )
5963 {
60- $ server = Models \ Server::with ('node ' )->findOrFail ($ sid );
64+ $ server = Server::with ('node ' )->findOrFail ($ sid );
6165
6266 $ validator = Validator::make ($ data , [
6367 'permissions ' => 'required|array ' ,
@@ -72,7 +76,7 @@ public function create($sid, array $data)
7276
7377 try {
7478 // Determine if this user exists or if we need to make them an account.
75- $ user = Models \ User::where ('email ' , $ data ['email ' ])->first ();
79+ $ user = User::where ('email ' , $ data ['email ' ])->first ();
7680 if (! $ user ) {
7781 try {
7882 $ repo = new UserRepository ;
@@ -88,18 +92,18 @@ public function create($sid, array $data)
8892 }
8993 } elseif ($ server ->owner_id === $ user ->id ) {
9094 throw new DisplayException ('You cannot add the owner of a server as a subuser. ' );
91- } elseif (Models \ Subuser::select ('id ' )->where ('user_id ' , $ user ->id )->where ('server_id ' , $ server ->id )->first ()) {
95+ } elseif (Subuser::select ('id ' )->where ('user_id ' , $ user ->id )->where ('server_id ' , $ server ->id )->first ()) {
9296 throw new DisplayException ('A subuser with that email already exists for this server. ' );
9397 }
9498
9599 $ uuid = new UuidService ;
96- $ subuser = Models \ Subuser::create ([
100+ $ subuser = Subuser::create ([
97101 'user_id ' => $ user ->id ,
98102 'server_id ' => $ server ->id ,
99103 'daemonSecret ' => (string ) $ uuid ->generate ('servers ' , 'uuid ' ),
100104 ]);
101105
102- $ perms = Models \ Permission::list (true );
106+ $ perms = Permission::list (true );
103107 $ daemonPermissions = $ this ->coreDaemonPermissions ;
104108
105109 foreach ($ data ['permissions ' ] as $ permission ) {
@@ -109,7 +113,7 @@ public function create($sid, array $data)
109113 array_push ($ daemonPermissions , $ perms [$ permission ]);
110114 }
111115
112- Models \ Permission::create ([
116+ Permission::create ([
113117 'subuser_id ' => $ subuser ->id ,
114118 'permission ' => $ permission ,
115119 ]);
@@ -134,7 +138,7 @@ public function create($sid, array $data)
134138 DB ::commit ();
135139
136140 return $ subuser ;
137- } catch (\ GuzzleHttp \ Exception \ TransferException $ ex ) {
141+ } catch (TransferException $ ex ) {
138142 DB ::rollBack ();
139143 throw new DisplayException ('There was an error attempting to connect to the daemon to add this user. ' , $ ex );
140144 } catch (\Exception $ ex ) {
@@ -155,7 +159,7 @@ public function create($sid, array $data)
155159 */
156160 public function delete ($ id )
157161 {
158- $ subuser = Models \ Subuser::with ('server.node ' )->findOrFail ($ id );
162+ $ subuser = Subuser::with ('server.node ' )->findOrFail ($ id );
159163 $ server = $ subuser ->server ;
160164
161165 DB ::beginTransaction ();
@@ -177,7 +181,7 @@ public function delete($id)
177181 }
178182 $ subuser ->delete ();
179183 DB ::commit ();
180- } catch (\ GuzzleHttp \ Exception \ TransferException $ ex ) {
184+ } catch (TransferException $ ex ) {
181185 DB ::rollBack ();
182186 throw new DisplayException ('There was an error attempting to connect to the daemon to delete this subuser. ' , $ ex );
183187 } catch (\Exception $ ex ) {
@@ -208,7 +212,7 @@ public function update($id, array $data)
208212 throw new DisplayValidationException (json_encode ($ validator ->all ()));
209213 }
210214
211- $ subuser = Models \ Subuser::with ('server.node ' )->findOrFail ($ id );
215+ $ subuser = Subuser::with ('server.node ' )->findOrFail ($ id );
212216 $ server = $ subuser ->server ;
213217
214218 DB ::beginTransaction ();
@@ -227,7 +231,7 @@ public function update($id, array $data)
227231 if (! is_null ($ perms [$ permission ])) {
228232 array_push ($ daemonPermissions , $ perms [$ permission ]);
229233 }
230- Models \ Permission::create ([
234+ Permission::create ([
231235 'subuser_id ' => $ subuser ->id ,
232236 'permission ' => $ permission ,
233237 ]);
@@ -249,7 +253,7 @@ public function update($id, array $data)
249253 ]);
250254
251255 DB ::commit ();
252- } catch (\ GuzzleHttp \ Exception \ TransferException $ ex ) {
256+ } catch (TransferException $ ex ) {
253257 DB ::rollBack ();
254258 throw new DisplayException ('There was an error attempting to connect to the daemon to update permissions. ' , $ ex );
255259 } catch (\Exception $ ex ) {
0 commit comments