Laravel 4 设置Laravel';授权用户

Laravel 4 设置Laravel';授权用户,laravel-4,Laravel 4,我正在使用Laravel的Auth类对我网站上的用户进行身份验证,基本Auth::trust(…)之类的东西 最近出现了一个新的需求(耶,涉众!),现在用户需要创建新用户(辅助用户)。由于主要用户的登录是通过第三方系统进行的,因此我无法将次要用户与主要用户一起存储(并重新使用当前的身份验证系统) 我想到的是以某种方式告诉Auth类登录,并在Auth::user()方法上强制设置用户 有办法做到这一点吗?编辑 为此,您必须在辅助用户模型中使用UserInterface类 use Illuminat

我正在使用Laravel的
Auth
类对我网站上的用户进行身份验证,基本
Auth::trust(…)
之类的东西

最近出现了一个新的需求(耶,涉众!),现在用户需要创建新用户(辅助用户)。由于主要用户的登录是通过第三方系统进行的,因此我无法将次要用户与主要用户一起存储(并重新使用当前的身份验证系统)

我想到的是以某种方式告诉
Auth
类登录,并在
Auth::user()
方法上强制设置用户

有办法做到这一点吗?

编辑

为此,您必须在辅助用户模型中使用
UserInterface

use Illuminate\Auth\UserInterface;
然后需要实现5个必需的方法:
getAuthIdentifier
getAuthPassword
getMemberToken
setMemberToken
getMemberTokenName

由于显然
config>auth
在运行时无法更改,因此您必须手动检查用户的凭据,获取实例并执行
auth::login($secondaryUser)


如果您有2个
用户
模型,我认为只要它们扩展了主用户类

,或者更简单一些:
Auth::loginUsingId(1):)我将编辑您的问题,在您的解决方案之外添加一些要求,然后接受它。
<?php

use Illuminate\Auth\UserInterface;

class SecondaryUser extends Eloquent implements UserInterface {

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'secondary_users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password');

    /**
     * Get the unique identifier for the secondary user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Get the password for the secondary user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

    /**
     * Get the token value for the "remember me" session.
     *
     * @return string
     */
    public function getRememberToken()
    {
        return $this->remember_token;
    }

    /**
     * Set the token value for the "remember me" session.
     *
     * @param  string  $value
     * @return void
     */
    public function setRememberToken($value)
    {
        $this->remember_token = $value;
    }

    /**
     * Get the column name for the "remember me" token.
     *
     * @return string
     */
    public function getRememberTokenName()
    {
        return 'remember_token';
    }

    public function mainUser()
    {
        return $this->belongsTo('User');
    }

}
$user = User::find(1);
Auth::login($user);