6dc51ba446a2faec08d321f9703e7c34a0aa82c6
bernd webinterface => /webinterface

bernd authored 17 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Bernd Wurst Lizenzinfos in eigenes Modu...

Bernd Wurst authored 10 years ago

5) Written 2008-2014 by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
9) To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10) 
11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
14) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15) */
bernd webinterface => /webinterface

bernd authored 17 years ago

16) 
17) require_once('session/checkuser.php');
18) 
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

19) function user_customer_match($cust, $user)
20) {
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

21)   $args = array(":cid" => $cust,
22)                 ":user" => $user);
23)   $result = db_query("SELECT uid FROM system.useraccounts WHERE kunde=:cid AND username=:user AND kundenaccount=1", $args);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

24)   if ($result->rowCount() > 0)
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

25)     return true;
26)   return false;
27) }
28) 
Bernd Wurst Passwort-Reset-Funktion akt...

Bernd Wurst authored 7 years ago

29) function find_username($input) 
30) {
31)   $args = array(":user" => $input);
32)   $result = db_query("SELECT username FROM system.useraccounts WHERE username=:user AND kundenaccount=1", $args);
33)   if ($result->rowCount() > 0)
34)   {
35)     $line = $result->fetch();
36)     return $line['username'];
37)   } else {
38)     return false;
39)   }
40) }
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

41) 
bernd webinterface => /webinterface

bernd authored 17 years ago

42) function customer_has_email($customerno, $email)
43) {
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

44)   $args = array(":cid" => $customerno,
45)                 ":email" => $email);
46)   $result = db_query("SELECT NULL FROM kundendaten.kunden WHERE id=:cid AND (email=:email OR email_extern=:email OR email_rechnung=:email)", $args);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

47)   return ($result->rowCount() > 0);
bernd webinterface => /webinterface

bernd authored 17 years ago

48) }
49) 
50) 
51) function validate_token($customerno, $token)
52) {
53)   expire_tokens();
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

54)   $args = array(":cid" => $customerno,
55)                 ":token" => $token);
56)   $result = db_query("SELECT NULL FROM kundendaten.kunden WHERE id=:cid AND token=:token", $args);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

57)   return ($result->rowCount() > 0);
bernd webinterface => /webinterface

bernd authored 17 years ago

58) }
59) 
60) 
Bernd Wurst Erlaube Useraccount-Initial...

Bernd Wurst authored 11 years ago

61) function get_uid_for_token($token) 
62) {
63)   expire_tokens();
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

64)   $result = db_query("SELECT uid FROM system.usertoken WHERE token=?", array($token));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

65)   if ($result->rowCount() == 0) {
Bernd Wurst Erlaube Useraccount-Initial...

Bernd Wurst authored 11 years ago

66)     return NULL;
67)   }
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

68)   $data = $result->fetch();
Bernd Wurst Erlaube Useraccount-Initial...

Bernd Wurst authored 11 years ago

69)   return $data['uid'];  
70) }
71) 
Bernd Wurst Zeige Username beim Passwor...

Bernd Wurst authored 11 years ago

72) function get_username_for_uid($uid) 
73) {
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

74)   $result = db_query("SELECT username FROM system.useraccounts WHERE uid=?", array($uid));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

75)   if ($result->rowCount() != 1) {
Bernd Wurst Zeige Username beim Passwor...

Bernd Wurst authored 11 years ago

76)     system_failure("Unexpected number of users with this uid (!= 1)!");
77)   }
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

78)   $item = $result->fetch();
Bernd Wurst Zeige Username beim Passwor...

Bernd Wurst authored 11 years ago

79)   return $item['username'];
80) }
81) 
bernd one-time-URLs für systemuser

bernd authored 15 years ago

82) function validate_uid_token($uid, $token)
83) {
84)   expire_tokens();
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

85)   $args = array(":uid" => $uid,
86)                 ":token" => $token);
87)   $result = db_query("SELECT NULL FROM system.usertoken WHERE uid=:uid AND token=:token", $args);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

