Modul praktikum RPL4 Team orange
1. Pastikan sudah register minimal 3 user 2. Memodifikasi table users
- jalankan perintah php artisan make:migration add_level_user --table=users pada command prompt
- buka text editor anda, cari file .. add_level_user.php pada folder database/migrations - tambahkan script pada function up() menjadi seperti di bawah ini ;
• Sesuaikan isi role dengan proyek yang di buat - Jalankan perintah php artisan migrate pada command prompt - Cek table users pada database , pastikan field level sudah ada ! - Buka file User.php pada folder app/Models
- Tambahakan username dan level pada bagian protected $fillable
3. Modifikasi halaman Login
- buka file resources/views/auth/login.blade.php - ubah input email menjadi username
. Memodifikasi table users
- jalankan perintah php artisan make:migration add_level_user --table=users pada command prompt
- buka text editor anda, cari file .. add_level_user.php pada folder database/migrations - tambahkan script pada function up() menjadi seperti di bawah ini ;
• Sesuaikan isi role dengan proyek yang di buat - Jalankan perintah php artisan migrate pada command prompt - Cek table users pada database , pastikan field level sudah ada ! - Buka file User.php pada folder app/Models
- Tambahakan username dan level pada bagian protected $fillable
3. Modifikasi halaman Login
- buka file resources/views/auth/login.blade.php - ubah input email menjadi username
4. Modifikasi request
- buka file app/http/requests/auth/Loginrequest.php - ubah semua email menjadi username
class LoginRequest extends FormRequest {
public function authorize() {
return true;
}
public function rules() {
return [
'username' => ['required', 'string'], 'password' => ['required', 'string'], ];
}
/**
* Attempt to authenticate the request's credentials.
*
* @return void *
* @throws \Illuminate\Validation\ValidationException */
public function authenticate() {
$this->ensureIsNotRateLimited();
if (! Auth::attempt($this->only('username', 'password'), $this-
>boolean('remember'))) {
RateLimiter::hit($this->throttleKey());
throw ValidationException::withMessages([
'username' => trans('auth.failed'), ]);
}
RateLimiter::clear($this->throttleKey());
}
/**
* Ensure the login request is not rate limited.
*
* @return void *
* @throws \Illuminate\Validation\ValidationException */
public function ensureIsNotRateLimited() {
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { return;
}
event(new Lockout($this));
$seconds = RateLimiter::availableIn($this->throttleKey());
throw ValidationException::withMessages([
'username' => trans('auth.throttle', [ 'seconds' => $seconds,
'minutes' => ceil($seconds / 60), ]),
]);
}
/**
* Get the rate limiting throttle key for the request.
*
* @return string */
public function throttleKey() {
return Str::transliterate(Str::lower($this->input('username')).'|'.$this-
>ip());
}
}
6. Buka loacalhost/phpMyAdmin di browser
- buka tabel users , tambahkan username dan level pada 3 data yang sudah di buat
- coba lakukan login dengan username
7. Membuat Midlleware checkRole
- Jalankan perintah php artisan make:middleware checkLevel pada command prompt - buka file checkLevel.php pada folder app/Http/Middleware/
- modifikasi script pada function handler ()
- Buka file Kernel.php pada folder app/Http
- Tambahkan script 'checkLevel' => \App\Http\Middleware\checkLevel::class, pada bagian protected $routeMIddleware