Skip to content

Commit

Permalink
menambahkan fitur ganti password di profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunnie-pin committed Jul 9, 2023
1 parent 03c44ee commit 6e66e2f
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
20 changes: 19 additions & 1 deletion app/Http/Controllers/ProfileUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function index()
}


public function update(Request $request, $user)
public function update(Request $request)
{
//
$request->validate([
Expand All @@ -39,4 +39,22 @@ public function update(Request $request, $user)

return redirect('/dashboard')->with('success', 'Profile telah berhasil diubah');
}

public function changePassword(){
return view('changepassword');
}

public function updatePassword(Request $request){
$request->validate([
'password' => 'required|min:8|max:30',
'password_confirmation' => 'required|same:password'
]);

User::where('id', auth()->user()->id)
->update([
'password' => Hash::make($request->password)
]);

return redirect('/dashboard')->with('success', 'Password telah berhasil diubah');
}
}
79 changes: 79 additions & 0 deletions resources/views/changepassword.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@extends('layouts.main')
@section('container')
<div class="pagetitle">
<h1>Change Password</h1>
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Profile</a></li>
<li class="breadcrumb-item active">Profile</li>
</ol>
</nav>
</div><!-- End Page Title -->

<section class="section dashboard">
<div class="row">

<!-- Left side columns -->
<div class="col-lg-12">
<div class="row">
<div class="card">
<div class="card-body p-3">

<form class="row g-3" method="post" action="{{route('update-password') }}">
@csrf
<div class="col-md-4">
<div class="pb-2">
<label for="nama" class="form-label">Email</label>
<input type="text" value="{{ auth()->user()->email }}" class="form-control"
disabled>
</div>

<div class="pb-2">
<label for="nama" class="form-label">Pasword Baru</label>
<input type="password" name="password" id="password"
class="form-control
@error('password')
is-invalid
@enderror
">

@error('password_confirmation')
<label class="form-check-label invalid-feedback">
{{ $message }}
</label>
@enderror
</div>

<div class="pb-2">
<label for="nama" class="form-label">Konfirmasi Password Baru</label>
<input type="password" name="password_confirmation" id="password_confirmation"
class="form-control
@error('password_confirmation')
is-invalid
@enderror
">

@error('password_confirmation')
<label class="form-check-label invalid-feedback">
{{ $message }}
</label>
@enderror
</div>

</div>

<div class="col-12 py-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>

<!-- end card -->
</div>
</div>
</div>
</div><!-- End Left side columns -->

</div>
</section>

@endsection
9 changes: 9 additions & 0 deletions resources/views/partials/navbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
<li>
<hr class="dropdown-divider">
</li>
<li>
<a class="dropdown-item d-flex align-items-center" href="{{ route('change-password') }}">
<i class="bi bi-gear"></i>
<span>Ubah Password</span>
</a>
</li>
<li>
<hr class="dropdown-divider">
</li>
<li>
<form action="{{ route('logout') }}" method="POST">
@csrf
Expand Down
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
'update' => 'update-profile'
])->except(['create', 'destroy', 'edit', 'store']) ->middleware('auth');

Route::get('/change-password', [ProfileUserController::class, 'changePassword'])->name('change-password')->middleware('auth');
Route::post('/change-password', [ProfileUserController::class, 'updatePassword'])->name('update-password')->middleware('auth');

Route::resource('/list-bidang', ListBidangController::class)->names([
'index' => 'list-bidang',
'create' => 'create-bidang',
Expand Down

0 comments on commit 6e66e2f

Please sign in to comment.