在我的插件中,我只有用户名或电子邮件,我必须授权该用户。我发现了下一个问题,但它对我不起作用:
class ApiPlugin extends ApiBase {
public function execute() {
$params = $this->extractRequestParams();
switch ( $params['do'] ) {
case 'login':
// Registering. Works fine.
$user = User::newFromName( 'admin' );
$user->setEmail( admin@email.com );
$user->setRealName( 'admin' );
$uid = $user->idForName();
if ( $uid === 0 ) {
$user->addToDatabase();
$user->setPassword( generate_password() );
$user->saveSettings();
}
$ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
$ssu->doUpdate();
if ($user->isLoggedIn()) $user->doLogout();
//Logging in.
$id = User::idFromName('admin');
$user->setID($id);
$user->loadFromId();
$user->setToken();
$user->saveSettings();
wfSetupSession();
$user->setCookies();
break;
}
}
}
此外,另一个问题是直接从数据库获取密码哈希,但这是野蛮行为......
提前致谢!