删除Sentry帐户激活检查

时间:2014-10-04 13:38:59

标签: php mysql laravel authentication cartalyst-sentry

我有一个名为' users'这是Sentry使用的,但我删除了我不需要的列,如激活码和持久代码等。

这是我桌子的结构: Users Table

我正在尝试使用我通过&Sentry :: createUser()'创建的帐户登录然而,' UserNotActivatedException'不断被抛出并阻止我登录。

这是我的登录代码:

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!']);
    }
}

这是要返回的响应:

Response

有没有办法禁用Sentry中用户的激活检查?

1 个答案:

答案 0 :(得分:1)

我通过创建自己的User类并将$ activated变量设置为true来修复错误。 用户类:

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

}

我还创建了两个新的迁移,将'persist_code'和'last_login'列添加到我的表中:

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

}
相关问题