15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'app/controllers/billy_signup/signups_controller.rb', line 15
def create
auth_hash = auth_details_hash
if auth_hash[:email_check] && auth_hash[:email_check][:status] == 'in-use'
if auth_hash[:authentication] && auth_hash[:authentication][:status] == 'valid'
@identity = @auth.user
else
flash.now[:alert] = "The password you have entered is not valid for the account associated with the email address you have entered. If you are unsure of your password, you can use the link below to request a new password."
render :action => "new"
return
end
else
temp_username = "#{params[:first_name].parameterize}-#{params[:last_name].parameterize}-#{rand(100)}"
hash = { :username => temp_username,
:password => params[:password],
:password_confirmation => params[:password],
:first_name => params[:first_name],
:last_name => params[:last_name],
:email_address => params[:email]
}
new_user = AtechIdentity::User.register(hash)
if new_user.is_a?(AtechIdentity::User)
@identity = new_user
else
flash.now[:alert] = "Sorry an error occured while registering your new admin account. Please check the details below and try again."
render :action => "new"
@ati_errors = new_user
return
end
end
if params[:account_name].blank?
flash.now[:alert] = "You must enter a name for your account to use when accessing it in the form below"
render :action => "new"
return
end
account_label = nil
account_label_index = 1
while account_label.nil?
proposed_domain = params[:account_name].gsub(/[^A-Za-z0-9\-\_\s]+/, '').parameterize
proposed_domain += account_label_index.to_s if account_label_index > 1
account_label = "#{proposed_domain}.#{@product.user_domain}"
errors = Billy::Service.validate_label(account_label)
if errors.is_a?(Array)
account_label = nil
account_label_index += 1
end
end
@service = Hash.new
@service[:billing_name] = params[:account_name]
@service[:label] = account_label
@service[:package] = @package.permalink
@service[:amount] = @package.amount
@service[:frequency] = @product.default_frequency || 1
@service[:trial_expires_on] = @product.trial_length.days.from_now.to_s(:db)
@service[:signup_source] = cookies[:referer]
if service = Billy::Service.create(@identity.identifier, @service)
session[:service_domain] = @service[:label]
session[:service_email] = params[:email]
redirect_to signup_complete_path
else
flash.now[:alert] = "An error occurred while creating your account. Please try again later or contact support."
render :action => "new"
end
end
|