1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
<?php
function invite($db){
$name=$_SESSION["username"];
$safe_name = SQLite3::escapeString("$name");
$email=$_POST["email"];
$safe_email=SQLite3::escapeString("$email");
$invite_db = $db->query("SELECT invites FROM user WHERE name='" . $safe_name . "';");
$invite_ar = $invite_db->fetchArray(SQLITE3_NUM);
$invite = $invite_ar[0];
if($invite <= 0){
return INVITE_INVITES;
}
$email_db = $db->query("Select 1 FROM user WHERE email='" . $safe_email . "';");
$email_ar = $email_db->fetchArray(SQLITE3_NUM);
if($email_ar[0] == 1){
return INVITE_USEREXISTS;
}
/*Generates the invite key => [-_0-9a-zA-Z]{11}*/
$key_array = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "_", "-", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" );
$length = count($key_array);
$key = "";
for ($i=0;$i<11;$i++){
$index = mt_rand(0,$length-1);
$key = "$key".$key_array[$index];
}
$id_db = $db->query("SELECT id FROM USER WHERE name='" . $safe_name . "';");
$id_ar = $id_db->fetchArray(SQLITE3_NUM);
$id = $id_ar[0];
/*Generates the new user and decrease the invites*/
$invite = $invite-1;
if($db->exec("
BEGIN TRANSACTION;
INSERT INTO user (id, name, email, senpai, key, status) VALUES (NULL, NULL, '" . $safe_email . "', '" . $id . "', '" . $key . "', 0);
UPDATE user SET invites='" . $invite . "' WHERE id='" . $id . "';
COMMIT;")
){
$subject="Welcome, you were invited to the new virtual filesystem.\nYour key is " . $key . "\nVisit files.iamfabulous.de/register to complete your registration.";
// Doesn't work with GMX or Web.de atm.
mail($email, "Invite", $subject, "From: mail@iamfabulous.de");
return INVITE_SUCCESSFULL;
} else {
return INVITE_DATABASE;
}
}
|