Registration by invites #23
This commit is contained in:
parent
1e01c6cf7d
commit
e20ed483c1
|
@ -1,10 +1,34 @@
|
|||
class UserController < ApplicationController
|
||||
def register
|
||||
|
||||
data = Invite.where(:email => params[:email], :code => params[:code]).first
|
||||
|
||||
unless data.nil?
|
||||
@code = data.code
|
||||
@email = data.email
|
||||
else
|
||||
redirect_to '/'
|
||||
end
|
||||
end
|
||||
|
||||
def complete
|
||||
data = Invite.where(:email => params[:invite_email], :code => params[:invite_code]).first
|
||||
unless data.nil?
|
||||
if params[:email].match(/\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\z/).nil? or
|
||||
params[:password].length < 6 or
|
||||
params[:password] != params[:password_c]
|
||||
redirect_to '/'
|
||||
end
|
||||
|
||||
User.collection.insert({
|
||||
email: params[:email],
|
||||
password: Digest::SHA256.hexdigest(params[:password]),
|
||||
name: '',
|
||||
regdate: Time.now(),
|
||||
referer: data.referer,
|
||||
lastvisit: Time.now(),
|
||||
invites: 0
|
||||
})
|
||||
|
||||
Invite.collection.remove({email: params[:invite_email], code: params[:invite_code]})
|
||||
else
|
||||
redirect_to '/'
|
||||
end
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<div id="registration">
|
||||
<h1>Welcome aboard, friend!</h1>
|
||||
</div>
|
|
@ -0,0 +1,31 @@
|
|||
<div id="registration">
|
||||
<h1>Greetings from BeatHaven!</h1>
|
||||
<%= form_tag('/reg/complete', :method => 'post') do -%>
|
||||
<%= hidden_field_tag 'invite_code', @code %>
|
||||
<%= hidden_field_tag 'invite_email', @email %>
|
||||
<%= label_tag 'email', 'E-mail' %><%= email_field_tag 'email', @email %>
|
||||
<%= label_tag 'password', 'Password' %><%= password_field_tag 'password', nil %><div id="password_error"></div>
|
||||
<%= label_tag 'password_c', 'Confirm' %><%= password_field_tag 'password_c', nil %><div id="password_c_error"></div>
|
||||
<div class="complete">
|
||||
<%= submit_tag 'Complete' %>
|
||||
</div>
|
||||
<% end -%>
|
||||
</div>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
$(function(){
|
||||
$('#password').focus();
|
||||
$('form').submit(function(){
|
||||
$('#password_error, #password_c_error').html('');
|
||||
if ($('#password').val().length < 6) {
|
||||
$('#password_error').html('* Password must be 6+ characters length');
|
||||
$('#password').focus();
|
||||
return false;
|
||||
} else if ($('#password').val() != $('#password_c').val()) {
|
||||
$('#password_c_error').html('* Password and confirmation doesn\'t match');
|
||||
$('#password_c').focus();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
})
|
||||
</script>
|
|
@ -7,7 +7,9 @@ Beathaven::Application.routes.draw do
|
|||
match 'listen/:id' => 'track#listen'
|
||||
match 'search/autocomplete' => 'artist#autocomplete'
|
||||
|
||||
# Registration & login
|
||||
match 'reg/:email/:code' => 'user#register', :constraints => { :email => /[-a-z0-9\._@]+/i, :code => /[a-z0-9]{8}/ }
|
||||
match 'reg/complete' => 'user#complete'
|
||||
|
||||
match '*a', :to => 'errors#routing'
|
||||
end
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
#registration {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin: -145px 0 0 -195px;
|
||||
padding: 20px;
|
||||
width: 350px;
|
||||
height: 250px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
#registration h1 {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 28px;
|
||||
font-weight: normal;
|
||||
margin: 0 0 30px 0;
|
||||
}
|
||||
|
||||
#registration label {
|
||||
display: block;
|
||||
float: left;
|
||||
width: 100px;
|
||||
font-size: 20px;
|
||||
line-height: 35px;
|
||||
}
|
||||
#registration input[type="email"], input[type="password"] {
|
||||
width: 230px;
|
||||
font-size: 20px;
|
||||
border: #EAEAEA 1px solid;
|
||||
background-color: #FCFCFC;
|
||||
padding: 5px;
|
||||
}
|
||||
#registration input[type="submit"] {
|
||||
color: #FFF;
|
||||
border: #EAEAEA 1px solid;
|
||||
background-color: #05A;
|
||||
font-size: 25px;
|
||||
padding: 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
#registration .complete {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
margin-top: 20px;
|
||||
}
|
||||
#email_error, #password_error, #password_c_error {
|
||||
float: right;
|
||||
color: #E30;
|
||||
width: 350px;
|
||||
height: 30px;
|
||||
margin: 4px -350px 0 0;
|
||||
line-height: 30px;
|
||||
font-size: 15px;
|
||||
}
|
Loading…
Reference in New Issue