pixelfed/app/Http/Controllers/Auth/LoginController.php

92 lines
2.2 KiB
PHP
Raw Normal View History

2018-04-15 23:56:48 +00:00
<?php
namespace App\Http\Controllers\Auth;
2018-08-28 03:07:36 +00:00
use App\AccountLog;
2018-04-15 23:56:48 +00:00
use App\Http\Controllers\Controller;
2018-08-28 03:07:36 +00:00
use App\User;
2018-04-15 23:56:48 +00:00
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
2022-01-25 06:26:38 +00:00
protected $redirectTo = '/i/web';
2018-04-15 23:56:48 +00:00
protected $maxAttempts = 5;
protected $decayMinutes = 60;
2018-04-15 23:56:48 +00:00
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
2018-06-01 17:58:43 +00:00
/**
* Validate the user login request.
*
2018-08-28 03:07:36 +00:00
* @param \Illuminate\Http\Request $request
*
2018-06-01 17:58:43 +00:00
* @return void
*/
public function validateLogin($request)
{
$rules = [
2019-03-20 02:51:45 +00:00
$this->username() => 'required|email',
2019-03-20 03:01:39 +00:00
'password' => 'required|string|min:6',
2018-06-01 17:58:43 +00:00
];
2020-12-13 04:04:59 +00:00
if(config('captcha.enabled')) {
$rules['h-captcha-response'] = 'required|captcha';
}
2018-06-01 17:58:43 +00:00
$this->validate($request, $rules);
}
2018-07-23 17:26:02 +00:00
/**
* The user has been authenticated.
*
2018-08-28 03:07:36 +00:00
* @param \Illuminate\Http\Request $request
* @param mixed $user
*
2018-07-23 17:26:02 +00:00
* @return mixed
*/
protected function authenticated($request, $user)
{
2019-03-20 02:51:45 +00:00
if($user->status == 'deleted') {
return;
}
2018-08-28 03:07:36 +00:00
$log = new AccountLog();
2018-07-23 17:26:02 +00:00
$log->user_id = $user->id;
$log->item_id = $user->id;
$log->item_type = 'App\User';
$log->action = 'auth.login';
$log->message = 'Account Login';
$log->link = null;
$log->ip_address = $request->ip();
$log->user_agent = $request->userAgent();
$log->save();
}
2018-04-15 23:56:48 +00:00
}