1

I have a table named 'users' that is being used by Sentry however I removed the columns I didn't need such as activation codes and persist codes etc.

This is the structure of my table: Users Table

I am trying to log in using an account I created through 'Sentry::createUser()' however the 'UserNotActivatedException' keeps being thrown and prevents me from logging in.

This is my login code:

public function postLogin() {
    #Build login
    if(!Input::has('email') || !Input::has('password')) {
        return Response::json(['response' => 'Please enter an email address and a password!']);
    }

    try {
        $credentials = [
            'email' => Input::get('email'),
            'password' => Input::get('password')
        ];

        $user = Sentry::authenticate($credentials, false);
        return Response::json(['response' => 'You have been logged in.']);
    } catch(Cartalyst\Sentry\Users\LoginRequiredException $e) {
        return Response::json(['response' => 'Please enter an email address!']);
    } catch(Cartalyst\Sentry\Users\PasswordRequiredException $e) {
        return Response::json(['response' => 'Please enter a password!']);
    } catch(Cartalyst\Sentry\Users\WrongPasswordException $e) {
        return Response::json(['response' => 'That account could not be found1!']);
    } catch(Cartalyst\Sentry\Users\UserNotFoundException $e) {
        return Response::json(['response' => 'That account could not be found2!']);
    } catch(Cartalyst\Sentry\Users\UserNotActivatedException $e) {
        return Response::json(['response' => 'That account could not be found3!']);
    } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) {
        return Response::json(['response' => 'That account could has been suspended!']);
    } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) {
        return Response::json(['response' => 'That account has been banned!']);
    }
}

This is the response that is being returned:

Response

Is there any way to disable the activation check for Users in Sentry?

Gustavo Straube
  • 3,744
  • 6
  • 39
  • 62
Liam Potter
  • 1,732
  • 8
  • 24
  • 47
  • [Have you tried it with `Sentry::createUser(array('email'=>'email', 'password'=>'password', 'activated'=>true,));`](https://cartalyst.com/manual/sentry#sentry::createuser%28%29) – Prix Oct 04 '14 at 13:55
  • I haven't tried that because the 'activated' column doesn't exist inside my table. – Liam Potter Oct 04 '14 at 14:17
  • [Well your table looks rather incomplete, compared to the one provided. If you made custom changes to the table, you will have to also change the code to reflect your changes, such as removing the verification for activated accounts.](https://github.com/cartalyst/sentry/blob/v2.1.4/schema/mysql.sql) – Prix Oct 04 '14 at 14:25
  • Yes, I said that I had changed it in my original question. The question which I'm asking is how do I remove the activation code. – Liam Potter Oct 04 '14 at 14:31
  • One simple way is to place the table back as the original and simple use the right methods to create/register accounts without requiring to be activated as described above on the documentation. – Prix Oct 04 '14 at 15:05

1 Answers1

1

I have fixed the error by creating my own User class and setting the $activated variable to true. User Class:

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
use Cartalyst\Sentry\Users\Eloquent\User as SentryUserModel;

class User extends SentryUserModel implements UserInterface, RemindableInterface {

    public $activated = true;

    public function getAuthIdentifier() {
        return $this->getKey();
    }

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

    public function getRememberToken() {
        return $this->remember_token;
    }

    public function setRememberToken($value) {
        $this->remember_token = $value;
    }

    public function getRememberTokenName() {
        return 'remember_token';
    }

    public function getReminderEmail() {
        return $this->email;
    }

}

I also created two new migrations to add the 'persist_code' and 'last_login' columns to my table:

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddLastLoginToUsersTable extends Migration {

     public function up() {
        Schema::table('users', function(Blueprint $table) {
            $table->string('last_login')->nullable();
        });
    }

    public function down() {
        Schema::table('users', function(Blueprint $table) {
            $table->dropColumn('last_login');
        });
    }

}


use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddPersistCodeToUsersTable extends Migration {

    public function up() {
        Schema::table('users', function(Blueprint $table) {
            $table->string('persist_code')->nullable();
        });
    }

    public function down() {
        Schema::table('users', function(Blueprint $table) {
            $table->dropColumn('persist_code');
        });
    }

}
Liam Potter
  • 1,732
  • 8
  • 24
  • 47