We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

register.php 3.67 KB
Newer Older
mattl's avatar
mattl committed
1 2
<?php

mattl's avatar
mattl committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/* Libre.fm -- a free network service for sharing your music listening habits

   Copyright (C) 2009 Libre.fm Project

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

elleo's avatar
elleo committed
22 23
require_once("database.php");
require_once("templating.php");
jurgbohn's avatar
jurgbohn committed
24
require_once("utils/EmailAddressValidator.php");
jurgbohn's avatar
jurgbohn committed
25 26 27

// Moving to open alpha
/*$authcode = $_GET["authcode"];
elleo's avatar
elleo committed
28 29 30 31 32 33

$res = $mdb2->query("SELECT inviter FROM Invitations WHERE code = " . $mdb2->quote($authcode, "text"));
if(!$res->numRows()) {
	$invalid_authcode = true;
} else {
	$invalid_authcode = false;
jurgbohn's avatar
jurgbohn committed
34
}*/
elleo's avatar
elleo committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48

if(isset($_POST['register'])) {

	$errors = "";
	$username = $_POST['username'];
	$password = $_POST['password'];
	$passwordrepeat = $_POST['password-repeat'];
	$fullname = $_POST['fullname'];
	$email = $_POST['email'];
	$location = $_POST['location'];
	$bio = $_POST['bio'];


	//Basic validation
jurgbohn's avatar
jurgbohn committed
49 50
	if(!preg_match("/^[a-zA-Z0-9_]{3,16}$/", $username)) {
		$errors .= "Your username must be atleast 3 characters in length (max 16)  and only consist of <i>a-z, A-Z, 0-9</i> and _ (underscore).<br />";
elleo's avatar
elleo committed
51 52 53 54 55 56 57 58 59
	}
	if(empty($password)) {
		$errors .= "You must enter a password.<br />";
	}
	if($password != $passwordrepeat) {
		$errors .= "Your passwords do not match.<br />";
	}
	if(empty($email)) {
		$errors .= "You must enter an e-mail address.<br />";
jurgbohn's avatar
jurgbohn committed
60 61 62
	} else {
	    $validator = new EmailAddressValidator();
	    if (!$validator->check_email_address($email)) {
jurgbohn's avatar
jurgbohn committed
63
		$errors .= "You must provide a valid email address!<br />";
jurgbohn's avatar
jurgbohn committed
64
	    }
elleo's avatar
elleo committed
65 66 67
	}

	//Check this username is available
68
	$res = $mdb2->query("SELECT username FROM Users WHERE username ~* " . $mdb2->quote($username));
elleo's avatar
elleo committed
69 70 71 72
	if($res->numRows()) {
		$errors .= "Sorry, that username is already registered.<br />";
	}

jurgbohn's avatar
jurgbohn committed
73
	if(empty($errors)) {
elleo's avatar
elleo committed
74
		// Create the user
jurgbohn's avatar
jurgbohn committed
75
		$sql = "INSERT INTO Users (username, password, email, fullname, bio, location, created) VALUES ("
elleo's avatar
elleo committed
76 77 78 79 80 81
			. $mdb2->quote($username, "text") . ", "
			. $mdb2->quote(md5($password), "text") . ", "
			. $mdb2->quote($email, "text") . ", "
			. $mdb2->quote($fullname, "text") . ", "
			. $mdb2->quote($bio, "text") . ", "
			. $mdb2->quote($location, "text") . ", "
jurgbohn's avatar
jurgbohn committed
82 83 84 85 86 87 88 89 90
			. time() . ")";
		$insert = $mdb2->exec($sql);
		if (PEAR::isError($insert)) {
		    reportError("Create user, insert, register.php", $sql);
		    $errors .= "An error occurred.";
		    $smarty->assign('error', $errors);
		    $smarty->display('error.tpl');
		    die();
		}
elleo's avatar
elleo committed
91
		// Remove auth code and set their username as the invitee
jurgbohn's avatar
jurgbohn committed
92 93 94
		//$mdb2->query("UPDATE Invitations SET code = NULL, invitee = " . $mdb2->quote($username, "text") . " WHERE code = " . $mdb2->quote($authcode, "text"));
		//$removesql = "DELETE FROM Invitation_Request WHERE email=" . $mdb2->quote($email, 'text');
		//$mdb2->exec($removesql);
elleo's avatar
elleo committed
95 96 97 98 99 100 101
		$smarty->assign("registered", true);
	} else {
		$smarty->assign("username", $username);
		$smarty->assign("fullname", $fullname);
		$smarty->assign("email", $email);
		$smarty->assign("location", $location);
		$smarty->assign("bio", $bio);
jurgbohn's avatar
jurgbohn committed
102
		$smarty->assign("errors", $errors);
elleo's avatar
elleo committed
103 104
	}
}
jurgbohn's avatar
jurgbohn committed
105 106
//$smarty->assign("invalid_authcode", $invalid_authcode);
//$smarty->assign("authcode", $authcode);
elleo's avatar
elleo committed
107 108 109

$smarty->display("register.tpl");
?>