Module: Accounts::Helpers
- Defined in:
- lib/accounts/helpers.rb
Instance Method Summary collapse
- #authenticate!(email, password) ⇒ Object
- #on_email_confirmed(account) ⇒ Object
- #register_new_account(email) ⇒ Object
- #respond_to_token(id) ⇒ Object
- #send_change_email_confirmation(account, new_email) ⇒ Object
- #send_change_password_link(account) ⇒ Object
- #site ⇒ Object
Instance Method Details
#authenticate!(email, password) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/accounts/helpers.rb', line 75 def authenticate!(email, password) account = ::Accounts::Account.first(:email => email) \ or return false account.confirm_password(password) or return false session[:account_id] = account.id end |
#on_email_confirmed(account) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/accounts/helpers.rb', line 41 def on_email_confirmed(account) account.status << :email_confirmed account.taint! :status # taint!() defined in model.rb account.save Accounts.deliver_new_account_admin_notification[account.email] end |
#register_new_account(email) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/accounts/helpers.rb', line 82 def register_new_account(email) account = ::Accounts::Account.create ({ :email => email }) account.saved? or return "We are unable to register you at this time. Please try again later." tok = ::Accounts::ActionToken.create({ :account => account, :action => 'reset password' }) link = "#{site}/response-token/#{tok.id}" Accounts.deliver_registration_confirmation[account.email, link] end |
#respond_to_token(id) ⇒ Object
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 |
# File 'lib/accounts/helpers.rb', line 48 def respond_to_token(id) token = ::Accounts::ActionToken.get(id) raise ::Accounts::AccountsError.new 404, %Q{Page not found. Go to <a href="/">home page</a>.} \ unless token begin on_email_confirmed token.account \ unless token.account.status.include? :email_confirmed case token.action when 'change email' then token.account.email = token.params[:new_email] token.account.save or return "We are unable to change your e-mail right now. Try again later." session[:account_id] = token.account.id # this visitor is authenticated redirect to("/logon?email=#{token.params[:new_email]}") when 'reset password' then session[:account_id] = token.account.id # this visitor is authenticated redirect '/change-password' else nil end ensure token.destroy or raise "Failed to destroy token #{token.id}" end end |
#send_change_email_confirmation(account, new_email) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/accounts/helpers.rb', line 31 def send_change_email_confirmation(account, new_email) tok = ::Accounts::ActionToken.create({ :account => account, :action => 'change email', :params => {:new_email => new_email} }) link = "#{site}/response-token/#{tok.id}" Accounts.deliver_change_email_confirmation[account.email, new_email, link] end |
#send_change_password_link(account) ⇒ Object
25 26 27 28 29 |
# File 'lib/accounts/helpers.rb', line 25 def send_change_password_link(account) tok = ::Accounts::ActionToken.create({ :account => account, :action => 'reset password' }) link = "#{site}/response-token/#{tok.id}" Accounts.deliver_change_password_link[account.email, link] end |
#site ⇒ Object
19 20 21 22 23 |
# File 'lib/accounts/helpers.rb', line 19 def site scheme = request.env['rack.url_scheme'] host = request.env['HTTP_HOST'] # includes port number "#{scheme}://#{host}" end |