Laravel Auth ::尝试总是返回false

时间:2015-11-26 18:37:58

标签: php laravel

我尝试过搜索Google并尝试了几种方法。但它们都没有工作:auth::attempt仍然返回false。我的注册码如下;在我的AuthController我有:

protected function create(array $data)
{
    $datetime = new \DateTime();
    $datetime->format('Y-m-d H:i:s');
    $datetime->getTimestamp();

    return User::create([
        'country_id' => 1, // default to malaysia
        'user_name' => $data['user_name'],
        'facebook_id' => null,
        'steam_link' => null,
        'password' => Hash::make($data['password']),
        'extra_information' => null,
        'remember_token' => null,
        'email' => $data['email'],
        'status_id' => 1, // active
        'is_verified' => false, // false
        'user_type_id' => 2, // normal user
        'account_status_id' => 1, // pending
        'confirmation_code' =>  str_random(30),
        'created_at' => $datetime
    ]);
}

 public function postRegister(Request $request)
 {
    $validator = $this->validator($request->all());

    if ($validator->fails()) {
        $this->throwValidationException(
            $request, $validator
        );
    }

    $user = $this->create($request->all());

    Mail::send('emails.registration_verification', ['user' => $user], function ($m) use ($user)
    {
        $m->from('no-reply@myapps.com', 'www.myapps.com');
        $m->to($user->email, $user->user_name)->subject('Verify your myappsaccount.');
    });

    return view('auth.registration_success')->with('user_name',$user->user_name)->with('email', $user->email);
}

public function emailVerification($confirmation_code)
{
    if (!$confirmation_code)
    {
        return Redirect::route('/errors/500');
    }

    $user = User::whereConfirmationCode($confirmation_code)->first();

    if (!$user)
    {
        return Redirect::route('/errors/500');
    }

    $user->account_status_id = 2; // active
    $user->confirmation_code = null;
    $user->save();

    return view('auth.verification_success')->with('user',$user);
}

public function postLogin(Request $request)
{
    $userdata = array(
        'email' => $request->email,
        'Password' => $request->password
    );

    if (Auth::attempt($userdata,true)) {
        echo 'test';
    }
    else {
        var_dump($userdata);
    }
}

我已经相应地删除了密码,我还将密码列从60更改为255,但登录失败。

预期的工作流程是用户注册,系统会向他们发送电子邮件进行验证。用户单击电子邮件中的链接将触发emailVerification方法。验证完成后,用户应该能够登录。

我错过了什么吗?

2 个答案:

答案 0 :(得分:1)

我很确定你的错误在这里:

password

数据库中的P字段是小写的,并且您正在检查以大写'Password' => $request->password开头的字段。将'password' => $request->password更改为import UIKit class EventTableViewController: UITableViewController { // MARK: Properties var events = [Event]() var isAdmin = false override func viewDidLoad() { super.viewDidLoad() // Use the edit button item provided by the table view controller. navigationItem.leftBarButtonItem = editButtonItem() // Load any saved events, otherwise load sample data. if let savedEvents = loadEvents() { events += savedEvents } else { // Load the sample data. loadSampleEvents() } } func loadSampleEvents() { let photo1 = UIImage(named: "event1")! let event1 = Event(name: "ACDC", photo: photo1, rating: 4, price: 500.0, eventDescription: "Album", album: "Album1")! let photo2 = UIImage(named: "event2")! let event2 = Event(name: "Cold Play", photo: photo2, rating: 5, price: 500.0, eventDescription: "Album", album: "Album1")! let photo3 = UIImage(named: "event3")! let event3 = Event(name: "One Direction", photo: photo3, rating: 3, price: 500.0, eventDescription: "Album", album: "Album1")! events += [event1, event2, event3] } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // MARK: - Table view data source override func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return events.count } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { // Table view cells are reused and should be dequeued using a cell identifier. let cellIdentifier = "EventTableViewCell" let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! EventTableViewCell // Fetches the appropriate event for the data source layout. let event = events[indexPath.row] cell.nameLabel.text = event.name cell.photoImageView.image = event.photo cell.ratingControl.rating = event.rating cell.priceLabel.text = event.album return cell } // Override to support conditional editing of the table view. override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { // Return false if you do not want item to be editable. return true } // Override to support editing the table view. override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { if editingStyle == .Delete { // Delete the row from the data source events.removeAtIndex(indexPath.row) saveEvents() tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) } else if editingStyle == .Insert { // Create new instance of class, add to the array, and add a new row to the table } } /* // Override to support rearranging the table view. override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) { } */ /* // Override to support conditional rearranging of the table view. override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool { // Return false if you do not want the item to be re-orderable. return true } */ // MARK: - Navigation // preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "ShowDetail" { let eventDetailViewController = segue.destinationViewController as! EventViewController // Get the cell that generated this segue. if let selectedEventCell = sender as? EventTableViewCell { let indexPath = tableView.indexPathForCell(selectedEventCell)! let selectedEvent = events[indexPath.row] eventDetailViewController.event = selectedEvent print(selectedEventCell) } } else if segue.identifier == "AddItem" { print("Adding new event.") } } @IBAction func unwindToMealList(sender: UIStoryboardSegue) { if let sourceViewController = sender.sourceViewController as? EventViewController, event = sourceViewController.event { if let selectedIndexPath = tableView.indexPathForSelectedRow { // Update an existing event. events[selectedIndexPath.row] = event tableView.reloadRowsAtIndexPaths([selectedIndexPath], withRowAnimation: .None) } else { // Add a new event. let newIndexPath = NSIndexPath(forRow: events.count, inSection: 0) events.append(event) tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Bottom) } // Save the events. saveEvents() } } // MARK: NSCoding func saveEvents() { let isSuccessfulSave = NSKeyedArchiver.archiveRootObject(events, toFile: Event.ArchiveURL.path!) if !isSuccessfulSave { print("Failed to save events...") } } func loadEvents() -> [Event]? { return NSKeyedUnarchiver.unarchiveObjectWithFile(Event.ArchiveURL.path!) as? [Event] } } ,它应该有效。

答案 1 :(得分:0)

我的不好,包括用户模型中的以下代码帮助我解决问题。

public function getAuthPassword()
    {
        return $this->password;
    }