02e4157a8ca150eb1510746a2ccae085257786cf
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('inc/db_connect.php');
18) require_once('session/checkuser.php');
19) 
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

20) function user_customer_match($cust, $user)
21) {
22)   $customerno = (int) $cust;
23)   $username = mysql_real_escape_string($user);
24)   $result = db_query("SELECT uid FROM system.useraccounts WHERE kunde={$customerno} AND username='{$username}' AND kundenaccount=1;");
25)   if (mysql_num_rows($result) > 0)
26)     return true;
27)   return false;
28) }
29) 
30) 
31) 
bernd webinterface => /webinterface

bernd authored 17 years ago

32) function customer_has_email($customerno, $email)
33) {
34)   $customerno = (int) $customerno;
35)   $email = mysql_real_escape_string($email);
bernd Typo

bernd authored 14 years ago

36)   $result = db_query("SELECT NULL FROM kundendaten.kunden WHERE id=".$customerno." AND (email='{$email}' OR email_extern='{$email}' OR email_rechnung='{$email}');");
bernd webinterface => /webinterface

bernd authored 17 years ago

37)   return (mysql_num_rows($result) > 0);
38) }
39) 
40) 
41) function validate_token($customerno, $token)
42) {
43)   expire_tokens();
44)   $customerno = (int) $customerno;
45)   $token = mysql_real_escape_string($token);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

46)   $result = db_query("SELECT NULL FROM kundendaten.kunden WHERE id={$customerno} AND token='{$token}';");
bernd webinterface => /webinterface

bernd authored 17 years ago

47)   return (mysql_num_rows($result) > 0);
48) }
49) 
50) 
Bernd Wurst Erlaube Useraccount-Initial...

Bernd Wurst authored 11 years ago

51) function get_uid_for_token($token) 
52) {
53)   expire_tokens();
54)   $token = mysql_real_escape_string($token);
55)   $result = db_query("SELECT uid FROM system.usertoken WHERE token='{$token}';");
56)   if (mysql_num_rows($result) == 0) {
57)     return NULL;
58)   }
59)   $data = mysql_fetch_assoc($result);
60)   return $data['uid'];  
61) }
62) 
Bernd Wurst Zeige Username beim Passwor...

Bernd Wurst authored 11 years ago

63) function get_username_for_uid($uid) 
64) {
65)   $uid = (int) $uid;
66)   $result = db_query("SELECT username FROM system.useraccounts WHERE uid={$uid}");
67)   if (mysql_num_rows($result) != 1) {
68)     system_failure("Unexpected number of users with this uid (!= 1)!");
69)   }
70)   $item = mysql_fetch_assoc($result);
71)   return $item['username'];
72) }
73) 
bernd one-time-URLs für systemuser

bernd authored 15 years ago

74) function validate_uid_token($uid, $token)
75) {
76)   expire_tokens();
77)   $uid = (int) $uid;
78)   $token = mysql_real_escape_string($token);
79)   $result = db_query("SELECT NULL FROM system.usertoken WHERE uid={$uid} AND token='{$token}';");
80)   return (mysql_num_rows($result) > 0);
81) }
82) 
83) 
bernd webinterface => /webinterface

bernd authored 17 years ago

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

bernd authored 16 years ago

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

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 15 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 17 years ago

104) {
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

105)   $username = mysql_real_escape_string($username);
bernd webinterface => /webinterface

bernd authored 17 years ago

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

Bernd Wurst authored 10 years ago

107)   $result = db_query("SELECT uid FROM system.useraccounts WHERE username='{$username}'");
108)   $uid = (int) mysql_fetch_assoc($result)['uid'];
109)   
110)   $result = db_query("SELECT created FROM system.usertoken WHERE uid={$uid}");
111)   if (mysql_num_rows($result) > 0) {
112)     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

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

Bernd Wurst authored 10 years ago

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

bernd authored 17 years ago

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

Bernd Wurst authored 10 years ago

121) function emailaddress_for_user($username)
122) {
123)   $username = mysql_real_escape_string($username);
124)   $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}'");
125)   $data = mysql_fetch_assoc($result);
126)   return $data['email'];
127) }
128) 
129) 
bernd webinterface => /webinterface

bernd authored 17 years ago

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

bernd authored 16 years ago

134)   $result = db_query("SELECT token FROM kundendaten.kunden WHERE id={$customerno} AND token IS NOT NULL;");
bernd webinterface => /webinterface

bernd authored 17 years ago

135)   if (mysql_num_rows($result) < 1)
136)     system_failure("Kann das Token nicht auslesen!");
137)   return mysql_fetch_object($result)->token;
138) }
139) 
140) 
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

141) function get_user_token($username) 
142) {
143)   $username = mysql_real_escape_string($username);
144)   $result = db_query("SELECT token FROM system.usertoken AS t INNER JOIN system.useraccounts AS u USING (uid) WHERE username='{$username}'");
145)   $tmp = mysql_fetch_assoc($result);
146)   return $tmp['token'];
147) }
148)