Class: BillySignup::SignupsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/billy_signup/signups_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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'
    ## user exists
    if auth_hash[:authentication] && auth_hash[:authentication][:status] == 'valid'
      ## logged in OK!
      @identity = @auth.user
    else
      ## password was invalid
      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
  
  ## check the field have been entered
  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
  
  ## verify the domain
   = nil
   = 1
  while .nil?
    proposed_domain = params[:account_name].gsub(/[^A-Za-z0-9\-\_\s]+/, '').parameterize
    proposed_domain += .to_s if  > 1
     = "#{proposed_domain}.#{@product.user_domain}"
    errors = Billy::Service.validate_label()
    if errors.is_a?(Array)
       = nil
       += 1
    end
  end
  
  @service = Hash.new
  @service[:billing_name]   = params[:account_name]
  @service[: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 
  else
    flash.now[:alert] = "An error occurred while creating your account. Please try again later or contact support."
    render :action => "new"
  end
end

#newObject



12
13
# File 'app/controllers/billy_signup/signups_controller.rb', line 12

def new
end

#reset_passwordObject



92
93
94
95
96
97
98
99
# File 'app/controllers/billy_signup/signups_controller.rb', line 92

def reset_password
  user = AtechIdentity::User.find(params[:email])
  if user && user.send_new_random_password
    render :json => {:status => "sent"}
  else
    render :json => {:status => "failed"}
  end
end

#validate_userObject



88
89
90
# File 'app/controllers/billy_signup/signups_controller.rb', line 88

def validate_user
  render :json => auth_details_hash
end