$return = array('error' => "Leave {$crushee_name} alone!"); } else { $already_registered = select_p($db, "select user_id from user where username = ?", array($crushee), 'getOne'); // add dummy account if (!$already_registered) { query_p($db, "insert into user (username, password, registered) values (?,'hashed',0)", array($crushee)); } do { $adjective = ucfirst(select_p($db, "select word from words where type = 'adjective' order by rand() limit 1", array(), 'getOne')); $noun = ucfirst(select_p($db, "select word from words where type = 'noun' order by rand() limit 1", array(), 'getOne')); $num = rand(1, select_p($db, "select count(*) from wes_users", array(), 'getOne')); $crusher_alias = "{$adjective} {$noun} {$num}"; $already = select_p($db, 'select crusher_alias from crushes where crusher_alias = ?', array($crusher_alias), 'getOne'); } while ($already); $crushee_id = select_p($db, 'select user_id from user where username = ?', array($crushee), 'getOne'); query_p($db, 'insert into crushes (crusher_id, crusher_alias, crushee_id) values (?,?,?)', array($signed_in_id, $crusher_alias, $crushee_id)); /** send e-mail */ $they_like_you = select_p($db, 'select * from crushes where crusher_id = ? and crushee_id = ?', array($crushee_id, $signed_in_id), 'getOne'); $successful_match = false; if ($they_like_you) { $successful_match = select_p($db, 'select user_id from user where username = ?', array($crushee), 'getOne'); $email_subject = "Wescam - {$signed_in_name} likes you, too!"; $email_body = "Wow... I mean, we always thought Wescam was a great idea, but we never thought it would actually, you know, *work*!. From everyone at Wescam, congrats!\n\n-Wescam"; } else { $email_subject = "Wescam - Someone on campus has added you"; $email_body = "Wescam 2010 is a site developed by Wesleyan students for seniors on campus interested in meeting up and someone has added you! Sign in below to learn more!\n\nhttp://cam.weshub.com/"; } require_once "/home/syn/swift/swift_required.php"; $transport = Swift_MailTransport::newInstance(); $mailer = Swift_Mailer::newInstance($transport); $message = Swift_Message::newInstance()->setSubject($email_subject)->setFrom(array('*****@*****.**' => 'Wescam'))->setTo(array("{$crushee}@wesleyan.edu"))->setBody($email_body);
$smarty->display('confirm.tpl'); } else { $db = connect_to_db(); if (!select_p($db, 'select username from user where username = ?', array($username), 'getOne')) { $smarty->assign('username', stripslashes($username)); $smarty->assign('incorrect_user', true); $smarty->display('confirm.tpl'); } else { $real_code = select_p($db, 'select code from user_confirm where username = ?', array($username), 'getOne'); if (!$real_code) { $smarty->assign('already', true); $smarty->display('confirm.tpl'); } else { if ($confirm_code == $real_code) { query_p($db, 'delete from user_confirm where username = ?', array($username)); query_p($db, 'update user set registered = 1 where username = ?', array($username)); $smarty->assign('username', stripslashes($username)); $smarty->assign('success', true); $smarty->display('confirm.tpl'); } else { $smarty->assign('username', stripslashes($username)); $smarty->assign('incorrect_code', true); $smarty->display('confirm.tpl'); } } } } } else { $smarty->display('confirm.tpl'); } }
} else { if (!preg_match('/[0-9][0-9][0-9][0-9]/', select_p($db, 'select division from wes_users where username = ?', array($username), 'getOne'))) { $errors['username'] = '******'; displayWithErrors($errors); } else { $password = generateHash($password); $code = randomString(); $has_dummy_account = select_p($db, "select * from user where username = ? and registered = 0", array($username), 'getOne'); query_p($db, 'start transaction'); if ($has_dummy_account) { query_p($db, 'update user set password = ? where username = ?', array($password, $username)); } else { query_p($db, 'insert into user (username, password, registered) values (?,?,0)', array($username, $password)); } query_p($db, 'insert into user_confirm (username, code) values (?,?)', array($username, $code)); query_p($db, 'commit'); /** start e-mail */ require_once "/home/syn/swift/swift_required.php"; $transport = Swift_MailTransport::newInstance(); $mailer = Swift_Mailer::newInstance($transport); $message = Swift_Message::newInstance()->setSubject("Wescam Confirmation - You did it!")->setFrom(array('*****@*****.**' => 'Wescam'))->setTo(array("{$username}@wesleyan.edu"))->setBody("You're almost there! Just click on the link below!\n\nhttp://cam.weshub.com/confirm/{$code}/"); $result = $mailer->send($message); /** end e-mail */ $smarty->assign('username', stripslashes($username)); $smarty->assign('success', true); $smarty->display('register.tpl'); } } } close_db($db); }