Bonsoir,
J'essai de faire une petite application web avec laravel, mais j'arrive pas à faire le login correctement!
la condition
if (Auth::attempt(['username' => Request::get('username'), 'password' => Request::get('password')]))
et toujours FALSE
Voila le code:
HTML:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <form action="{{url('auth/login')}}" method="post" accept-charset="utf-8" class="ui form">
<div class="ui segment biarabi animated zoomInDown">
<div class="field">
<div class="ui left icon input biarabi">
<i class=" blue inverted circular user icon"></i>
<input type="text" name="username" placeholder="اسم المستخدم" class="biarabi">
</div>
</div>
<div class="field">
<div class="ui left icon input biarabi">
<i class="blue inverted circular lock icon"></i>
<input type="password" name="password" placeholder="كلمة المرور" class="biarabi">
</div>
</div>
<div class="field">
<input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />
<input type="submit" value="تسجيل الدخول" class="ui button large fluid blue biarabi">
</div>
</div>
</form> |
Model User:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
<?php
namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
class User extends Model implements AuthenticatableContract
{
use Authenticatable;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'email', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
} |
UserController:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <?php
namespace App\Http\Controllers;
use Request;
use App\User;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
//
public function login(Request $request) {
if (Auth::attempt(['username' => Request::get('username'),
'password' => Request::get('password')
]))
{
return "Welcome </br> Username: " . Request::get('username') ."</br> Password: " . Request::get('password');
} else {
return "your are Not logged </br> Username: " . Request::get('username') ."</br> Password: " . Request::get('password');
}
}
} |
Route:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::post('auth/login', 'UserController@login'); |
Partager