MediaWiki  1.34.0
OATHUser.php
Go to the documentation of this file.
1 <?php
20 
21 use User;
22 
28 class OATHUser {
30  private $user;
31 
33  private $keys;
34 
38  private $module;
39 
45  public function __construct( User $user, $keys = [] ) {
46  $this->user = $user;
47  $this->setKeys( $keys );
48  }
49 
53  public function getUser() {
54  return $this->user;
55  }
56 
60  public function getIssuer() {
61  global $wgSitename, $wgOATHAuthAccountPrefix;
62 
63  if ( $wgOATHAuthAccountPrefix !== false ) {
64  return $wgOATHAuthAccountPrefix;
65  }
66  return $wgSitename;
67  }
68 
72  public function getAccount() {
73  return $this->user->getName();
74  }
75 
81  public function getKeys() {
82  return $this->keys;
83  }
84 
92  public function getFirstKey() {
93  if ( !empty( $this->keys ) ) {
94  return $this->keys[0];
95  }
96  return null;
97  }
98 
104  public function setKeys( $keys = [] ) {
105  $this->keys = [];
106  if ( is_array( $keys ) ) {
107  foreach ( $keys as $key ) {
108  $this->addKey( $key );
109  }
110  }
111  }
112 
118  public function clearAllKeys() {
119  $this->keys = [];
120  }
121 
127  public function addKey( IAuthKey $key ) {
128  if ( !$this->keyTypeCorrect( $key ) ) {
129  return;
130  }
131 
132  $this->keys[] = $key;
133  }
134 
140  public function getModule() {
141  return $this->module;
142  }
143 
149  public function setModule( IModule $module = null ) {
150  $this->module = $module;
151  }
152 
156  public function disable() {
157  $this->keys = [];
158  $this->module = null;
159  }
160 
167  private function keyTypeCorrect( IAuthKey $key ) {
168  foreach ( $this->keys as $keyToTest ) {
169  if ( get_class( $keyToTest ) !== get_class( $key ) ) {
170  return false;
171  }
172  }
173  return true;
174  }
175 }
MediaWiki\Extension\OATHAuth\OATHUser\getModule
getModule()
Gets the module instance associated with this user.
Definition: OATHUser.php:140
MediaWiki\Extension\OATHAuth\IAuthKey
Definition: IAuthKey.php:8
MediaWiki\Extension\OATHAuth\OATHUser
Class representing a user from OATH's perspective.
Definition: OATHUser.php:28
MediaWiki\Extension\OATHAuth\OATHUser\clearAllKeys
clearAllKeys()
Removes all keys associated with the user Warning: This only removes the keys in memory,...
Definition: OATHUser.php:118
MediaWiki\Extension\OATHAuth\OATHUser\getKeys
getKeys()
Get the key associated with this user.
Definition: OATHUser.php:81
MediaWiki\Extension\OATHAuth\OATHUser\$keys
IAuthKey[] $keys
Definition: OATHUser.php:33
MediaWiki\Extension\OATHAuth\OATHUser\getAccount
getAccount()
Definition: OATHUser.php:72
MediaWiki\Extension\OATHAuth\OATHUser\addKey
addKey(IAuthKey $key)
Adds single key to the key array.
Definition: OATHUser.php:127
MediaWiki\Extension\OATHAuth\OATHUser\setKeys
setKeys( $keys=[])
Set the key associated with this user.
Definition: OATHUser.php:104
MediaWiki\Extension\OATHAuth\OATHUser\getIssuer
getIssuer()
Definition: OATHUser.php:60
MediaWiki\Extension\OATHAuth\OATHUser\setModule
setModule(IModule $module=null)
Sets the module instance associated with this user.
Definition: OATHUser.php:149
MediaWiki\Extension\OATHAuth\OATHUser\$user
User $user
Definition: OATHUser.php:30
MediaWiki\Extension\OATHAuth\OATHUser\$module
IModule $module
Definition: OATHUser.php:38
MediaWiki\Extension\OATHAuth\OATHUser\__construct
__construct(User $user, $keys=[])
Constructor.
Definition: OATHUser.php:45
$wgSitename
$wgSitename
Name of the site.
Definition: DefaultSettings.php:80
MediaWiki\Extension\OATHAuth\OATHUser\keyTypeCorrect
keyTypeCorrect(IAuthKey $key)
All keys set for the user must be of the same type.
Definition: OATHUser.php:167
MediaWiki\Extension\OATHAuth
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
MediaWiki\Extension\OATHAuth\OATHUser\getFirstKey
getFirstKey()
Useful for modules that operate on single-key premise, as well as testing the key type,...
Definition: OATHUser.php:92
MediaWiki\Extension\OATHAuth\OATHUser\getUser
getUser()
Definition: OATHUser.php:53
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
MediaWiki\Extension\OATHAuth\OATHUser\disable
disable()
Disables current (if any) auth method.
Definition: OATHUser.php:156
MediaWiki\Extension\OATHAuth\IModule
Definition: IModule.php:9