Module: Sinatra::Hancock::Users

Defined in:
lib/sinatra/hancock/users.rb

Defined Under Namespace

Modules: Helpers

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



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
# File 'lib/sinatra/hancock/users.rb', line 33

def self.registered(app)
  app.helpers Helpers
  app.helpers Sinatra::Mailer

  app.template(:signup_confirmation) { users_template('signup_confirmation') }
  app.template(:signup_form) { users_template('signup_form') }
  app.template(:register_form) { users_template('register_form') }

  app.get '/sso/register/:token' do
    user_by_token(params['token'])
    haml :register_form
  end

  app.post '/sso/register/:token' do
    user = user_by_token(params['token'])
    user.update_attributes(:enabled => true,
                           :access_token => nil,
                           :password => params['password'],
                           :password_confirmation => params['password_confirmation'])
    destination = session.delete('hancock_server_return_to') || '/'
    session.reject! { |key,value| key != 'hancock_server_user_id' }
    redirect destination
  end

  app.get '/sso/signup' do
    haml :signup_form
  end

  app.post '/sso/signup' do
    @user = ::Hancock::User.(params)
    from = options.do_not_reply

    if @user.save
      raise ::Hancock::ConfigurationError.new("You need to define options.do_not_reply") unless from
      @registration_url = absolute_url("/sso/register/#{@user.access_token}")
      email :to      => @user.email,
            :from    => from,
            :subject => "Welcome to #{::Hancock::App.provider_name}!",
            :body    => haml()
    end
    haml :signup_confirmation
  end
end

.users_template(file) ⇒ Object



4
5
6
7
# File 'lib/sinatra/hancock/users.rb', line 4

def self.users_template(file)
  template = File.expand_path(File.dirname(__FILE__)+'/views/users')
  File.read("#{template}/#{file}.haml")
end