MediaWiki REL1_31
OATHUserRepository.php
Go to the documentation of this file.
1<?php
21
24 protected $lb;
25
27 protected $cache;
28
35 $this->lb = $lb;
36 $this->cache = $cache;
37 }
38
43 public function findByUser( User $user ) {
44 $oathUser = $this->cache->get( $user->getName() );
45 if ( !$oathUser ) {
46 $oathUser = new OATHUser( $user, null );
47
48 $uid = CentralIdLookup::factory()->centralIdFromLocalUser( $user );
49 $res = $this->getDB( DB_REPLICA )->selectRow(
50 'oathauth_users',
51 '*',
52 [ 'id' => $uid ],
53 __METHOD__
54 );
55 if ( $res ) {
56 $key = new OATHAuthKey( $res->secret, explode( ',', $res->scratch_tokens ) );
57 $oathUser->setKey( $key );
58 }
59
60 $this->cache->set( $user->getName(), $oathUser );
61 }
62 return $oathUser;
63 }
64
68 public function persist( OATHUser $user ) {
69 $this->getDB( DB_MASTER )->replace(
70 'oathauth_users',
71 [ 'id' ],
72 [
73 'id' => CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() ),
74 'secret' => $user->getKey()->getSecret(),
75 'scratch_tokens' => implode( ',', $user->getKey()->getScratchTokens() ),
76 ],
77 __METHOD__
78 );
79 $this->cache->set( $user->getUser()->getName(), $user );
80 }
81
85 public function remove( OATHUser $user ) {
86 $this->getDB( DB_MASTER )->delete(
87 'oathauth_users',
88 [ 'id' => CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() ) ],
89 __METHOD__
90 );
91 $this->cache->delete( $user->getUser()->getName() );
92 }
93
98 private function getDB( $index ) {
99 global $wgOATHAuthDatabase;
100
101 return $this->lb->getConnectionRef( $index, [], $wgOATHAuthDatabase );
102 }
103}
interface is intended to be more or less compatible with the PHP memcached client.
Definition BagOStuff.php:47
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
persist(OATHUser $user)
__construct(LoadBalancer $lb, BagOStuff $cache)
OATHUserRepository constructor.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition OATHUser.php:24
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:53
getName()
Get the user name, or the IP of an anonymous user.
Definition User.php:2482
Helper class to handle automatically marking connections as reusable (via RAII pattern) as well handl...
Definition DBConnRef.php:15
Database connection, tracking, load balancing, and transaction manager for a cluster.
$res
Definition database.txt:21
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:247
you have access to all of the normal MediaWiki so you can get a DB use the cache
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:29