Browse code

Verify-Funktion für Kunden-Mailadressen eingebaut. Vorbereitung für Self-service-Änderungen

Bernd Wurst authored on11/11/2017 11:49:10
Showing4 changed files
... ...
@@ -12,3 +12,4 @@ RewriteEngine On
12 12
 RewriteBase /
13 13
 RewriteRule ^go/(.*)$  dispatch.php?go=$1&%{QUERY_STRING}
14 14
 RewriteRule ^init(.*)$  go/index/initialize_useraccount?token=$1&%{QUERY_STRING} [R]
15
+RewriteRule ^verify(.*)$  go/index/verify?token=$1&%{QUERY_STRING} [R]
... ...
@@ -123,7 +123,7 @@ function db_query($stmt, $params = NULL)
123 123
   global $_db;
124 124
   __ensure_connected();
125 125
   $backtrace = debug_backtrace();
126
-  DEBUG($backtrace[0]['file'].':'.$backtrace[0]['line'].': '.$stmt);
126
+  DEBUG($backtrace[0]['file'].':'.$backtrace[0]['line'].': '.htmlspecialchars($stmt));
127 127
   if ($params) {
128 128
     DEBUG($params);
129 129
   }
130 130
new file mode 100644
... ...
@@ -0,0 +1,64 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2014 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
+*/
16
+
17
+
18
+function verify_mail_token($token)
19
+{
20
+  db_query("DELETE FROM kundendaten.mailaddress_token WHERE expire<NOW()");
21
+  $args = array(":token" => $token);
22
+  $result = db_query("SELECT kunde, typ, email FROM kundendaten.mailaddress_token WHERE token=:token AND expire>NOW()", $args);
23
+  if ($result->rowCount() > 0)
24
+  {
25
+    $line = $result->fetch();
26
+    db_query("DELETE FROM kundendaten.mailaddress_token WHERE token=:token", $args); 
27
+    return $line;
28
+  } else {
29
+    return NULL;
30
+  }
31
+}
32
+
33
+
34
+function update_mailaddress($daten)
35
+{
36
+    $kunde = $daten['kunde'];
37
+    $typ = $daten['typ'];
38
+    $email = $daten['email'];
39
+
40
+    $dbfield = NULL;
41
+    if ($typ == 'regular') {
42
+        $dbfield = 'email';
43
+    } elseif ($typ == 'rechnung') {
44
+        $dbfield = 'email_rechnung';    
45
+    } elseif ($typ == 'newsletter') {
46
+        $dbfield = 'email_newsletter';    
47
+    } elseif ($typ == 'extern') {
48
+        $dbfield = 'email_extern';
49
+    }
50
+    if ($dbfield == NULL) {
51
+        system_failure('Ungültige Daten hinterlegt. Bitte die Änderung nochmal von vorne vornehmen.');
52
+    }
53
+    
54
+    if (! check_emailaddr($email)) {
55
+        system_failure('Es ist eine ungültige Adresse hinterlegt. So wird das nichts. Bitte die Änderung von vorne machen.');
56
+    } 
57
+
58
+    $args = array(':kunde' => $kunde,
59
+                  ':email' => $email);
60
+    db_query("UPDATE kundendaten.kunden SET $dbfield=:email WHERE id=:kunde", $args);
61
+    
62
+}
63
+
64
+
0 65
new file mode 100644
... ...
@@ -0,0 +1,37 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2014 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
+https://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
+*/
16
+
17
+require_once('kundendaten.php');
18
+require_once('inc/security.php');
19
+
20
+title("E-Mail-Adresse bestätigen");
21
+$show = 'token';
22
+
23
+if (isset($_REQUEST['token']))
24
+{
25
+  $token = $_REQUEST['token'];
26
+  $daten = verify_mail_token($token);
27
+  if ($daten == NULL) {
28
+    system_failure('Die E-Mail-Adresse konnte nicht verifiziert werden. Vielleicht ist der Link bereits abgelaufen.');
29
+  } else  {
30
+    update_mailaddress($daten);
31
+    success_msg('Die E-Mail-Adresse wurde erfolgreich geändert');
32
+    header('Location: /');
33
+  }
34
+}
35
+
36
+
37
+?>