88)   return ($result->rowCount() > 0);
bernd one-time-URLs für systemuser

bernd authored 15 years ago

89) }
90) 
91) 
bernd webinterface => /webinterface

bernd authored 17 years ago

92) function expire_tokens()
93) {
94)   $expire = "1 DAY";
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

95)   db_query("UPDATE kundendaten.kunden SET token=NULL, token_create=NULL WHERE token_create < NOW() - INTERVAL {$expire};");
bernd one-time-URLs für systemuser

bernd authored 15 years ago

96)   db_query("DELETE FROM system.usertoken WHERE expire < NOW();");
bernd webinterface => /webinterface

bernd authored 17 years ago

97) }
98) 
99) function invalidate_customer_token($customerno)
100) {
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

101)   db_query("UPDATE kundendaten.kunden SET token=NULL, token_create=NULL WHERE id=?", array($customerno));
bernd webinterface => /webinterface

bernd authored 17 years ago

102) }
103)  
bernd one-time-URLs für systemuser

bernd authored 15 years ago

104) function invalidate_systemuser_token($uid)
105) {
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

106)   db_query("DELETE FROM system.usertoken WHERE uid=?", array($uid));
bernd one-time-URLs für systemuser

bernd authored 15 years ago

107) }
108)  
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

109) function create_token($username)
bernd webinterface => /webinterface

bernd authored 17 years ago

110) {
111)   expire_tokens();
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

112)   $result = db_query("SELECT uid FROM system.useraccounts WHERE username=?", array($username));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

113)   $uid = (int) $result->fetch()['uid'];
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

114)   
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

115)   $result = db_query("SELECT created FROM system.usertoken WHERE uid=?", array($uid));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

116)   if ($result->rowCount() > 0) {
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

117)     system_failure("Für Ihr Benutzerkonto ist bereits eine Passwort-Erinnerung versendet worden. Bitte wenden Sie sich an den Support wenn Sie diese nicht erhalten haben.");
bernd webinterface => /webinterface

bernd authored 17 years ago

118)   }
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

119)   
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

120)   $args = array(":uid" => $uid,
121)                 ":token" => random_string(16));
Bernd Wurst Passwort-Reset-Funktion akt...

Bernd Wurst authored 7 years ago

122)   db_query("INSERT INTO system.usertoken VALUES (:uid, NOW(), NOW() + INTERVAL 1 DAY, :token)", $args);
bernd webinterface => /webinterface

bernd authored 17 years ago

123)   return true;
124) }
125) 
126) 
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

127) function emailaddress_for_user($username)
128) {
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

129)   $result = db_query("SELECT k.email FROM kundendaten.kunden AS k INNER JOIN system.useraccounts AS u ON (u.kunde=k.id) WHERE u.username=?", array($username));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

130)   $data = $result->fetch();
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

131)   return $data['email'];
132) }
133) 
134) 
bernd webinterface => /webinterface

bernd authored 17 years ago

135) function get_customer_token($customerno)
136) {
137)   expire_tokens();
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

138)   $result = db_query("SELECT token FROM kundendaten.kunden WHERE id=? AND token IS NOT NULL", array($customerno));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

139)   if ($result->rowCount() < 1)
bernd webinterface => /webinterface

bernd authored 17 years ago

140)     system_failure("Kann das Token nicht auslesen!");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

141)   return $result->fetch(PDO::FETCH_OBJ)->token;
bernd webinterface => /webinterface

bernd authored 17 years ago

142) }
143) 
144) 
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

145) function get_user_token($username) 
146) {
Bernd Wurst Modul index auf prepared st...

Bernd Wurst authored 10 years ago

147)   $result = db_query("SELECT token FROM system.usertoken AS t INNER JOIN system.useraccounts AS u USING (uid) WHERE username=?", array($username));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

148)   $tmp = $result->fetch();
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

149)   return $tmp['token'];
150) }
151)