Browse code

Changed majority of files.

DoubleBastionAdmin authored on 30/11/2024 06:56:40
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,113 @@
1
+<?php
2
+/**
3
+ *  Copyright (C) 2021  Double Bastion LLC
4
+ *
5
+ *  This file is part of Roundpin, which is licensed under the
6
+ *  GNU Affero General Public License Version 3.0. The license terms
7
+ *  are detailed in the "LICENSE.txt" file located in the root directory.
8
+ */
9
+
10
+session_start();
11
+
12
+ // header('Set-Cookie: PHPSESSID= ' . session_id() . '; SameSite=strict; Secure=true; HttpOnly=true;');
13
+
14
+if (isset($_POST['s_ajax_call']) && ($_POST['s_ajax_call'] == $_SESSION['validate_s_access'])) {
15
+
16
+ define('ACCESSCONST', TRUE);
17
+
18
+ require('db-connect.php');
19
+
20
+    $username = $_POST['username'];
21
+    $currentEmail = $_POST['current_email'];
22
+    $newEmail = $_POST['new_email'];
23
+
24
+    // Get the email address of the current user from the 'app_users' table
25
+    $enabled = 1;
26
+    $queryemail = $mysqli->prepare("SELECT id, username, emailaddress, enabled FROM app_users WHERE username = ? AND enabled = ?");
27
+    $queryemail->bind_param("si", $username, $enabled);
28
+    $queryemail->execute();
29
+    $emailfromdb = $queryemail->get_result()->fetch_assoc();
30
+    $fetchedemailfromdb = $emailfromdb['emailaddress'];
31
+
32
+    // Check if there is any other user with the same email address as the new email address
33
+    $getemails = $mysqli->query("SELECT emailaddress FROM app_users");
34
+
35
+    $duplicateemail = 0;
36
+
37
+    while ($row = $getemails->fetch_row()) {
38
+
39
+           if ($newEmail == $row[0]) {
40
+               $duplicateemail = 1;
41
+               break;
42
+           }
43
+    }
44
+
45
+
46
+    if ($fetchedemailfromdb == $currentEmail) {
47
+
48
+       if ($duplicateemail == 0) {
49
+
50
+           /**
51
+            *  Send the verification email
52
+            */
53
+
54
+           // Generate a random string to be used as the termination of the verification link
55
+           function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
56
+                    $pieces = [];
57
+                    $max = mb_strlen($keyspace, '8bit') - 1;
58
+
59
+                    for ($i = 0; $i < $length; ++$i) {
60
+                         $pieces []= $keyspace[random_int(0, $max)];
61
+                    }
62
+                    return implode('', $pieces);
63
+           }
64
+
65
+           $token = random_str(55);
66
+
67
+           // Enter the new token in the database
68
+           $reg = 1;
69
+           $enbld = 1;
70
+           $entertokenquery = $mysqli->prepare("UPDATE app_users SET token = ? WHERE username = ? AND registered = ? AND enabled = ?");
71
+           $entertokenquery->bind_param("ssii", $token, $username, $reg, $enbld);
72
+           $entertokenquery->execute();
73
+
74
+           // Create the verification email
75
+           $verificationLink = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . "/src/change-email-verification.php?token=" . $token . "&newemail=" . $newEmail;
76
+
77
+           $domaininit = explode(".", $_SERVER['HTTP_HOST']);
78
+           array_shift($domaininit);
79
+           $domain = implode(".", $domaininit);
80
+
81
+           $headers = "MIME-Version: 1.0" . "\r\n";
82
+           $headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";
83
+
84
+           $headers .= "From: " . "no-reply@" . $domain . "\r\n";
85
+
86
+           $subject = "Roundpin email address verification";
87
+
88
+           $message = "Hello, <br><br>
89
+                       We have received your email address change request. To change your current Roundpin email address, please verify your address by clicking on
90
+                       the link from below: <br><br>
91
+                       <a href='".$verificationLink."'>".$verificationLink."</a><br><br>
92
+                       Alternatively, you can copy the link and paste it in the address bar of your browser.<br><br>
93
+                       After email address verification, your new email address will be assigned to your Roundpin account and saved to the database.<br><br>
94
+                       Thank you,<br>
95
+                       Roundpin<br>
96
+                       Host: '" . $_SERVER['HTTP_HOST'] . "'";
97
+
98
+           // Send the verification email
99
+           mail($newEmail, $subject, $message, $headers);
100
+
101
+           $emailchangemessage = "An email has been sent to your new email address. Please click on the link included in the received email to change your Roundpin user email address.";
102
+
103
+       } else { $emailchangemessage = "The new email address is already used by another Roundpin user. Please, choose a different email address!"; }
104
+        
105
+    } else { $emailchangemessage = "The email address you have entered in the 'Current Email' field doesn't match your current email address!"; }
106
+
107
+    echo json_encode($emailchangemessage);
108
+
109
+} else {
110
+        header("Location: ../login.php");
111
+}
112
+
113
+?>
0 114
\ No newline at end of file