Permalink
Browse files

Invites system added. Toggable

  • Loading branch information...
1 parent 985d229 commit 554bb73f1981e2376e91d09e67097a39edbda5fe @redroot committed May 21, 2011
@@ -57,6 +57,7 @@ p.success { background: #cfc; border: 5px solid #fff; color: #030; outline: 1px
.form_last {width: 95%; clear: both; }
+
#content_wrapper fieldset li, #facebox li {list-style:none; margin-bottom: 5px;}
#content_wrapper fieldset li label, #facebox li label { display: block; margin-bottom: 3px; }
@@ -68,7 +69,8 @@ p.success { background: #cfc; border: 5px solid #fff; color: #030; outline: 1px
#content_wrapper form label.error, #content_wrapper span.error { color: #d22; background-image: url('../images/layout/cancel.png');}
#content_wrapper form label.validfield, #content_wrapper span.success { color: #2a2; background-image: url('../images/layout/accept.png') !important;}
-
+ #content_wrapper fieldset li.form_li_sep {padding-bottom: 10px; margin-bottom: 20px; border-bottom: 1px solid #ccc; }
+
/**
Tab styles
**/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -810,11 +810,12 @@ function invites()
if($this->input->post("inviteAction") == "allGenerate")
{
$this->invite_model->generateInvites($count);
- redirect('batcave/invites/?alGen='.$count,'location');
+ redirect('batcave/invites/?allGen='.$count,'location');
}
else if($this->input->post("inviteAction") == "userGenerate")
{
-
+ $this->invite_model->generateInvitesForUsers($count);
+ redirect('batcave/invites/?userGen='.$count,'location');
}
}
}
@@ -4,6 +4,9 @@
**/
class User extends Controller {
+ // global setting for invites. e.g. test invite code, display invites
+ private $useInvites = true;
+
function User()
{
parent::Controller();
@@ -897,7 +900,10 @@ function signup()
$this->template->write("title","Join Urika");
//empty for now
- $data = array("further_errors" => "");
+ $data = array(
+ "further_errors" => "",
+ "useInvite" => $this->useInvites
+ );
$this->template->write_view("content","user/signup_form", $data, TRUE);
@@ -1002,6 +1008,23 @@ function create_user()
$further_errors[] = "Leave well enough alone spam bot";
}
+ // invite check
+ $inviteToDelete = false;
+ if($this->useInvites == true)
+ {
+ $this->load->model("invite_model");
+ $inv_row = $this->invite_model->getInvite(trim($this->input->post("s_invite")),"inv_code");
+
+ if($inv_row == false)
+ {
+ $further_errors[] = "The invite code you used does not exist";
+ }
+ else
+ {
+ $inviteToDelete = $inv_row->row();
+ }
+ }
+
if(count($further_errors) > 0)
{
// loop through further errors and output with the rest of errors
@@ -1014,7 +1037,10 @@ function create_user()
$out .= '<p class="error">'.$error.'</p>';
}
- $data["further_errors"] = $out;
+ $data = array(
+ "further_errors" => $out,
+ "useInvite" => $this->useInvites
+ );
$this->template->add_js("assets/js/formvalidation.js");
$this->template->write("title","Join Urika");
@@ -1032,6 +1058,15 @@ function create_user()
{
$this->template->write("title","Registration Successfull");
+
+ /*
+ Delete invite if it exists
+ */
+ if($this->useInvites == true && $inviteToDelete != false)
+ {
+ $this->invite_model->deleteInvite($inviteToDelete->invite_id);
+ }
+
/*
send verification e-mail
*/
@@ -1632,6 +1667,27 @@ function account()
Grab stats
*/
$stats = $this->user_model->getUserStats($row->user_id);
+
+ /*
+ grab invites if required
+ */
+ $invites = false;
+ if($this->useInvites == true)
+ {
+ $userinvites = $this->user_model->getUserInvites($row->user_id);
+
+ $invites["count"] = $userinvites["count"];
+ $invites["html"] = '';
+
+ foreach($userinvites["result"] as $i => $inv)
+ {
+ $invites["html"] .= '
+ <p class="borderbox">
+ Invite '.($i+1).': <strong style="color: #930;">'.$inv->inv_code.'</strong>
+ </p>
+ ';
+ }
+ }
$data = array (
@@ -1652,7 +1708,8 @@ function account()
'gravatar_class' => $gravatar_class,
'upload_url' => $avatar_url
),
- 'stats' => $stats
+ 'stats' => $stats,
+ 'invites' => $invites
);
@@ -14,7 +14,7 @@ class invite_model extends Model {
function getInvite($value,$field = "invite_id")
{
$this->db->where(trim($field), trim($value));
- $query = $this->db->get('invite');
+ $query = $this->db->get('invites');
if($query->num_rows == 1)
{
@@ -63,6 +63,53 @@ function generateInvites($count = 5)
return true;
}
+
+ /*
+ Generates n invite codes for all users for each user, as long as they are verified
+
+ @param count : number of invites per user
+ */
+ function generateInvitesForUsers($count = 1)
+ {
+ $words = array(
+ "shinobiz",
+ "samuraiz",
+ "ninjaz",
+ "warriorz",
+ "hokagez"
+ );
+
+ $this->load->helper("string");
+
+ $usersql = 'SELECT user_id, u_verified FROM users';
+
+ $users = $this->db->query($usersql)->result();
+
+ $userscount = count($users);
+
+ $invitessql = '
+ INSERT INTO invites
+ (inv_code,inv_user_id)
+ VALUES
+ ';
+
+ for($i = 0; $i < $userscount; $i++)
+ {
+ if($users[$i]->u_verified == 0)
+ {
+ continue;
+ }
+
+
+ $invitessql .= '("'.random_string('unique').$words[rand(0,count($words)-1)].'",'.$users[$i]->user_id.'),';
+ }
+
+ $invitessql = substr($invitessql,0,-1).';';
+
+ $this->db->query($invitessql);
+
+ return true;
+ }
////////////// UPDATE FUNCTIONS
@@ -72,7 +119,7 @@ function generateInvites($count = 5)
Deletes by id, including all related records
@param id : invite_id to delete
*/
- function deleteNotice($id)
+ function deleteInvite($id)
{
if($id != null)
{
@@ -697,6 +697,22 @@ function getUserComments($user_id, $type = null)
}
/*
+ Returns an array of user invites
+
+ @param user_id : if of user to check
+ */
+ function getUserInvites($user_id)
+ {
+ $this->db->where("inv_user_id",$user_id);
+ $query = $this->db->get("invites");
+
+ $rtn["count"] = $query->num_rows;
+ $rtn["result"] = ($query->num_rows > 0) ? $query->result() : 0;
+
+ return $rtn;
+ }
+
+ /*
Checks if an e-mail is already on a blacklist
@param email : e-mail to check for
@@ -10,10 +10,18 @@
<ul class="tabNav">
<li><a href="#" title="Tab link">Profile Image</a></li>
<li><a href="#" title="Tab link">Public Details</a></li>
- <li><a href="#" title="Tab link">Change Password</a></li>
- <li><a href="#" title="Tab link">Change E-mail</a></li>
+ <li><a href="#" title="Tab link">Password</a></li>
+ <li><a href="#" title="Tab link">E-mail</a></li>
<li><a href="#" title="Tab link">Notices</a></li>
<li><a href="#" title="Tab link">API Key</a></li>
+ <?php
+ if($invites != false)
+ {
+ $inviteword = ($invites["count"] == 1) ? "Invite" : "Invites";
+
+ echo '<li><a href="#" title="Tab link"><strong>'.$invites["count"].'</strong> '.$inviteword.'</a></li>';
+ }
+ ?>
</ul>
<div class="tabContentWrapper">
@@ -197,6 +205,17 @@
?></strong>
</p>
</div>
+ <?php
+ if($invites != false)
+ {
+ echo '
+ <div class="tabContent">
+ <p style="margin-bottom:10px;">Below is a list of your invite codes, which you can use to invite new members. Please be responsible with your invite codes: only invite those you know will contribute to the site. </p>
+ '.$invites["html"].'
+ </div>
+ ';
+ }
+ ?>
</div>
</div>
@@ -13,8 +13,23 @@
echo $further_errors;
?>
<fieldset>
- <legend>Pick a username</legend>
+ <legend>Fill in your details</legend>
<ul>
+ <?php
+ if($useInvite == true)
+ {
+ echo '
+ <li class="form_li_sep">
+ <label for="s_invite"><strong>Your Invite Code</strong></label>
+ <input type="text" name="s_invite" id="s_invite" style="width: 300px" placeholder="Invite Code" class="required" />
+ </li>
+
+ ';
+
+
+ }
+
+ ?>
<li>
<label for="s_username">Username</label>
<input type="text" name="s_username" id="s_username" placeholder="Enter a username" minlength="4" class="required" />
@@ -33,6 +48,7 @@
<input type="password" name="s_password_b" id="s_password_b" equalTo="#s_password_a" minlength="8" class="required" />
</li>
+
<li>
<label for="s_human">Human Check: 8 + 3 = ?</label>
<input type="text" name="s_human" id="s_human" class="required" />

0 comments on commit 554bb73

Please sign in to comment.