update profile admin, user, and routes

This commit is contained in:
raditya09 2023-11-07 14:38:29 +07:00
parent 62f67653ef
commit 683d315d7a
10 changed files with 157 additions and 109 deletions

View File

@ -3,7 +3,9 @@
namespace App\Http\Controllers\AdminBackend;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class AdminProfileController extends Controller
{
@ -11,4 +13,52 @@ public function index()
{
return view('admin_backend.admin_profile');
}
public function update(Request $request)
{
// Validate the request data (you can add more validation rules)
$validatedData = $request->validate([
'nama_lengkap' => 'required',
'nim' => 'required',
'profile_image' => 'image|mimes:jpeg,png,jpg,gif|max:2048',
]);
$imagePath = null;
if ($request->hasFile('profile_image')) {
$image = $request->file('profile_image');
$imagePath = $image->store('images', 'public');
}
$user = User::findOrFail(auth()->user()->id);
$user->nama_lengkap = $request->input('nama_lengkap');
$user->nim = $request->input('nim');
if ($imagePath != null) {
$user->foto = $imagePath;
}
$user->update();
return redirect('/admin')->with('success', 'Profile updated successfully');
}
public function changePassword(Request $request)
{
$request->validate([
'current_password' => 'required',
'new_password' => 'required|string|min:8|confirmed',
], [
'new_password.min' => 'Password tidak boleh kurang dari 8 karakter',
]);
$user = Auth::user();
// Verify the current password using the fully qualified namespace
if (!\Illuminate\Support\Facades\Hash::check($request->input('current_password'), $user->password)) {
return redirect()->back()->with('error', 'Current password is incorrect');
}
// Update the password
$user->password = \Illuminate\Support\Facades\Hash::make($request->input('new_password'));
$user->save();
return redirect()->back()->with('success', 'Password changed successfully');
}
}

View File

@ -63,7 +63,7 @@ public function store(Request $request)
$user->angkatan = $request->input('angkatan');
$user->email = $request->input('email');
$user->password = Hash::make($request->input('email'));
$user->kelas_user = '1';
$user->kelas_user = '3';
// Setel atribut-atribut lain yang perlu diisi
$user->save();

View File

@ -41,7 +41,7 @@ public function update(Request $request)
}
$user->update();
return redirect('/dashboard')->with('success', 'Profile updated successfully1');
return redirect('/dashboard')->with('success', 'Profile updated successfully');
}
public function changePassword(Request $request)

View File

