MediaWiki REL1_34
OATHUser.php
Go to the documentation of this file.
1<?php
20
21use User;
22
28class 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}
$wgSitename
Name of the site.
Class representing a user from OATH's perspective.
Definition OATHUser.php:28
setModule(IModule $module=null)
Sets the module instance associated with this user.
Definition OATHUser.php:149
clearAllKeys()
Removes all keys associated with the user Warning: This only removes the keys in memory,...
Definition OATHUser.php:118
setKeys( $keys=[])
Set the key associated with this user.
Definition OATHUser.php:104
getModule()
Gets the module instance associated with this user.
Definition OATHUser.php:140
__construct(User $user, $keys=[])
Constructor.
Definition OATHUser.php:45
getKeys()
Get the key associated with this user.
Definition OATHUser.php:81
keyTypeCorrect(IAuthKey $key)
All keys set for the user must be of the same type.
Definition OATHUser.php:167
addKey(IAuthKey $key)
Adds single key to the key array.
Definition OATHUser.php:127
getFirstKey()
Useful for modules that operate on single-key premise, as well as testing the key type,...
Definition OATHUser.php:92
disable()
Disables current (if any) auth method.
Definition OATHUser.php:156
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...