Created
October 1, 2010 01:22
-
-
Save santiago/605579 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
@user = User.new(params[:user]) | |
if @user.save | |
# it should add an activation code | |
@activation_code= Digest::SHA1.hexdigest(@user.login+Time.now.to_s) | |
@user.update_attributes({:code => @activation_code}) | |
# it should convert birthdate params to Date type | |
date= params[:year] | |
if params[:month].strip =~ /^\d{2}$/ | |
if params[:day].strip =~ /^\d{2}$/ | |
date << "-#{params[:month]}-#{params[:day]}" | |
end | |
end | |
# it should save/update birthdate and gender | |
@user.partner.update_attributes({:birth_date =>date, :gender=>params[:gender]}) | |
# it should link partners if there is a link request | |
if @user.partner.has_partner_link_request? | |
@user.partner.accept_partner_link_request! | |
end | |
# context coming from email link | |
if params[:c] | |
# it should receive a valid code | |
code= EmailCode.find_by_code(params[:c]) | |
# it should link partners | |
Partner.find(session[:partner_id]).accept_partner_link_request!(code) | |
# context blind link request | |
elsif params[:partner] | |
partner= Partner.find_by_partner_link_code(params[:partner]) | |
begin | |
# it should link partners | |
@user.partner.accept_blind_partner_link_request!(params[:partner]) | |
rescue Exception => e | |
flash[:notice] = e.message | |
# it should redirect to "" | |
redirect_back_or_default "/" | |
return | |
end | |
end | |
render_reg = lambda { | |
email= RegistrationMailer.create_sent(@user) | |
tpl= "verify_account" | |
if params[:client]=="fun" | |
email= RegistrationMailer.create_fun(@user) | |
tpl= "fun_verify_account" | |
end | |
email.set_content_type("text/html") | |
RegistrationMailer.deliver(email) | |
render tpl | |
} | |
respond_to do |format| | |
format.html &render_reg | |
end | |
else | |
render :action => :new | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment