e31e3e4ddd524edb7f9ac61797fbce20f9d1620b
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) 
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 Wurst Erlaube Useraccount-Initial...

Bernd Wurst authored 11 years ago

39) function get_uid_for_token($token) 
40) {
41)   expire_tokens();
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) {
45)     return NULL;
46)   }
47)   $data = mysql_fetch_assoc($result);
48)   return $data['uid'];  
49) }
50) 
bernd one-time-URLs für systemuser

bernd authored 15 years ago

51) function validate_uid_token($uid, $token)
52) {
53)   expire_tokens();
54)   $uid = (int) $uid;
55)   $token = mysql_real_escape_string($token);
56)   $result = db_query("SELECT NULL FROM system.usertoken WHERE uid={$uid} AND token='{$token}';");
57)   return (mysql_num_rows($result) > 0);
58) }
59) 
60) 
bernd webinterface => /webinterface

bernd authored 17 years ago

61) function expire_tokens()
62) {
63)   $expire = "1 DAY";
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

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

bernd authored 17 years ago

66) }
67) 
68) function invalidate_customer_token($customerno)
69) {
70)   $customerno = (int) $customerno;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 17 years ago

72) }
73)  
bernd one-time-URLs für systemuser

bernd authored 15 years ago

74) function invalidate_systemuser_token($uid)
75) {
76)   $uid = (int) $uid;
77)   db_query("DELETE FROM system.usertoken WHERE uid={$uid} LIMIT 1;");
78) }
79)  
bernd webinterface => /webinterface

bernd authored 17 years ago

80) function create_token($customerno)
81) {
82)   $customerno = (int) $customerno;
83)   expire_tokens();
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

85)   if (mysql_num_rows($result) > 0)
86)   {
87)     $res = mysql_fetch_object($result)->token_create;
88)     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.");
89)     return false;
90)   }
91)   $token = random_string(10);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 17 years ago

93)   return true;
94) }
95) 
96) 
97) function get_customer_token($customerno)
98) {
99)   $customerno = (int) $customerno;
100)   expire_tokens();
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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