1Day пре 3 година
родитељ
комит
8a583424db
2 измењених фајлова са 72 додато и 10 уклоњено
  1. 35 0
      app/Http/Controllers/ProfileController.php
  2. 37 10
      resources/views/profile/index.blade.php

+ 35 - 0
app/Http/Controllers/ProfileController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers;
 
+use App\Classes\Pterodactyl;
 use App\Models\Configuration;
 use App\Models\User;
 use Illuminate\Contracts\View\Factory;
@@ -11,6 +12,7 @@ use Illuminate\Http\Request;
 use Illuminate\Http\Response;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Hash;
+use Illuminate\Validation\ValidationException;
 
 class ProfileController extends Controller
 {
@@ -53,10 +55,27 @@ class ProfileController extends Controller
                 'new_password_confirmation' => 'required|same:new_password'
             ]);
 
+            //Update Users Password on Pterodactyl
+            //Username,Mail,First and Lastname are required aswell
+            $response = Pterodactyl::client()->patch('/application/users/'.$user->pterodactyl_id, [
+                "password" => $request->input('new_password'),
+                "username" => $request->input('name'),
+                "first_name" => $request->input('name'),
+                "last_name" => $request->input('name'),
+                "email" => $request->input('email'),
+
+            ]);
+            if ($response->failed()) {
+                throw ValidationException::withMessages([
+                    'pterodactyl_error_message' => $response->toException()->getMessage(),
+                    'pterodactyl_error_status' => $response->toException()->getCode()
+                ]);
+            }
             //update password
             $user->update([
                 'password' => Hash::make($request->input('new_password')),
             ]);
+
         }
 
         //validate request
@@ -80,11 +99,27 @@ class ProfileController extends Controller
             ]);
         }
 
+        //update name and email on Pterodactyl
+        $response = Pterodactyl::client()->patch('/application/users/'.$user->pterodactyl_id, [
+            "username" => $request->input('name'),
+            "first_name" => $request->input('name'),
+            "last_name" => $request->input('name'),
+            "email" => $request->input('email'),
+        ]);
+
+        if ($response->failed()) {
+            throw ValidationException::withMessages([
+                'pterodactyl_error_message' => $response->toException()->getMessage(),
+                'pterodactyl_error_status' => $response->toException()->getCode()
+            ]);
+        }
+
         //update name and email
         $user->update([
             'name' => $request->input('name'),
             'email' => $request->input('email'),
         ]);
+        $user->sendEmailVerificationNotification();
 
         return redirect()->route('profile.index')->with('success' , __('Profile updated'));
     }

+ 37 - 10
resources/views/profile/index.blade.php

@@ -11,7 +11,8 @@
                 <div class="col-sm-6">
                     <ol class="breadcrumb float-sm-right">
                         <li class="breadcrumb-item"><a href="{{route('home')}}">{{__('Dashboard')}}</a></li>
-                        <li class="breadcrumb-item"><a class="text-muted" href="{{route('profile.index')}}">{{__('Profile')}}</a>
+                        <li class="breadcrumb-item"><a class="text-muted"
+                                                       href="{{route('profile.index')}}">{{__('Profile')}}</a>
                         </li>
                     </ol>
                 </div>
@@ -28,9 +29,12 @@
                 <div class="col-lg-12 px-0">
                     @if(!Auth::user()->hasVerifiedEmail() && strtolower($force_email_verification) == 'true')
                         <div class="alert alert-warning p-2 m-2">
-                            <h5><i class="icon fas fa-exclamation-circle"></i>{{__('Required Email verification!')}}</h5>
+                            <h5><i class="icon fas fa-exclamation-circle"></i>{{__('Required Email verification!')}}
+                            </h5>
                             {{__('You have not yet verified your email address')}}
-                            <a class="text-primary" href="{{route('verification.send')}}">{{__('Click here to resend verification email')}}</a> <br>
+                            <a class="text-primary"
+                               href="{{route('verification.send')}}">{{__('Click here to resend verification email')}}</a>
+                            <br>
                             {{__('Please contact support If you didnt receive your verification email.')}}
                         </div>
                     @endif
