f1f231f5e074dfa038e70a67d39849e80f2b4b4d
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 Updated copyright notice (2...

Bernd Wurst authored 11 years ago

5) Written 2008-2013 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) {
21)   $customerno = (int) $cust;
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

22)   $username = db_escape_string($user);
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

23)   $result = db_query("SELECT uid FROM system.useraccounts WHERE kunde={$customerno} AND username='{$username}' AND kundenaccount=1;");
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) 
29) 
30) 
bernd webinterface => /webinterface

bernd authored 17 years ago

31) function customer_has_email($customerno, $email)
32) {
33)   $customerno = (int) $customerno;
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

34)   $email = db_escape_string($email);
bernd Typo

bernd authored 14 years ago

35)   $result = db_query("SELECT NULL FROM kundendaten.kunden WHERE id=".$customerno." AND (email='{$email}' OR email_extern='{$email}' OR email_rechnung='{$email}');");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 17 years ago

37) }
38) 
39) 
40) function validate_token($customerno, $token)
41) {
42)   expire_tokens();
43)   $customerno = (int) $customerno;
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

44)   $token = db_escape_string($token);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

45)   $result = db_query("SELECT NULL FROM kundendaten.kunden WHERE id={$customerno} AND token='{$token}';");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 17 years ago

47) }
48) 
49) 
Bernd Wurst Erlaube Useraccount-Initial...

Bernd Wurst authored 11 years ago

50) function get_uid_for_token($token) 
51) {
52)   expire_tokens();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

53)   $token = db_escape_string($token);
Bernd Wurst Erlaube Useraccount-Initial...

Bernd Wurst authored 11 years ago

54)   $result = db_query("SELECT uid FROM system.usertoken WHERE token='{$token}';");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 11 years ago

56)     return NULL;
57)   }
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 11 years ago

59)   return $data['uid'];  
60) }
61) 
Bernd Wurst Zeige Username beim Passwor...

Bernd Wurst authored 11 years ago

62) function get_username_for_uid($uid) 
63) {
64)   $uid = (int) $uid;
65)   $result = db_query("SELECT username FROM system.useraccounts WHERE uid={$uid}");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 11 years ago

70)   return $item['username'];
71) }
72) 
bernd one-time-URLs für systemuser

bernd authored 15 years ago

73) function validate_uid_token($uid, $token)
74) {
75)   expire_tokens();
76)   $uid = (int) $uid;
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

77)   $token = db_escape_string($token);
bernd one-time-URLs für systemuser

bernd authored 15 years ago

78)   $result = db_query("SELECT NULL FROM system.usertoken WHERE uid={$uid} AND token='{$token}';");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

80) }
81) 
82) 
bernd webinterface => /webinterface

bernd authored 17 years ago

83) function expire_tokens()
84) {
85)   $expire = "1 DAY";
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

86)   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

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

bernd authored 17 years ago

88) }
89) 
90) function invalidate_customer_token($customerno)
91) {
92)   $customerno = (int) $customerno;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

93)   db_query("UPDATE kundendaten.kunden SET token=NULL, token_create=NULL WHERE id={$customerno} LIMIT 1;");
bernd webinterface => /webinterface

bernd authored 17 years ago

94) }
95)  
bernd one-time-URLs für systemuser

bernd authored 15 years ago

96) function invalidate_systemuser_token($uid)
97) {
98)   $uid = (int) $uid;
99)   db_query("DELETE FROM system.usertoken WHERE uid={$uid} LIMIT 1;");
100) }
101)  
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

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

bernd authored 17 years ago

103) {
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

104)   $username = db_escape_string($username);
bernd webinterface => /webinterface

bernd authored 17 years ago

105)   expire_tokens();
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

106)   $result = db_query("SELECT uid FROM system.useraccounts WHERE username='{$username}'");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

108)   
109)   $result = db_query("SELECT created FROM system.usertoken WHERE uid={$uid}");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

111)     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

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

Bernd Wurst authored 10 years ago

113)   
114)   $token = random_string(16);
115)   db_query("INSERT INTO system.usertoken VALUES ({$uid}, NOW(), NOW() + INTERVAL 1 DAY, '{$token}')");
bernd webinterface => /webinterface

bernd authored 17 years ago

116)   return true;
117) }
118) 
119) 
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

120) function emailaddress_for_user($username)
121) {
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

122)   $username = db_escape_string($username);
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

123)   $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='{$username}'");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

125)   return $data['email'];
126) }
127) 
128) 
bernd webinterface => /webinterface

bernd authored 17 years ago

129) function get_customer_token($customerno)
130) {
131)   $customerno = (int) $customerno;
132)   expire_tokens();
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 17 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 17 years ago

137) }
138) 
139) 
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

140) function get_user_token($username) 
141) {
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

142)   $username = db_escape_string($username);
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

143)   $result = db_query("SELECT token FROM system.usertoken AS t INNER JOIN system.useraccounts AS u USING (uid) WHERE username='{$username}'");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

145)   return $tmp['token'];
146) }
147)