1
0
Fork 0

Invites beta

This commit is contained in:
magnolia-fan 2011-04-16 12:31:47 +04:00
parent 00918b93af
commit b241ece155
2 changed files with 50 additions and 1 deletions

View File

@ -1,4 +1,8 @@
class UserController < ApplicationController class UserController < ApplicationController
@@invite_salt = 'Gouranga gives a fuck?!'
@@email_regex = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
def login def login
@hide_player = 1 @hide_player = 1
unless params[:email].nil? or params[:password].nil? unless params[:email].nil? or params[:password].nil?
@ -28,7 +32,7 @@ class UserController < ApplicationController
@hide_player = 1 @hide_player = 1
data = Invite.where(:email => params[:invite_email], :code => params[:invite_code]).first data = Invite.where(:email => params[:invite_email], :code => params[:invite_code]).first
unless data.nil? unless data.nil?
if params[:email].match(/\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\z/).nil? or if params[:email].match(@@email_regex).nil? or
params[:password].length < 6 or params[:password].length < 6 or
params[:password] != params[:password_c] params[:password] != params[:password_c]
redirect_to '/' redirect_to '/'
@ -63,4 +67,26 @@ class UserController < ApplicationController
render :json => 'wtf?' render :json => 'wtf?'
end end
end end
def invite
@data = User.collection.find({session_key: Digest::SHA256.hexdigest(request.session['session_id'])}).first
unless @data.nil?
if @data.invites > 0
pp 1
if request.request_method == 'POST'
unless params[:email].nil?
if params[:email].match(@@email_regex)
Invite.collection.insert({email: params[:email], code: Digest::SHA256.hexdigest(params[:email] << @@invite_salt), referer: @data._id})
@data.invites -= 1
User.collection.update({_id: @data._id}, @data.attributes)
@ok = true
end
end
end
pp 2
else
render :json => 'wtf?'
end
end
end
end end

23
app/views/user/invite.erb Normal file
View File

@ -0,0 +1,23 @@
<div id="registration">
<h1>Help BeatHaven dominate those lousy humans!</h1>
<%= form_tag('/reg/complete', :method => 'post') do -%>
<%= label_tag 'email', 'E-mail' %><%= email_field_tag 'email', @email %><div id="email_error"></div>
<div class="complete">
<%= submit_tag 'I wanna get this guy in!' %>
</div>
<% end -%>
</div>
<script type="text/javascript" charset="utf-8">
$(function(){
$('#email').focus();
$('form').submit(function(){
$('#email, #email_error').html('');
if (! $('#email').val().match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/)) {
$('#email_error').html('* Invalid email');
$('#email').focus();
return false;
}
return true;
})
})
</script>