mercredi 23 décembre 2015

Authentication Doesn't work for me [ Laravel 5.2 ]

I set up my seeder as such:

use Illuminate\Database\Seeder;
use App\Etis\Domain\Entities\UsersEntity;

class AdminUser extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        UsersEntity::Create([
            'name'      => 'Billy Bob',
            'email'     => 'someemail@gmail.com',
            'password'  => bcrypt('password'),
        ]);
    }
}

Now that we have this set up, I created a controller to allow for login. I know theres already an authentic-able controller, how ever:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use \Twitter;
use Auth;
use App\Etis\Domain\Entities\UsersEntity;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class BlogController extends Controller {

    use AuthenticatesAndRegistersUsers;

    public function login() {
        return view('blog.login');
    }

    public function postLogin(Request $request) {

        $this->validate($request, [
            'email'    => 'required|email',
            'password' => 'required|min:3'
        ]);

        $credentials = $this->getCredentials($request);

        if (Auth::attempt($credentials)) {
            dd('Hello Bob ....');
        } else {
            return redirect()->back()->withErrors(['We could not log you in. Sorry.']);
        }
    }
}

It gets all the way down to the Auth::attempt($credentials) which doesn't authenticate. Instead I get: We could not log you in. Sorry.

The $credentials look like:

array:2 [▼
  "email" => "someemail@gmail.com"
  "password" => "password"
]

So what did I do wrong? Why doesn't it authenticate?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire