laravelが初めてです。私はいくつかの関連記事を見たことがありますが、私は正解を見つけることができませんでした。私はphp artisan make:auth
を使ってauth
を作った、私はディレクトリpublicPages
を持っている。 auth.login
ビューを私のカスタムpublicPages.login
とpublicPages.register
に変更しました。登録プロセスは正常に動作し、users
テーブルにデータを挿入します。ユーザーにはログインしません。私がlogin
ビューとに行くとき。それはエラーを返すことも、ユーザーをログインさせることもありません。ここで登録プロセスは正常に実行されますが、ログインビューは動作していませんlaravel authentication
はルートです:
Route::auth();
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController'
]);
Route::group(array('namespace' => 'UserControllers'), function()
{
Route::group(['middleware' => ['web']], function() {
Route::group(['middleware' => 'auth'], function() {
Route::get('community', '[email protected]');
Route::post('communities', '[email protected]');
Route::get('edit/{id}', ['as' => 'edit', 'uses' => '[email protected]']);
Route::get('delete/{id}', '[email protected]');
Route::post('update/{id}', ['as' => 'update', 'uses' => '[email protected]']);
Route::get('create', '[email protected]');
Route::post('idea', '[email protected]');
Route::get('users', '[email protected]');
Route::get('deleteUser/{id}', '[email protected]');
Route::get('delete/idea/{id}', '[email protected]');
Route::get('approve/{id}', '[email protected]');
});
});
コントローラー:
class UserController extends Controller {
//constructor
public function __construct() {
$this->middleware('auth');
}
私はそれがすべてのUserController function
のためのログインページにリダイレクトします$this->middleware('auth');
使用するときに私が知っています。それはうまく動作しています。
ビュー:
<form id="login-form" class="clearfix" action="{{url('/login')}}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<p class="rs pb30">Please Provide your Credentials to Verify Your Identity</p>
<div class="form form-post-comment">
<div class="fa-align-center">
<label for="login_email">
<input id="login_email" type="email" name="email" class="txt fill-width txt-name{{ $errors->has('email') ? ' has-error' : '' }}" placeholder="Enter Your Email" required="required"/>
</label>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
<br><br>
<label for="password">
<input id="password" type="password" name="login_password" class="txt fill-width txt-email" placeholder="Enter Your Password" required="required"/>
</label> <br><br>
<label for="links">
<a href="/changepassword" class="txt-emphasis">Forgotten Password?</a>
<p>Don't have an account? <a href="/register" class="txt-emphasis">Register Here</a> </p>
</label>
</div>
<div class="clear"></div>
<p >
<span id="response"></span>
{{--<input type="submit" class="btn btn-submit-comment" value="Login">--}}
<button class="btn btn-submit-comment" form="login-form">Login</button>
</p>
</div>
ここではAuthenticatesUsersファイルです:
<?php
namespace Illuminate\Foundation\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Lang;
//use App\Http\Requests\UserRequest;
trait AuthenticatesUsers
{
use RedirectsUsers;
/**
* Show the application login form.
*
* @return \Illuminate\Http\Response
*/
public function getLogin()
{
return $this->showLoginForm();
}
/**
* Show the application login form.
*
* @return \Illuminate\Http\Response
*/
public function showLoginForm()
{
$view = property_exists($this, 'loginView')
? $this->loginView : 'auth.authenticate';
if (view()->exists($view)) {
return view($view);
}
return view('publicPages.login');
}
/**
* Handle a login request to the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function postLogin(Request $request)
{
return $this->login($request);
}
/**
* Handle a login request to the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function login(Request $request)
{
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
$throttles = $this->isUsingThrottlesLoginsTrait();
if ($throttles && $lockedOut = $this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
$credentials = $this->getCredentials($request);
if (Auth::guard($this->getGuard())->attempt($credentials, $request->has('remember'))) {
return $this->handleUserWasAuthenticated($request, $throttles);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
if ($throttles && ! $lockedOut) {
$this->incrementLoginAttempts($request);
}
return $this->sendFailedLoginResponse($request);
}
/**
* Validate the user login request.
*
* @param \Illuminate\Http\Request $request
* @return void
*/
protected function validateLogin(Request $request)
{
$this->validate($request, [
$this->loginUsername() => 'required', 'password' => 'required',
]);
}
/**
* Send the response after the user was authenticated.
*
* @param \Illuminate\Http\Request $request
* @param bool $throttles
* @return \Illuminate\Http\Response
*/
protected function handleUserWasAuthenticated(Request $request, $throttles)
{
if ($throttles) {
$this->clearLoginAttempts($request);
}
if (method_exists($this, 'authenticated')) {
return $this->authenticated($request, Auth::guard($this->getGuard())->user());
}
return redirect()->intended($this->redirectPath());
}
/**
* Get the failed login response instance.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
protected function sendFailedLoginResponse(Request $request)
{
return redirect()->back()
->withInput($request->only($this->loginUsername(), 'remember'))
->withErrors([
$this->loginUsername() => $this->getFailedLoginMessage(),
]);
}
/**
* Get the failed login message.
*
* @return string
*/
protected function getFailedLoginMessage()
{
return Lang::has('auth.failed')
? Lang::get('auth.failed')
: 'These credentials do not match our records.';
}
/**
* Get the needed authorization credentials from the request.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
protected function getCredentials(Request $request)
{
return $request->only($this->loginUsername(), 'password');
}
/**
* Log the user out of the application.
*
* @return \Illuminate\Http\Response
*/
public function getLogout()
{
return $this->logout();
}
/**
* Log the user out of the application.
*
* @return \Illuminate\Http\Response
*/
public function logout()
{
Auth::guard($this->getGuard())->logout();
return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}
/**
* Get the guest middleware for the application.
*/
public function guestMiddleware()
{
$guard = $this->getGuard();
return $guard ? 'guest:'.$guard : 'guest';
}
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function loginUsername()
{
return property_exists($this, 'username') ? $this->username : 'email';
}
/**
* Determine if the class is using the ThrottlesLogins trait.
*
* @return bool
*/
protected function isUsingThrottlesLoginsTrait()
{
return in_array(
ThrottlesLogins::class, class_uses_recursive(static::class)
);
}
/**
* Get the guard to be used during authentication.
*
* @return string|null
*/
protected function getGuard()
{
return property_exists($this, 'guard') ? $this->guard : null;
}
}
私はpostLoginForm()
に変更する必要はありますか?おかげ
はアップデート2: 私は
if (Auth::attempt(['email' => $email, 'password' => $password])) {
// Authentication passed...
return redirect()->intended('dashboard');
} else {
echo 'not logged in';
}
にpostLoginForm()
関数のコードを変更した今、ようやくそれがnot logged in
を出力しますが、それは自動的に適用されるためにも、私は、それがnot logged in
言うtrue
資格情報、
あなたの返信ありがとう、私もそれを試みました。最初は 'routes.php'にはありませんでした。 @Alexey Mezenin –
'showLoginForm'関数のビューパスを更新しましたか? – Vikas
これはshowLoginFormです。public function showLoginForm() { $ view = property_exists($ this、 'loginView') ?$ this-> loginView: 'auth.authenticate'; if(view() - > exists($ view)){ return view($ view); } 戻るビュー( 'auth.login'); } 'ビューを戻す( 'auth.login')'をビュー( 'publicPages.login)'に戻す必要がありますか? –