bd22f03937341179a1beaf87aafcde8e61882589
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) 
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

17) require_once('inc/db_connect.php');
bernd webinterface => /webinterface

bernd authored 17 years ago

18) require_once('session/checkuser.php');
19) 
20) function customer_has_email($customerno, $email)
21) {
22)   $customerno = (int) $customerno;
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

23)   $email = mysql_real_escape_string($email);
24)   $result = db_query("SELECT NULL FROM kundendaten.kunden WHERE id=".$customerno." AND (email='{$email}' OR email_extern='{$email}' OR email_rechnung='{$email}');");
25)   return (mysql_num_rows($result) > 0);
bernd webinterface => /webinterface

bernd authored 17 years ago

26) }
27) 
28) 
29) function validate_token($customerno, $token)
30) {
31)   expire_tokens();
32)   $customerno = (int) $customerno;
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

33)   $token = mysql_real_escape_string($token);
34)   $result = db_query("SELECT NULL FROM kundendaten.kunden WHERE id={$customerno} AND token='{$token}';");
35)   return (mysql_num_rows($result) > 0);
bernd webinterface => /webinterface

bernd authored 17 years ago

36) }
37) 
38) 
Bernd Wurst Erlaube Useraccount-Initial...

Bernd Wurst authored 11 years ago

39) function get_uid_for_token($token) 
40) {
41)   expire_tokens();
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

42)   $token = mysql_real_escape_string($token);
43)   $result = db_query("SELECT uid FROM system.usertoken WHERE token='{$token}';");
44)   if (mysql_num_rows($result) == 0) {
Bernd Wurst Erlaube Useraccount-Initial...

Bernd Wurst authored 11 years ago

45)     return NULL;
46)   }
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

47)   $data = mysql_fetch_assoc($result);
Bernd Wurst Erlaube Useraccount-Initial...

Bernd Wurst authored 11 years ago

48)   return $data['uid'];  
49) }
50) 
Bernd Wurst Zeige Username beim Passwor...

Bernd Wurst authored 11 years ago

51) function get_username_for_uid($uid) 
52) {
53)   $uid = (int) $uid;
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

54)   $result = db_query("SELECT username FROM system.useraccounts WHERE uid={$uid}");
55)   if (mysql_num_rows($result) != 1) {
Bernd Wurst Zeige Username beim Passwor...

Bernd Wurst authored 11 years ago

56)     system_failure("Unexpected number of users with this uid (!= 1)!");
57)   }
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

58)   $item = mysql_fetch_assoc($result);
Bernd Wurst Zeige Username beim Passwor...

Bernd Wurst authored 11 years ago

59)   return $item['username'];
60) }
61) 
bernd one-time-URLs für systemuser

bernd authored 15 years ago

62) function validate_uid_token($uid, $token)
63) {
64)   expire_tokens();
65)   $uid = (int) $uid;
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

66)   $token = mysql_real_escape_string($token);
67)   $result = db_query("SELECT NULL FROM system.usertoken WHERE uid={$uid} AND token='{$token}';");
68)   return (mysql_num_rows($result) > 0);
bernd one-time-URLs für systemuser

bernd authored 15 years ago

69) }
70) 
71) 
bernd webinterface => /webinterface

bernd authored 17 years ago

72) function expire_tokens()
73) {
74)   $expire = "1 DAY";
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

75)   db_query("UPDATE kundendaten.kunden SET token=NULL, token_create=NULL WHERE token_create < NOW() - INTERVAL {$expire};");
76)   db_query("DELETE FROM system.usertoken WHERE expire < NOW();");
bernd webinterface => /webinterface

bernd authored 17 years ago

77) }
78) 
79) function invalidate_customer_token($customerno)
80) {
81)   $customerno = (int) $customerno;
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

bernd authored 17 years ago

83) }
84)  
bernd one-time-URLs für systemuser

bernd authored 15 years ago

85) function invalidate_systemuser_token($uid)
86) {
87)   $uid = (int) $uid;
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

88)   db_query("DELETE FROM system.usertoken WHERE uid={$uid} LIMIT 1;");
bernd one-time-URLs für systemuser

bernd authored 15 years ago

89) }
90)  
bernd webinterface => /webinterface

bernd authored 17 years ago

91) function create_token($customerno)
92) {
93)   $customerno = (int) $customerno;
94)   expire_tokens();
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

95)   $result = db_query("SELECT token_create FROM kundendaten.kunden WHERE id={$customerno} AND token_create IS NOT NULL;");
96)   if (mysql_num_rows($result) > 0)
bernd webinterface => /webinterface

bernd authored 17 years ago

97)   {
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

98)     $res = mysql_fetch_object($result)->token_create;
bernd webinterface => /webinterface

bernd authored 17 years ago

99)     input_error("Sie haben diese Funktion kürzlich erst benutzt, an Ihre E-Mail-Adresse wurde bereits am {$res} eine Nachricht verschickt. Sie können diese Funktion erst nach Ablauf von 24 Stunden erneut benutzen.");
100)     return false;
101)   }
102)   $token = random_string(10);
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

bernd authored 17 years ago

104)   return true;
105) }
106) 
107) 
108) function get_customer_token($customerno)
109) {
110)   $customerno = (int) $customerno;
111)   expire_tokens();
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

112)   $result = db_query("SELECT token FROM kundendaten.kunden WHERE id={$customerno} AND token IS NOT NULL;");
113)   if (mysql_num_rows($result) < 1)
bernd webinterface => /webinterface

bernd authored 17 years ago

114)     system_failure("Kann das Token nicht auslesen!");
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

115)   return mysql_fetch_object($result)->token;