删除哨兵帐户激活检查

Posted

技术标签:

【中文标题】删除哨兵帐户激活检查【英文标题】: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 中用户的激活检查?

【问题讨论】:

Have you tried it with Sentry::createUser(array('email'=>'email', 'password'=>'password', 'activated'=>true,)); 我没有尝试过,因为我的表中不存在“激活”列。 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. 是的,我说我在原来的问题中改变了它。我要问的问题是如何删除激活码。 一种简单的方法是将表格放回原来的位置,并且简单地使用正确的方法创建/注册帐户,而无需按照文档中的上述说明进行激活。 【参考方案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');
        );
    


【讨论】:

以上是关于删除哨兵帐户激活检查的主要内容,如果未能解决你的问题,请参考以下文章

检查用户是不是激活了他/她的帐户的最有效方法?

magicbook 14 office 激活

Android 内容解析器返回在移动设备中激活的所有帐户 否

电脑文件没有权限删除怎么解决

反应帐户激活

删除用于确认用户电子邮件的 Joomla 激活电子邮件... LOCALHOST