dcc202fb249a446ac15c7cf413b9f1b4a3f31b58
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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 2 years ago

5) Written 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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 2 years ago

9) This code is published under a 0BSD license.
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

10) 
11) 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.
12) */
bernd webinterface => /webinterface

bernd authored 17 years ago

13) 
14) require_once('session/checkuser.php');
15) 
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

16) function user_customer_match($cust, $user)
17) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

18)     $args = [":cid" => $cust,
19)                 ":user" => $user, ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

20)     $result = db_query("SELECT uid FROM system.useraccounts WHERE kunde=:cid AND username=:user AND kundenaccount=1", $args);
21)     if ($result->rowCount() > 0) {
22)         return true;
23)     }
24)     return false;
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

25) }
26) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

27) function find_username($input)
Bernd Wurst Passwort-Reset-Funktion akt...

Bernd Wurst authored 7 years ago

28) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

29)     $args = [":user" => $input];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

30)     $result = db_query("SELECT username FROM system.useraccounts WHERE username=:user AND kundenaccount=1", $args);
31)     if ($result->rowCount() > 0) {
32)         $line = $result->fetch();
33)         return $line['username'];
34)     } else {
35)         return false;
36)     }
Bernd Wurst Passwort-Reset-Funktion akt...

Bernd Wurst authored 7 years ago

37) }
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

38) 
bernd webinterface => /webinterface

bernd authored 17 years ago

39) function customer_has_email($customerno, $email)
40) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

41)     $args = [":cid" => $customerno,
42)                 ":email" => $email, ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

43)     $result = db_query("SELECT NULL FROM kundendaten.kunden WHERE id=:cid AND (email=:email OR email_extern=:email OR email_rechnung=:email)", $args);
44)     return ($result->rowCount() > 0);
bernd webinterface => /webinterface

bernd authored 17 years ago

45) }
46) 
47) 
48) function validate_token($customerno, $token)
49) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

50)     expire_tokens();
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

51)     $args = [":cid" => $customerno,
52)                 ":token" => $token, ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

53)     $result = db_query("SELECT NULL FROM kundendaten.kunden WHERE id=:cid AND token=:token", $args);
54)     return ($result->rowCount() > 0);
bernd webinterface => /webinterface

bernd authored 17 years ago

55) }
56) 
57) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

58) function get_uid_for_token($token)
Bernd Wurst Erlaube Useraccount-Initial...

Bernd Wurst authored 11 years ago

59) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

60)     expire_tokens();
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

61)     $result = db_query("SELECT uid FROM system.usertoken WHERE token=?", [$token]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

62)     if ($result->rowCount() == 0) {
63)         return null;
64)     }
65)     $data = $result->fetch();
66)     return $data['uid'];
Bernd Wurst Erlaube Useraccount-Initial...

Bernd Wurst authored 11 years ago

67) }
68) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

69) function get_username_for_uid($uid)
Bernd Wurst Zeige Username beim Passwor...

Bernd Wurst authored 11 years ago

70) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

71)     $result = db_query("SELECT username FROM system.useraccounts WHERE uid=?", [$uid]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

72)     if ($result->rowCount() != 1) {
73)         system_failure("Unexpected number of users with this uid (!= 1)!");
74)     }
75)     $item = $result->fetch();
76)     return $item['username'];
Bernd Wurst Zeige Username beim Passwor...

Bernd Wurst authored 11 years ago

77) }
78) 
bernd one-time-URLs für systemuser

bernd authored 16 years ago

79) function validate_uid_token($uid, $token)
80) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

81)     expire_tokens();
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

82)     $args = [":uid" => $uid,
83)                 ":token" => $token, ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

84)     $result = db_query("SELECT NULL FROM system.usertoken WHERE uid=:uid AND token=:token", $args);
85)     return ($result->rowCount() > 0);
bernd one-time-URLs für systemuser

bernd authored 16 years ago

86) }
87) 
88) 
bernd webinterface => /webinterface

bernd authored 17 years ago

89) function expire_tokens()
90) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 17 years ago

94) }
95) 
96) function invalidate_customer_token($customerno)
97) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

98)     db_query("UPDATE kundendaten.kunden SET token=NULL, token_create=NULL WHERE id=?", [$customerno]);
bernd webinterface => /webinterface

bernd authored 17 years ago

99) }
Hanno remove whitespace in empty...

Hanno authored 6 years ago

100) 
bernd one-time-URLs für systemuser

bernd authored 16 years ago

101) function invalidate_systemuser_token($uid)
102) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

103)     db_query("DELETE FROM system.usertoken WHERE uid=?", [$uid]);
bernd one-time-URLs für systemuser

bernd authored 16 years ago

104) }
Hanno remove whitespace in empty...

Hanno authored 6 years ago

105) 
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

106) function create_token($username)
bernd webinterface => /webinterface

bernd authored 17 years ago

107) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

108)     expire_tokens();
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

109)     $result = db_query("SELECT uid FROM system.useraccounts WHERE username=?", [$username]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

110)     $uid = (int) $result->fetch()['uid'];
Hanno remove whitespace in empty...

Hanno authored 6 years ago

111) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

112)     $result = db_query("SELECT created FROM system.usertoken WHERE uid=?", [$uid]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

113)     if ($result->rowCount() > 0) {
114)         system_failure("Für Ihr Benutzerkonto ist bereits eine Passwort-Erinnerung versendet worden. Bitte wenden Sie sich an den Support wenn Sie diese nicht erhalten haben.");
115)     }
Hanno remove whitespace in empty...

Hanno authored 6 years ago

116) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

117)     $args = [":uid" => $uid,
118)                 ":token" => random_string(16), ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

119)     db_query("INSERT INTO system.usertoken VALUES (:uid, NOW(), NOW() + INTERVAL 1 DAY, :token)", $args);
120)     return true;
bernd webinterface => /webinterface

bernd authored 17 years ago

121) }
122) 
123) 
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

124) function emailaddress_for_user($username)
125) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

126)     $result = db_query("SELECT k.email FROM kundendaten.kunden AS k INNER JOIN system.useraccounts AS u ON (u.kunde=k.id) WHERE u.username=?", [$username]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

127)     $data = $result->fetch();
128)     return $data['email'];
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

129) }
130) 
131) 
bernd webinterface => /webinterface

bernd authored 17 years ago

132) function get_customer_token($customerno)
133) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

134)     expire_tokens();
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

135)     $result = db_query("SELECT token FROM kundendaten.kunden WHERE id=? AND token IS NOT NULL", [$customerno]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

136)     if ($result->rowCount() < 1) {
137)         system_failure("Kann das Token nicht auslesen!");
138)     }
139)     return $result->fetch(PDO::FETCH_OBJ)->token;
bernd webinterface => /webinterface

bernd authored 17 years ago

140) }
141) 
142) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

143) function get_user_token($username)
Bernd Wurst Ermögliche Kunden sich eine...

Bernd Wurst authored 10 years ago

144) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

145)     $result = db_query("SELECT token FROM system.usertoken AS t INNER JOIN system.useraccounts AS u USING (uid) WHERE username=?", [$username]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

146)     $tmp = $result->fetch();
147)     return $tmp['token'];