diff --git a/account.inc.php b/account.inc.php index 0401786..861dee7 100644 --- a/account.inc.php +++ b/account.inc.php @@ -45,13 +45,6 @@ function account_valid_password($pass) return true; } -/* A more strict version of isEmailAddress() */ -function account_valid_email($str) -{ - $x = eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $str); - return ($x == 1) ? true : false; -} - /* Duplicate of common.inc.php:generatePassword, which will be deleted * eventually when ALL users are handled through this file */ function account_generate_password($pwlen=8) @@ -126,7 +119,7 @@ function account_load_by_username($username) } -function account_create($username) +function account_create($username,$password=NULL) { global $config; @@ -149,16 +142,30 @@ function account_create($username) $accounts_id = mysql_insert_id(); - account_set_password($accounts_id, NULL); + account_set_password($accounts_id, $password); + account_set_email($accounts_id, $email); $a = account_load($accounts_id); + return $a; } +function account_set_email($accounts_id,$email) { + global $config; + //we dont actually set the email until its confirmed, we only set the pending email :p + if(isEmailAddress($email)) { + $code=generatePassword(24); + mysql_query("UPDATE accounts SET pendingemail='".mysql_real_escape_string($email)."', pendingemailcode='$code' WHERE id='$accounts_id'"); + + $urlproto = $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://"; + $urlmain = "$urlproto{$_SERVER['HTTP_HOST']}{$config['SFIABDIRECTORY']}"; + $urlemailconfirm = "emailconfirmation.php?i=$accounts_id&e=".rawurlencode($email)."&c=".$code; + $link=$urlmain."/".$urlemailconfirm; + + email_send('account_email_confirmation',$email,array(),array("EMAIL"=>$email,"EMAILCONFIRMATIONLINK"=>$link)); + } +} /* - if(user_valid_email($username)) { - mysql_query("UPDATE users SET email='$username' WHERE id='$uid'"); - } */ ?> diff --git a/common.inc.functions.php b/common.inc.functions.php index 997adeb..cc79103 100644 --- a/common.inc.functions.php +++ b/common.inc.functions.php @@ -280,7 +280,7 @@ function outputStatus($status) { //returns true if its a valid email address, false if its not function isEmailAddress($str) { - if(eregi('^[+a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $str)) + if(preg_match('/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$/', $str)) return true; else return false; diff --git a/db/db.code.version.txt b/db/db.code.version.txt index c92ba56..7d645f5 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -207 +208 diff --git a/db/db.update.208.sql b/db/db.update.208.sql new file mode 100644 index 0000000..036df30 --- /dev/null +++ b/db/db.update.208.sql @@ -0,0 +1,12 @@ +ALTER TABLE `accounts` ADD `pendingemailcode` VARCHAR( 32 ) NULL DEFAULT NULL AFTER `pendingemail`; +INSERT INTO `emails` ( `val` , `name` , `description` , `from` , `subject` , `body` , `bodyhtml` , `type` , `fundraising_campaigns_id` , `lastsent`) VALUES ( 'account_email_confirmation', 'Email Address Confirmation', 'Gets sent when someone adds or changes their email address to allow the user to confirm the email address is valid', NULL , 'Email Authorization - [FAIRNAME]', +'We have received a request to add or change the email address on +your account. Before any emails will be sent to you from +[FAIRNAME] you need to +click the link below to validate your email address. + +Email Address: [EMAIL] + +[EMAILCONFIRMATIONLINK] + +Thank You', '', 'system', NULL , NULL); diff --git a/emailconfirmation.php b/emailconfirmation.php new file mode 100644 index 0000000..1c50a09 --- /dev/null +++ b/emailconfirmation.php @@ -0,0 +1,40 @@ + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> + diff --git a/register.php b/register.php new file mode 100644 index 0000000..e9926f9 --- /dev/null +++ b/register.php @@ -0,0 +1,255 @@ + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> + $x)); + exit; + +case 'save': + $email = trim($_POST['email']); + $pass = trim($_POST['pass1']); + $username_link = ($_POST['username_link'] == 'yes') ? true : false; + $username = $username_link ? $email : trim($_POST['username']); + $a=account_create($username,$pass); + if($email) { + account_set_email($a['id'],$email); + } + exit; + echo json_encode($a); + } + + send_header("Account Registration", + array("Account Registration" => "register.php") + ,"change_password" +); + +?> +
+
+ +

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Email
+
+
+
Username
:
+ type="checkbox" name="username_link" value="yes" /> +
+
+
+
Password
+
+
+
+
+ " /> +
+
+
+ + + + diff --git a/schoolteams.php b/schoolteams.php index aca16c1..28e1861 100644 --- a/schoolteams.php +++ b/schoolteams.php @@ -95,7 +95,7 @@ function draw_page(){ } '; + echo '