Add infos into target window
[ryzomcore.git] / ryzom / server / www / login / libs / r2_login_user.php
blob21119f299e0ea40c3c6aa4d178479641855cfbc0
1 <?php
3 class RingUser {
5 function __construct($db, $login, $password, $clientApplication, $submittedLang) {
6 global $AcceptUnknownUser;
7 $this->db = $db;
8 $this->login = $login;
9 $this->password = $password;
10 $this->lang = $submittedLang;
11 $this->client = $clientApplication;
13 $this->db->select();
15 $this->user = $this->db->querySingle('SELECT * FROM user WHERE Login="'._e($this->login).'"');
16 if ($this->user) {
17 $this->uid = $this->user['UId'];
18 } else {
19 if ($AcceptUnknownUser && $this->password) {
20 $this->db->query('INSERT INTO user SET Login = "'._e($this->login).'", Password = "'._e($this->password).'", ShardId=-1, Privilege=":DEV:"');
21 $this->user = $this->db->querySingle('SELECT * FROM user WHERE Login="'._e($this->login).'"');
22 $this->uid = $this->user['UId'];
23 } else {
24 $this->uid = 0;
25 $this->user = array('Password' => 'AA');
28 $this->authenticate = False;
29 setMsgLanguage($submittedLang);
33 function askSalt() {
34 $user = $this->user;
35 if ($user)
36 echo '1:'.substr($user['Password'], 0, 2);
37 else
38 dieError(2001, '', 'askSalt');
41 function createRingInfo($ServerDomain) {
42 $domainInfo = $ServerDomain->domainInfo;
43 $this->db->select($domainInfo['ring_db_name']);
44 $result = $this->db->querySingle('SELECT user_id FROM ring_users where user_id = "'._e($this->uid).'"');
45 if (!$result)
46 $this->db->query('INSERT INTO ring_users SET user_id = "'._e($this->uid).'", user_name = "'._e($this->login).'", user_type="ut_pioneer"');
49 function checkAccess() {
52 function updatePrivs($privs) {
53 $this->db->query('UPDATE user SET ExtendedPrivilege="'._e($privs).'" WHERE UId='._e($this->uid));
54 $this->user['ExtendedPrivilege'] = $privs;
57 function addPriv($priv) {
58 $eprivs = explode(':', $this->user['ExtendedPrivilege']);
59 $privs = array();
60 foreach ($eprivs as $p)
61 $privs[$p] = $p;
62 unset($privs['']);
63 $privs[$priv] = $priv;
64 $this->updatePrivs(':'.implode(':', array_keys($privs)).':');
67 function removePriv($priv) {
68 $eprivs = explode(':', $this->user['ExtendedPrivilege']);
69 $privs = array();
70 foreach ($eprivs as $p)
71 $privs[$p] = $p;
72 unset($privs['']);
73 unset($privs[$priv]);
74 $this->updatePrivs(':'.implode(':', array_keys($privs)).':');
78 function checkPermission($ServerDomain) {
79 $perm = $this->db->querySingle('SELECT * FROM permission WHERE UId="'._e($this->uid).'" AND ClientApplication="'._e($this->client).'"');
80 if (!$perm)
81 $this->db->query('INSERT INTO permission (UId, ClientApplication, ShardId, AccessPrivilege) VALUES ("'._e($this->uid).'", "'._e($this->client).'", "'.$ServerDomain->getShard('ShardId').'", "OPEN")');
84 function logConnection() {
87 function checkValidity($password, $ServerDomain) {
88 $user = $this->user;
90 if (!$user)
91 dieError(3009, $this->login);
93 if ($this->user['Password'] == $password) {
94 $this->login = $this->user['Login']; // Correct case
96 $this->checkAccess();
97 $this->checkPermission($ServerDomain);
98 $this->logConnection();
100 $this->priv = $this->user['Privilege'];
102 return True;
103 } else
104 dieError(2004);
105 return False;