@ -19,9 +19,16 @@
<div class="card">
<div class="card-body profile-card pt-4 d-flex flex-column align-items-center">
<img src="{{ asset('backend/assets/img/profile-img.jpg')}}" alt="Profile" class="rounded-circle">
<h2>Raditya Arief Pratama</h2>
<h3>Teknik Informatika</h3>
<img src="{{ asset('storage/' . Auth::user()->foto)}}" alt="Profile" class="rounded-circle">
<h2>
@if(Auth::user())
{{ Auth::user()->nama_lengkap }}
@endif</h2>
<h3>
@if(Auth::user())
{{ Auth::user()->nim }}
@endif
</h3>
</div>
</div>
@ -54,117 +61,99 @@
<div class="row">
<div class="col-lg-3 col-md-4 label ">{{ __('Nama Lengkap') }}</div>
<div class="col-lg-9 col-md-8">Raditya Arief Pratama</div>
<div class="col-lg-9 col-md-8">
@if(Auth::user())
{{ Auth::user()->nama_lengkap }}
@endif
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">{{ __('NIM') }}</div>
<div class="col-lg-9 col-md-8">E4212423</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">{{ __('Semester') }}</div>
<div class="col-lg-9 col-md-8">5</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">{{ __('Angkatan') }}</div>
<div class="col-lg-9 col-md-8">2021</div>
<div class="col-lg-3 col-md-4 label">{{ __('NIP') }}</div>
<div class="col-lg-9 col-md-8">
@if(Auth::user())
{{ Auth::user()->nim }}
@endif
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">{{ __('E-Mail') }}</div>
<div class="col-lg-9 col-md-8">radityaariefp@polije.ac.id</div>
<div class="col-lg-9 col-md-8">
@if(Auth::user())
{{ Auth::user()->email }}
@endif</div>
</div>
</div>
<div class="tab-pane fade profile-edit pt-3" id="profile-edit">
<!-- Profile Edit Form -->
<form>
<div class="row mb-3">
<label for="profileImage" class="col-md-4 col-lg-3 col-form-label">Profile Image</label>
<div class="col-md-8 col-lg-9">
<img src="{{ asset('backend/assets/img/profile-img.jpg')}}" alt="Profile">
<div class="pt-2">
<a href="#" class="btn btn-primary btn-sm" title="Upload new profile image"><i class="bi bi-upload"></i></a>
<a href="#" class="btn btn-danger btn-sm" title="Remove my profile image"><i class="bi bi-trash"></i></a>
</div>
<div class="tab-pane fade profile-edit pt-3" id="profile-edit">
<form method="POST" action="/admin-profile/update" enctype="multipart/form-data">
@csrf
<div class="row mb-3">
<label for="profileImage" class="col-md-4 col-lg-3 col-form-label">Profile Image</label>
<div class="col-md-8 col-lg-9">
<img src="{{ asset('storage/' . Auth::user()->foto)}}" alt="Profile">
<div class="pt-2">
<input type="file" name="profile_image" class="form-control-file">
</div>
</div>
</div>
</div>
<div class="row mb-3">
<label for="nama_lengkap" class="col-md-4 col-lg-3 col-form-label">{{ __('Nama Lengkap') }}</label>
<div class="col-md-8 col-lg-9">
<input name="nama_lengkap" type="text" class="form-control" id="nama_lengkap" value="Raditya Arief Pratama">
<div class="row mb-3">
<label for="nama_lengkap" class="col-md-4 col-lg-3 col-form-label">{{ __('Nama Lengkap') }}</label>
<div class="col-md-8 col-lg-9">
<input name="nama_lengkap" type="text" class="form-control" id="nama_lengkap" value="{{ Auth::user()->nama_lengkap }}">
</div>
</div>
</div>
<div class="row mb-3">
<label for="nim" class="col-md-4 col-lg-3 col-form-label">{{ __('NIM') }}</label>
<div class="col-md-8 col-lg-9">
<input name="nim" type="text" class="form-control" id="nim" value="E4212423">
<div class="row mb-3">
<label for="nim" class="col-md-4 col-lg-3 col-form-label">{{ __('NIP') }}</label>
<div class="col-md-8 col-lg-9">
<input name="nim" type="text" class="form-control" id="nim" value="{{ Auth::user()->nim }}">
</div>
</div>
</div>
<div class="row mb-3">
<label for="semester" class="col-md-4 col-lg-3 col-form-label">{{ __('Semester') }}</label>
<div class="col-md-8 col-lg-9">
<input name="semester" type="text" class="form-control" id="semester" value="5">
<div class="text-center">
<button type="submit" class="btn btn-primary">Save Changes</button>
</div>
</div>
</form>
</div> <!-- End Profile Edit Form -->
<div class="row mb-3">
<label for="angkatan" class="col-md-4 col-lg-3 col-form-label">{{ __('Angkatan') }}</label>
<div class="col-md-8 col-lg-9">
<input name="angkatan" type="text" class="form-control" id="angkatan" value="2021">
</div>
</div>
<div class="row mb-3">
<label for="email" class="col-md-4 col-lg-3 col-form-label">{{ __('E-Mail') }}</label>
<div class="col-md-8 col-lg-9">
<input name="email" type="text" class="form-control" id="email" value="radityaariefp@polije.ac.id">
</div>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary">Save Changes</button>
</div>
</form><!-- End Profile Edit Form -->
</div>
<div class="tab-pane fade pt-3" id="profile-change-password">
<!-- Change Password Form -->
<form>
<!-- Change Password Form -->
<form method="POST" action="{{ route('admin-profile.changePassword') }}">
@csrf
<div class="row mb-3">
<label for="currentPassword" class="col-md-4 col-lg-3 col-form-label">Current Password</label>
<div class="col-md-8 col-lg-9">
<input name="password" type="password" class="form-control" id="currentPassword">
</div>
</div>
<div class="row mb-3">
<label for="current_password" class="col-md-4 col-lg-3 col-form-label">Current Password</label>
<div class="col-md-8 col-lg-9">
<input name="current_password" type="password" class="form-control" id="current_password">
</div>
</div>
<div class="row mb-3">
<label for="newPassword" class="col-md-4 col-lg-3 col-form-label">New Password</label>
<div class="col-md-8 col-lg-9">
<input name="newpassword" type="password" class="form-control" id="newPassword">
</div>
</div>
<div class="row mb-3">
<label for="new_password" class="col-md-4 col-lg-3 col-form-label">New Password</label>
<div class="col-md-8 col-lg-9">
<input name="new_password" type="password" class="form-control" id="new_password">
</div>
</div>
<div class="row mb-3">
<label for="renewPassword" class="col-md-4 col-lg-3 col-form-label">Re-enter New Password</label>
<div class="col-md-8 col-lg-9">
<input name="renewpassword" type="password" class="form-control" id="renewPassword">
</div>
</div>
<div class="row mb-3">
<label for="new_password_confirmation" class="col-md-4 col-lg-3 col-form-label">Re-enter New Password</label>
<div class="col-md-8 col-lg-9">
<input name="new_password_confirmation" type="password" class="form-control" id="new_password_confirmation">
</div>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary">Change Password</button>
</div>
</form><!-- End Change Password Form -->
<div class="text-center">
<button type="submit" class="btn btn-primary">Change Password</button>
</div>
</form>
<!-- End Change Password Form -->
</div>
@ -181,9 +170,9 @@
@endsection
@section('script')
<script>
$(document).ready(function() {
$("#sidebar-profile").removeClass("collapsed");
});
</script>
@endsection
<script>
$(document).ready(function() {
$("#sidebar-profile").removeClass("collapsed");
});
</script>
@endsection