@@ -38,14 +42,19 @@
                     @if(is_null(Auth::user()->discordUser) && strtolower($force_discord_verification) == 'true')
                         @if(!empty(env('DISCORD_CLIENT_ID')) && !empty(env('DISCORD_CLIENT_SECRET')))
                             <div class="alert alert-warning p-2 m-2">
-                                <h5><i class="icon fas fa-exclamation-circle"></i>{{__('Required Discord verification!')}}</h5>
+                                <h5>
+                                    <i class="icon fas fa-exclamation-circle"></i>{{__('Required Discord verification!')}}
+                                </h5>
                                 {{__('You have not yet verified your discord account')}}
-                                <a class="text-primary" href="{{route('auth.redirect')}}">{{__('Login with discord')}}</a> <br>
+                                <a class="text-primary"
+                                   href="{{route('auth.redirect')}}">{{__('Login with discord')}}</a> <br>
                                 {{__('Please contact support If you face any issues.')}}
                             </div>
                         @else
                             <div class="alert alert-danger p-2 m-2">
-                                <h5><i class="icon fas fa-exclamation-circle"></i>{{__('Required Discord verification!')}}</h5>
+                                <h5>
+                                    <i class="icon fas fa-exclamation-circle"></i>{{__('Required Discord verification!')}}
+                                </h5>
                                 {{__('Due to system settings you are required to verify your discord account!')}} <br>
                                 {{__('It looks like this hasnt been set-up correctly! Please contact support.')}}'
                             </div>
@@ -99,7 +108,8 @@
                                 </div>
                             </div>
                             <ul class="nav nav-tabs">
-                                <li class="nav-item"><a href="javasript:void(0)" class="active nav-link">{{__('Settings')}}</a>
+                                <li class="nav-item"><a href="javasript:void(0)"
+                                                        class="active nav-link">{{__('Settings')}}</a>
                                 </li>
                             </ul>
                             <div class="tab-content pt-3">
@@ -108,6 +118,20 @@
                                         <div class="col">
                                             <div class="row">
                                                 <div class="col">
+                                                    @if( $errors->has('pterodactyl_error_message') )
+                                                        @foreach( $errors->get('pterodactyl_error_message') as $err )
+                                                            <span class="text-danger" role="alert">
+                                                                <small><strong>{{ $err }}</strong></small>
+                                                            </span>
+                                                        @endforeach
+                                                    @endif
+                                                        @if( $errors->has('pterodactyl_error_status') )
+                                                            @foreach( $errors->get('pterodactyl_error_status') as $err )
+                                                                <span class="text-danger" role="alert">
+                                                                    <small><strong>{{ $err }}</strong></small>
+                                                                </span>
+                                                            @endforeach
+                                                        @endif
                                                     <div class="form-group"><label>{{__('Name')}}</label> <input
                                                             class="form-control @error('name') is-invalid @enderror"
                                                             type="text" name="name"
@@ -144,7 +168,8 @@
                                             <div class="mb-3"><b>{{__('Change Password')}}</b></div>
                                             <div class="row">
                                                 <div class="col">
-                                                    <div class="form-group"><label>{{__('Current Password')}}</label> <input
+                                                    <div class="form-group"><label>{{__('Current Password')}}</label>
+                                                        <input
                                                             class="form-control @error('current_password') is-invalid @enderror"
                                                             name="current_password" type="password"
                                                             placeholder="••••••">
@@ -173,7 +198,8 @@
                                             </div>
                                             <div class="row">
                                                 <div class="col">
-                                                    <div class="form-group"><label>{{__('Confirm Password')}}</span></label>
+                                                    <div class="form-group">
+                                                        <label>{{__('Confirm Password')}}</span></label>
                                                         <input
                                                             class="form-control @error('new_password_confirmation') is-invalid @enderror"
                                                             name="new_password_confirmation" type="password"
@@ -238,7 +264,8 @@
                                     </div>
                                     <div class="row">
                                         <div class="col d-flex justify-content-end">
-                                            <button class="btn btn-primary" type="submit">{{__('Save Changes')}}</button>
+                                            <button class="btn btn-primary"
+                                                    type="submit">{{__('Save Changes')}}</button>
                                         </div>
                                     </div>