838077f18b71321a685c84329342e6a711d22d09
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) 
5) Written 2008-2012 by schokokeks.org Hosting, namely
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) 
20) function customer_has_email($customerno, $email)
21) {
22)   $customerno = (int) $customerno;
23)   $email = mysql_real_escape_string($email);
bernd Typo

bernd authored 14 years ago

24)   $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

25)   return (mysql_num_rows($result) > 0);
26) }
27) 
28) 
29) function validate_token($customerno, $token)
30) {
31)   expire_tokens();
32)   $customerno = (int) $customerno;
33)   $token = mysql_real_escape_string($token);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 17 years ago

35)   return (mysql_num_rows($result) > 0);
36) }
37) 
38) 
bernd one-time-URLs für systemuser

bernd authored 15 years ago

39) function validate_uid_token($uid, $token)
40) {
41)   expire_tokens();
42)   $uid = (int) $uid;
43)   $token = mysql_real_escape_string($token);
44)   $result = db_query("SELECT NULL FROM system.usertoken WHERE uid={$uid} AND token='{$token}';");
45)   return (mysql_num_rows($result) > 0);
46) }
47) 
48) 
bernd webinterface => /webinterface

bernd authored 17 years ago

49) function expire_tokens()
50) {
51)   $expire = "1 DAY";
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

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

bernd authored 17 years ago

54) }
55) 
56) function invalidate_customer_token($customerno)
57) {
58)   $customerno = (int) $customerno;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 17 years ago

60) }
61)  
bernd one-time-URLs für systemuser

bernd authored 15 years ago

62) function invalidate_systemuser_token($uid)
63) {
64)   $uid = (int) $uid;
65)   db_query("DELETE FROM system.usertoken WHERE uid={$uid} LIMIT 1;");
66) }
67)  
bernd webinterface => /webinterface

bernd authored 17 years ago

68) function create_token($customerno)
69) {
70)   $customerno = (int) $customerno;
71)   expire_tokens();
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 17 years ago

73)   if (mysql_num_rows($result) > 0)
74)   {
75)     $res = mysql_fetch_object($result)->token_create;
76)     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.");
77)     return false;
78)   }
79)   $token = random_string(10);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 17 years ago

81)   return true;
82) }
83) 
84) 
85) function get_customer_token($customerno)
86) {
87)   $customerno = (int) $customerno;
88)   expire_tokens();
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

89)   $result = db_query("SELECT token FROM kundendaten.kunden WHERE id={$customerno} AND token IS NOT NULL;");