bd22f03937341179a1beaf87aafcde8e61882589
bernd Entities repariert

bernd authored 16 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 Entities repariert

bernd authored 16 years ago

16) 
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

17) require_once('inc/db_connect.php');
bernd Entities repariert

bernd authored 16 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 Entities repariert

bernd authored 16 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 Entities repariert

bernd authored 16 years ago

36) }
37) 
38) 
39) function expire_tokens()
40) {
41)   $expire = "1 DAY";
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

42)   db_query("UPDATE kundendaten.kunden SET token=NULL, token_create=NULL WHERE token_create < NOW() - INTERVAL {$expire};");
bernd Entities repariert

bernd authored 16 years ago

43) }
44) 
45) function invalidate_customer_token($customerno)
46) {
47)   $customerno = (int) $customerno;
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

48)   db_query("UPDATE kundendaten.kunden SET token=NULL, token_create=NULL WHERE id={$customerno} LIMIT 1;");
bernd Entities repariert

bernd authored 16 years ago

49) }
50)  
51) function create_token($customerno)
52) {
53)   $customerno = (int) $customerno;
54)   expire_tokens();
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

55)   $result = db_query("SELECT token_create FROM kundendaten.kunden WHERE id={$customerno} AND token_create IS NOT NULL;");
56)   if (mysql_num_rows($result) > 0)
bernd Entities repariert

bernd authored 16 years ago

57)   {
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

58)     $res = mysql_fetch_object($result)->token_create;
bernd Entities repariert

bernd authored 16 years ago

59)     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.");
60)     return false;
61)   }
62)   $token = random_string(10);
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

63)   db_query("UPDATE kundendaten.kunden SET token='{$token}', token_create=now() WHERE id={$customerno} LIMIT 1;");
bernd Entities repariert

bernd authored 16 years ago

64)   return true;
65) }
66) 
67) 
68) function get_customer_token($customerno)
69) {
70)   $customerno = (int) $customerno;
71)   expire_tokens();
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

72)   $result = db_query("SELECT token FROM kundendaten.kunden WHERE id={$customerno} AND token IS NOT NULL;");
73)   if (mysql_num_rows($result) < 1)
bernd Entities repariert

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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