php - Error: Login attribute is required using Sentry and Laravel -
since today, login controller (using sentry) doesn't work anymore. changed 10203902 times keeps giving me error: "a [login] attribute required". past 2-3 weeks controller worked fine.
logincontroller
<?php namespace digitus\auth\controllers; use illuminate\view\environment view; use cartalyst\sentry\sentry; use illuminate\support\facades\input; use illuminate\routing\redirector redirect; class logincontroller extends \digitus\base\controllers\bcontroller{ public function __construct(input $input, view $view, sentry $sentry, redirect $redirect){ $this->input = $input; $this->view = $view; $this->sentry = $sentry; $this->user = $this->sentry->getuser(); $this->redirect = $redirect; if($this->sentry->check()) { $user = $this->sentry->getuser(); } else { $user = null; } $this->view->share('loggeduser', $user); } protected $input; protected $view; protected $sentry; protected $redirect; public function index() { return $this->view->make('user.login'); } public function login() { $user = $this->user->where('username', $this->input->get('email_or_username'))->orwhere('email', $this->input->get('email_or_username'))->first(); $credentials = array( 'email' => input::get('email_or_username') ?: null, 'password' => $this->input->get('password'), ); try { $user = $this->sentry->authenticate($credentials, false); if($this->sentry->check()) { return $this->redirect->to('admin'); } else { return $this->redirect->to(''); } } catch (\exception $e) { return $this->redirect->to('login')->witherrors(array('login'=> $e->getmessage())); } } } view
@extends('layouts.main') @section('content') <div class="col-md-4 col-md-offset-4"> <div class="panel panel-info"> <div class="panel-heading">please login</div> <div class="panel-body"> {{ form::open(array('url' => 'login')) }} @if($errors->has('login')) <div class="alert alert-danger"> <a href="#" class="close" data-dismiss="alert">×</a> {{ $errors->first('login', ':message') }} </div> @endif <div class="form-group"> {{ form::label('email_or_username', 'email address or username') }} {{ form::email('email_or_username', '', array('class'=>'form-control','placeholder'=>'please enter email address or username login', 'autofocus')) }} </div> <div class="form-group"> {{ form::label('password', 'password') }} {{ form::password('password', array('class'=>'form-control', 'placeholder'=>'password')) }} </div> <div class="form-group"> {{ form::submit('login', array('class'=>'btn btn-success')) }} {{ html::link('/', 'cancel', array('class'=>'btn btn-danger')) }} </div> <hr> <div class="form-group"> <h2>don't have account?</h2> {{ html::link('register', 'please register here', array('class'=>'btn btn-primary btn-xs'))}} </div> {{ form::close() }} </div> </div> </div> @stop i've asked many people solutions or fixes etc. didn't work..
ps & fyi: published sentry config, , login_attribute email. or input great. in advance..
sentry uses
protected static $loginattribute = 'email'; to login data, check if have made changes it. lines giving hard time:
$loginname = $this->userprovider->getemptyuser()->getloginname(); $logincredentialkey = (isset($credentials[$loginname])) ? $loginname : 'login'; basically if $loginattribute not available use 'login' credential key. can test give wants:
$credentials = array( 'email' => input::get('email_or_username') ?: null, 'login' => input::get('email_or_username') ?: null, 'password' => $this->input->get('password'), ); unfortunately, cannot have 2 different fields login user, if need you'll have check manually, able like:
public function login() { $user = $this->sentry->getuserprovider()->getemptyuser(); $user = $user->where('email', $this->input->get('email_or_username')) ->orwhere('username', $this->input->get('email_or_username')) ->first(); try { if ($user && hash::check($this->input->get('password'), $user->password)) /// here check if user found { $this->sentry->login($user, false); /// remember = false /// here login happening in case of true } else { // user not found or wrong password } } catch (\exception $e) { return $this->redirect->to('login')->witherrors(array('login'=> $e->getmessage())); } }
Comments
Post a Comment