Class: Widgets::Signup::Base

Inherits:
ErpApp::Widgets::Base
  • Object
show all
Defined in:
app/widgets/signup/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.base_layoutObject



61
62
63
64
65
66
67
68
# File 'app/widgets/signup/base.rb', line 61

def base_layout
  begin
    file = File.join(File.dirname(__FILE__),"/views/layouts/base.html.erb")
    IO.read(file)
  rescue
    return nil
  end
end

.titleObject



53
54
55
# File 'app/widgets/signup/base.rb', line 53

def title
  "Sign Up"
end

.widget_nameObject



57
58
59
# File 'app/widgets/signup/base.rb', line 57

def widget_name
  File.basename(File.dirname(__FILE__))
end

Instance Method Details

#indexObject



4
5
6
7
8
9
# File 'app/widgets/signup/base.rb', line 4

def index
  @login_url = params[:login_url]
  @user = User.new

  render
end

#locateObject

should not be modified modify at your own risk



48
49
50
# File 'app/widgets/signup/base.rb', line 48

def locate
  File.dirname(__FILE__)
end

#newObject



11
12
13
14
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
# File 'app/widgets/signup/base.rb', line 11

def new
  @website = Website.find_by_host(request.host_with_port)
  @configuration = @website.configurations.first
  password_config_option = @configuration.get_item(ConfigurationItemType.find_by_internal_identifier('password_strength_regex')).options.first
  primary_host = @configuration.get_item(ConfigurationItemType.find_by_internal_identifier('primary_host')).options.first

  @email = params[:email]
  @user = User.new(
    :email => @email,
    :username => params[:username],
    :password => params[:password],
    :password_confirmation => params[:password_confirmation]
  )
  @user.password_validator = {:regex => password_config_option.value, :error_message => password_config_option.comment}
  #set this to tell activation where to redirect_to for login and temp password
  @user.add_instance_attribute(:login_url,params[:login_url])
  @user.add_instance_attribute(:temp_password, params[:password])
  @user.add_instance_attribute(:domain, primary_host.value)
  begin
    if @user.save
      individual = Individual.create(:current_first_name => params[:first_name], :current_last_name => params[:last_name])
      @user.party = individual.party
      @user.add_role(@website.role)
      @user.save
      render :update => {:id => "#{@uuid}_result", :view => :success}
    else
      render :update => {:id => "#{@uuid}_result", :view => :error}
    end
  rescue Exception=>ex
    logger.error ex.message
    logger.error ex.backtrace
    render :update => {:id => "#{@uuid}_result", :view => :error}
  end
end