Support the ongoing development of Laravel.io →
posted 10 years ago
Authentication
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

@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

Last updated 2 years ago.
0

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';
	}

}

Last updated 2 years ago.
0

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)
Last updated 2 years ago.
0

This may help. Try Sentry for your authentication, It is easy and powerful.

Last updated 2 years ago.
0

@Sikandhar

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.

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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
            }
Last updated 2 years ago.
0

@CleverCookie

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.');
	}
Last updated 2 years ago.
0

Thinking about using sentry, but I do not want to give up on this. I always figure out the solution.

Last updated 2 years ago.
0

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?

Last updated 2 years ago.
0

I removed the 'active' => 1 and it still throws the error in my conditional.

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

I also tried changing the property to

'active'	=>	User::where('active', '=', '1')->get();
Last updated 2 years ago.
0

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'
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

swgj19 swgj19 Joined 11 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.