I tested your code and its working. Check your auth.php, Or i guess you might be using some other name for your user's storing table except the name users.
@Sikandhar Yes, my code looks perfect to me, but it is a mystery. Thank you for looking at it. My table is named users:
-- Table structure for table `users`
--
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(50) NOT NULL,
`username` varchar(20) NOT NULL,
`password` varchar(60) NOT NULL,
`password_temp` varchar(60) NOT NULL,
`code` varchar(60) NOT NULL,
`active` int(11) NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;
Here is my auth.php
Here is my User model
Maybe something is missing in my User model
Ok, I changed my User model after seeing this post here
I am almost positive I am missing something in my User model but not sure what it is.
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
protected $fillable = array('email', 'username', 'password', 'code', 'active');
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('Password', 'remember_token');
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->password;
}
/**
* Get the e-mail address where password reminders are sent.
*
* @return string
*/
public function getReminderEmail()
{
return $this->email;
}
public function getRememberToken()
{
return $this->remember_token;
}
public function setRememberToken($value)
{
$this->remember_token = $value;
}
public function getRememberTokenName()
{
return 'remember_token';
}
}
I now added the remember_token as field in users table and three functions according to the laravel docs.
Now I get this error:
Class User contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Illuminate\Auth\UserInterface::getAuthIdentifier)
This may help. Try Sentry for your authentication, It is easy and powerful.
Thank you for suggesting Sentry. I have used it before. I am wanting to do this project from scratch using the Auth and am wanting to fully understand it.
Ok, I got rid of the error, a simple mistake of a misspelling in
public function getAuthIndentifier() //<----bad spelling!!!!
However:
The auth is still not being recognized because in my conditional my error 'Email/password wrong, or account not activated yet?' is showing. I even changed the conditional to true or false, and false come up every time. My auth is not being recognized.
Well, you can't use two returns in a single code block, and I see you are missing a semi-colon.
if($auth) {
// Redirect to the intended page
return 'true';
}else{
return Redirect::route('account-sign-in') //<--missing a semi-colon which can always lead to unexpected results
return 'false'; //<--second return will not be executed
}
Not sure where you got that code, but if you look at my Controller in the above link or here, this is what I have. The semicolons are there because I have no syntactical errors, but instead logical errors.
Here is what I have.
if($auth) {
// Redirect to the intended page
return Redirect::intended('/');
}else{
return Redirect::route('account-sign-in')
->with('global', 'Email/password wrong, or account not activated yet?');
}
}
return Redirect::route('account-sign-in')
->with('global', 'There was a problem signing you in.');
}
Thinking about using sentry, but I do not want to give up on this. I always figure out the solution.
I got that code block from your first post on the thread, but I see you don't have anything wrong with your controller.
Does the Auth::attempt() work when you remove 'active' => 1?
I removed the 'active' => 1 and it still throws the error in my conditional.
I did var_dump($auth) and get bool(false)
That is basically saying that the $auth array strings are empty. This does not make sense.
I also tried changing the property to
'active' => User::where('active', '=', '1')->get();
Finally found the mistake. I could kick myself back to Texas. Anyhow, here it is
if ($validator->fails()) {
return Redirect::route('account-create')
->withErrors($validator)
//saves input if redirect occurs because of error
->withInput();
}else{
$email = Input::get('email');
$username = Input::get('username');
$password = Input::get('email');<--------------- should be 'password'
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community