如何使用以下代码进行登录和注册

时间:2019-05-22 09:26:17

标签: php laravel authentication login

我在laravel网上商店工作,我在身份验证,登录和注册方面遇到一些问题。首先,如果我尝试使用已经在数据库中注册的电子邮件地址和密码登录,则会显示“这些凭据与我们的记录不匹配”。因此它无法识别我的数据。如果我导航到该页面,它将实际上识别出我的电子邮件。

如果我尝试注册,它什么也没做。

我已经尝试过再次进行php artisan make:auth,但这不会有任何改变。另外,我还检查了以下模型:我在验证器和dd();中做了一些create(){},但是dd();不会在create函数中启动,所以我想create函数是没有触发。

//登录控制器:

class LoginController extends Controller
{


    use AuthenticatesUsers;

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

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

//注册控制器:

 protected function validator(array $data)
    {
        return Validator::make($data, [
            'gebruikersnaam' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 
            'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
            'voornaam' => ['required', 'string', 'max:255'],
            'achternaam' => ['required', 'string', 'max:255'],
            'telefoonnummer' => ['required', 'string','min:9' ,'max:255'],
            'klant_afbeelding' => ['required', 'string', 'max:255'],
        ]);
    }

 1. /**
         * Create a new user instance after a valid registration.
         *
         * @param  array  $data
         * @return \App\User
         */

    protected function create(array $data)
    {
        return User::create([
            'gebruikersnaam' => $data['gebruikersnaam'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
            'voornaam' => $data['voornaam'],
            'achternaam' => $data['achternaam'],
            'telefoonnummer' => $data['telefoonnummer'],
            'klant_afbeelding' => $data['klant_afbeelding'],
        ]);
    }

//用户类别:

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'gebruikersnaam', 'email', 'password','voornaam','achternaam',
        'telefoonnummer','klant_afbeelding'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

}

//我的路线:

<?php  
Route::get('/', function () {
    return view('home');
});

// Route::get('/', function (Request $request) {
//      $data = $request->validate([
//         'message' => 'required|max:255',
//         'rating' => 'required|url|max:255',
//     ]);
//
//     return view('home');
// });

Route::get('/Profiel', 'ProfielController@Profiel');

Route::get('/home', 'HomeController@index')->name('home');

Route::get('/home', 'HomeController@Home' );

// route voor de review submit
Route::resource('reviewSubmit', 'ReviewController');


Route::get('/Profiel', 'ProfielController@Profiel');

Route::post('/profielupdate', 'ProfielController@update');

Route::post('/niewsbriefsubscribe', 'HomeController@subscribe');

Auth::routes();

Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
Route::get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
Route::post('register', 'Auth\RegisterController@register');

Route::get('/home', 'HomeController@index')->name('home');

//登录视图

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">{{ __('Login') }}</div>

                <div class="card-body">
                    <form method="POST" action="{{ route('login') }}">
                        @csrf

                        <div class="form-group row">
                            <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>

                                @error('email')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="current-password">

                                @error('password')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                            </div>
                        </div>

                        <div class="form-group row">
                            <div class="col-md-6 offset-md-4">
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>

                                    <label class="form-check-label" for="remember">
                                        {{ __('Remember Me') }}
                                    </label>
                                </div>
                            </div>
                        </div>

                        <div class="form-group row mb-0">
                            <div class="col-md-8 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    {{ __('Login') }}
                                </button>

                                @if (Route::has('password.request'))
                                    <a class="btn btn-link" href="{{ route('password.request') }}">
                                        {{ __('Forgot Your Password?') }}
                                    </a>
                                @endif
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

//注册视图

    @extends('layouts.app')

@section('content')
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">{{ __('Register') }}</div>

                    <div class="card-body">
                        <form method="POST" action="{{ route('register') }}">
                            @csrf

                            <div class="form-group row">
                                <label for="gebruikersnaam" class="col-md-4 col-form-label text-md-right">{{ __('Gebruikersnaam') }}</label>

                                <div class="col-md-6">
                                    <input id="name" type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>

                                    @error('gebruikersnaam')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                    @enderror
                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

                                <div class="col-md-6">
                                    <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email">

                                    @error('email')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                    @enderror
                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="voornaam" class="col-md-4 col-form-label text-md-right">{{ __('Voornaam') }}</label>

                                <div class="col-md-6">
                                    <input id="voornaam" type="text" class="form-control @error('voornaam') is-invalid @enderror" name="voornaam" value="{{ old('voornaam') }}" required autocomplete="voornaam">

                                    @error('voornaam')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                    @enderror
                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="achternaam" class="col-md-4 col-form-label text-md-right">{{ __('Achternaam') }}</label>

                                <div class="col-md-6">
                                    <input id="achternaam" type="text" class="form-control @error('achternaam') is-invalid @enderror" name="achternaam" value="{{ old('achternaam') }}" required autocomplete="achternaam">

                                    @error('achternaam')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                    @enderror
                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="telefoonnummer" class="col-md-4 col-form-label text-md-right">{{ __('Telefoonnummer') }}</label>

                                <div class="col-md-6">
                                    <input id="telefoonnummer" type="text" class="form-control @error('telefoonnummer') is-invalid @enderror" name="telefoonnummer" value="{{ old('telefoonnummer') }}" required autocomplete="telefoonnummer">

                                    @error('telefoonnummer')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                    @enderror
                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="wachtwoord" class="col-md-4 col-form-label text-md-right">{{ __('Wachtwoord') }}</label>

                                <div class="col-md-6">
                                    <input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="new-password">

                                    @error('password')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                    @enderror
                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>

                                <div class="col-md-6">
                                    <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
                                </div>
                            </div>

                            <div class="form-group row mb-0">
                                <div class="col-md-6 offset-md-4">
                                    <button type="submit" class="btn btn-primary">
                                        {{ __('Registreer') }}
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

发生的预期事情是我可以注册并实际保存在数据库中并登录。

此刻输出相反。

0 个答案:

没有答案