【问题标题】:Remove Sentry Account Activation Check删除哨兵帐户激活检查
【发布时间】:2014-11-29 08:44:31
【问题描述】:

我有一个 Sentry 正在使用的名为“用户”的表,但是我删除了不需要的列,例如激活码和持久码等。

这是我的表的结构:

我正在尝试使用通过“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!']);
    }
}

这是正在返回的响应:

有什么方法可以禁用 Sentry 中用户的激活检查?

【问题讨论】:

标签: php mysql laravel authentication cartalyst-sentry


【解决方案1】:

我已通过创建自己的 User 类并将 $activate 变量设置为 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');
        });
    }

}

【讨论】:

    猜你喜欢
    • 2021-11-14
    • 2014-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多