Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ class AuthLoginCustomController extends Controller
{
public function showLoginForm()
{
return view('auth.login'); // Gunakan view login yang sama
return view('auth.login');
}

public function login(Request $request)
{
$request->validate([
'email' => 'required|email', // Atau 'username'
'email' => 'required|email',
'password' => 'required',
'remember' => 'nullable|boolean',
]);

$user = User::where('email', $request->email)->first(); // Atau 'username'
$user = User::where('email', $request->email)->first();

if ($user && Hash::check($request->password, $user->password)) {
Auth::login($user, $request->remember);
// dd(Auth::user());
return redirect()->intended(route('home')); // Sesuaikan dengan route Anda
return redirect()->intended(route('home'));
}

return back()->withErrors([
'email' => 'These credentials do not match our records.', // Sesuaikan pesan error
'email' => 'These credentials do not match our records.',
])->onlyInput('email');
}

Expand Down
54 changes: 17 additions & 37 deletions web-sch-12/app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
Expand All @@ -10,63 +9,44 @@

class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/

use RegistersUsers;

/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/home';

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}

/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}

/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\Models\User
*/
protected function create(array $data)
{
$username = $data['username'] ?? $this->generateUsername($data['name']);

return User::create([
'name' => $data['name'],
'email' => $data['email'],
'name' => $data['name'],
'email' => $data['email'],
'username' => $username,
'password' => Hash::make($data['password']),
]);
}

protected function generateUsername($name)
{
$words = explode(' ', trim($name));
$firstFieveWords = array_slice($words, 0, 5);
$base = strtolower(implode('', $firstFieveWords));
$randomNumber = rand(1000, 9999);

return $base . $randomNumber;
}
}
Loading