View File

@ -2,6 +2,9 @@
<aside id="sidebar" class="sidebar">
<ul class="sidebar-nav" id="sidebar-nav">
<li>
<a class="card-body profile-card pt-4 d-flex flex-column align-items-center">
<img src="{{ asset('storage/' . Auth::user()->foto)}}" alt="Profile" class="rounded-circle" style="width: 120px; height: 120px;">
</a><!-- End Profile Iamge Icon -->
<h6 class="d-flex flex-column align-items-center"><?php $user = Auth::user();
echo($user->nama_lengkap)?>
</h6>

View File

@ -23,7 +23,7 @@
<h5 class="card-title">Knowledge of Metacognitif (KM) </h5>
@foreach ($historiPengisian as $item)
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: {{ $item->km_total/68*100 }}%;" aria-valuenow="{{ $item->km_total }}" aria-valuemin="0" aria-valuemax="68"></div>
<div class="progress-bar" role="progressbar" style="width: {{ $item->km_total/68*100 }}%;" aria-valuenow="{{ $item->km_total }}" aria-valuemin="0" aria-valuemax="85"></div>
</div>
<div class="pt-1 d-flex justify-content-between"><span>Nilai anda</span> {{ $item->km_total }} </div>
@endforeach
@ -39,7 +39,7 @@
<h5 class="card-title">Regulation of Metacognitif (RM) </h5>
@foreach ($historiPengisian as $item)
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: {{ $item->km_total/132*100 }}%;" aria-valuenow="{{ $item->rm_total }}" aria-valuemin="0" aria-valuemax="132"></div>
<div class="progress-bar" role="progressbar" style="width: {{ $item->km_total/132*100 }}%;" aria-valuenow="{{ $item->rm_total }}" aria-valuemin="0" aria-valuemax="175"></div>
</div>
<div class="pt-1 d-flex justify-content-between"><span>Nilai anda</span> {{ $item->rm_total }}</div>
@endforeach
@ -87,7 +87,7 @@
<small> <p>Keterangan Nilai KM:</p> </small>
<small> <p>KM High 63</p> </small>
<small> <p>KM Medium 42</p> </small>
<small> <p>KM Low <42 </p> </small>
<small> <p>KM Low < 42 </p> </small>
</div>
</div>
</div><!-- End Penjelasan KM -->

View File

@ -3,11 +3,10 @@
<ul class="sidebar-nav" id="sidebar-nav">
<li>
<a class="card-body profile-card pt-4 d-flex flex-column align-items-center">
<img src="{{ asset('storage/' . Auth::user()->foto)}}" alt="Profile" class="rounded-circle" style="width: 120px; height: 120px;>
<img src="{{ asset('storage/' . Auth::user()->foto)}}" alt="Profile" class="rounded-circle" style="width: 120px; height: 120px;">
</a><!-- End Profile Iamge Icon -->
<!-- <h6> {{ Auth::user()->name }}</h6> -->
<h6> class="d-flex flex-column align-items-center"><?php $user = Auth::user();
<h6 class="d-flex flex-column align-items-center"><?php $user = Auth::user();
echo($user->nama_lengkap)?>
</h6>
<span class="d-flex flex-column align-items-center"><?php $user = Auth::user();

View File

@ -46,7 +46,7 @@
<div class="d-flex align-items-center justify-content-between">
<a href="#" class="logo d-flex align-items-center">
<img src="{{ asset('backend/assets/img/logo.png')}}" alt="">
<span class="d-none d-lg-block">NiceAdmin</span>
<span class="d-none d-lg-block">{{config('app.name')}}</span>
</a>
<i class="bi bi-list toggle-sidebar-btn"></i>
</div><!-- End Logo -->

View File

@ -98,7 +98,10 @@
<div class="row">
<div class="col-lg-3 col-md-4 label">{{ __('E-Mail') }}</div>
<div class="col-lg-9 col-md-8">radityaariefp@polije.ac.id</div>
<div class="col-lg-9 col-md-8">
@if(Auth::user())
{{ Auth::user()->email }}
@endif</div>
</div>
</div>

View File

@ -65,6 +65,10 @@
Route::get('/hasil/cetak-pdf', 'AdminResultController@cetak_pdf')->name('userQuestionnaire.cetak');
Route::post('/select-period', 'SelectPeriodController@update')->name('adminSelectPeriod');
Route::post('/select-period/active', 'SelectPeriodController@active')->name('adminSelectPeriod.active');
Route::post('/admin-profile/update', 'AdminProfileController@update');
Route::get('/admin-profile/change-password', 'AdminProfileController@changePasswordForm')->name('admin-profile.changePasswordForm');
Route::post('/admin-profile/change-password', 'AdminProfileController@changePassword')->name('admin-profile.changePassword');