5effc2bd7685822df276c1372dab480cff321941
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 Lizenzinfos in eigenes Modu...

Bernd Wurst authored 10 years ago

5) Written 2008-2014 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) 
17) require_once('session/checkuser.php');
18) 
19) function customer_has_email($customerno, $email)
20) {
21)   $customerno = (int) $customerno;
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

22)   $email = db_escape_string($email);
bernd Tabelle 'kundenkontakt' kom...

bernd authored 14 years ago

23)   $result = db_query("SELECT NULL FROM kundendaten.kunden WHERE id=".$customerno." AND (email='".$email."' OR email_extern='{$email}' OR email_rechnung='{$email'}');");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

24)   return ($result->rowCount() > 0);
bernd Entities repariert

bernd authored 16 years ago

25) }
26) 
27) 
28) function validate_token($customerno, $token)
29) {
30)   expire_tokens();
31)   $customerno = (int) $customerno;
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

32)   $token = db_escape_string($token);
bernd Entities repariert

bernd authored 16 years ago

33)   $result = db_query("SELECT NULL FROM kundendaten.kunden WHERE id={$customerno} AND token='{$token}';");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

34)   return ($result->rowCount() > 0);
bernd Entities repariert

bernd authored 16 years ago

35) }
36) 
37) 
38) function expire_tokens()
39) {
40)   $expire = "1 DAY";
41)   db_query("UPDATE kundendaten.kunden SET token=NULL, token_create=NULL WHERE token_create < NOW() - INTERVAL {$expire};");
42) }
43) 
44) function invalidate_customer_token($customerno)
45) {
46)   $customerno = (int) $customerno;
47)   db_query("UPDATE kundendaten.kunden SET token=NULL, token_create=NULL WHERE id={$customerno} LIMIT 1;");
48) }
49)  
50) function create_token($customerno)
51) {
52)   $customerno = (int) $customerno;
53)   expire_tokens();
54)   $result = db_query("SELECT token_create FROM kundendaten.kunden WHERE id={$customerno} AND token_create IS NOT NULL;");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

55)   if ($result->rowCount() > 0)
bernd Entities repariert

bernd authored 16 years ago

56)   {
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

57)     $res = $result->fetch(PDO::FETCH_OBJ)->token_create;
bernd Entities repariert

bernd authored 16 years ago

58)     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.");
59)     return false;
60)   }
61)   $token = random_string(10);
62)   db_query("UPDATE kundendaten.kunden SET token='{$token}', token_create=now() WHERE id={$customerno} LIMIT 1;");
63)   return true;
64) }
65) 
66) 
67) function get_customer_token($customerno)
68) {
69)   $customerno = (int) $customerno;
70)   expire_tokens();
71)   $result = db_query("SELECT token FROM kundendaten.kunden WHERE id={$customerno} AND token IS NOT NULL;");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

72)   if ($result->rowCount() < 1)
bernd Entities repariert

bernd authored 16 years ago

73)     system_failure("Kann das Token nicht auslesen!");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

74)   return $result->fetch(PDO::FETCH_OBJ)->token;