diff --git a/app/Http/Controllers/Auth/ChangePasswordController.php b/app/Http/Controllers/Auth/ChangePasswordController.php index d2c451c..5a85ea9 100644 --- a/app/Http/Controllers/Auth/ChangePasswordController.php +++ b/app/Http/Controllers/Auth/ChangePasswordController.php @@ -30,8 +30,7 @@ class ChangePasswordController extends Controller 'password_confirmation' => 'required', ]); - if (app('hash')->check($input['old_password'], auth()->user()->password)) - { + if (app('hash')->check($input['old_password'], auth()->user()->password)) { $user = auth()->user(); $user->password = $input['password']; $user->save(); @@ -43,5 +42,4 @@ class ChangePasswordController extends Controller flash(trans('auth.old_password_failed'), 'danger'); return back(); } - } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php new file mode 100644 index 0000000..fce06e0 --- /dev/null +++ b/app/Http/Controllers/Auth/LoginController.php @@ -0,0 +1,76 @@ +middleware('guest', ['except' => 'logout']); + } + + /** + * Send the response after the user was authenticated. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + protected function sendLoginResponse(Request $request) + { + $request->session()->regenerate(); + + $this->clearLoginAttempts($request); + + flash(trans('auth.welcome', ['name' => $request->user()->name])); + + return $this->authenticated($request, $this->guard()->user()) + ?: redirect()->intended($this->redirectPath()); + } + + /** + * Log the user out of the application. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function logout(Request $request) + { + $this->guard()->logout(); + + $request->session()->flush(); + + $request->session()->regenerate(); + flash(trans('auth.logged_out'), 'success'); + + return redirect(route('auth.login')); + } +} diff --git a/app/Http/Controllers/Auth/ProfileController.php b/app/Http/Controllers/Auth/ProfileController.php index e6e6ae1..b8b3848 100644 --- a/app/Http/Controllers/Auth/ProfileController.php +++ b/app/Http/Controllers/Auth/ProfileController.php @@ -30,7 +30,7 @@ class ProfileController extends Controller $user->email = $profileData['email']; $user->save(); - flash()->success(trans('auth.profile_updated')); + flash(trans('auth.profile_updated'), 'success'); return back(); } diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 0df3ade..be75fa5 100755 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -3,55 +3,19 @@ namespace App\Http\Controllers; use App\Entities\Users\User; -use App\Http\Requests\Accounts\ChangePasswordRequest; -use App\Http\Requests\Accounts\LoginRequest; use App\Http\Requests\Accounts\RegisterRequest; use Auth; use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\PasswordBroker; -use Illuminate\Foundation\Auth\ResetsPasswords; -use Illuminate\Foundation\Auth\ThrottlesLogins; -use Illuminate\Http\Request; class AuthController extends Controller { - use ThrottlesLogins; - public function __construct(Guard $auth, PasswordBroker $passwords) { $this->auth = $auth; $this->passwords = $passwords; - $this->middleware('guest', ['only' => ['getLogin', 'postLogin', 'getRegister', 'postRegister']]); - $this->middleware('auth', ['only' => ['getLogout', 'getProfile', 'patchProfile']]); - } - - public function getLogin() - { - return view('auth.login'); - } - - public function postLogin(Request $request) - { - $loginData = $request->validate([ - 'email' => 'required|email', - 'password' => 'required', - ]); - - if (Auth::attempt($loginData)) { - flash()->success(trans('auth.welcome', ['name' => Auth::user()->name])); - return redirect()->intended('home'); - } - - flash()->error(trans('auth.failed')); - return redirect()->back()->withInput(); - } - - public function getLogout() - { - Auth::logout(); - flash()->success('Anda telah logout.'); - return redirect()->route('auth.login'); + $this->middleware('guest'); } public function getRegister() diff --git a/routes/web/account.php b/routes/web/account.php index 2496f3b..353c3de 100644 --- a/routes/web/account.php +++ b/routes/web/account.php @@ -3,13 +3,15 @@ * Account Routes */ Route::group(['middleware' => 'web','as'=>'auth.'], function() { - Route::get('login', ['as'=>'login', 'uses' => 'AuthController@getLogin']); - Route::post('login', ['as'=>'login', 'uses' => 'AuthController@postLogin']); - Route::get('logout', ['as'=>'logout', 'uses' => 'AuthController@getLogout']); Route::get('register', ['as'=>'register', 'uses' => 'AuthController@getRegister']); Route::post('register', ['as'=>'register', 'uses' => 'AuthController@postRegister']); }); +// Authentication Routes... +Route::get('login', 'Auth\LoginController@showLoginForm')->name('auth.login'); +Route::post('login', 'Auth\LoginController@login'); +Route::get('logout', 'Auth\LoginController@logout')->name('auth.logout'); + // User Profile Routes... Route::get('profile', ['uses' => 'Auth\ProfileController@show'])->name('auth.profile'); Route::patch('profile', ['uses' => 'Auth\ProfileController@update'])->name('auth.profile');