2009-10-07 20:46:40 -04:00
|
|
|
class SessionsController < ApplicationController
|
2010-01-13 12:12:13 -05:00
|
|
|
include Devise::Controllers::InternalHelpers
|
2009-10-27 19:26:40 -04:00
|
|
|
|
2009-10-12 07:37:28 -04:00
|
|
|
before_filter :require_no_authentication, :only => [ :new, :create ]
|
2009-10-07 20:46:40 -04:00
|
|
|
|
2009-10-17 11:10:15 -04:00
|
|
|
# GET /resource/sign_in
|
2009-10-07 20:46:40 -04:00
|
|
|
def new
|
2010-02-08 13:07:24 -05:00
|
|
|
unless resource_just_signed_up?
|
|
|
|
Devise::FLASH_MESSAGES.each do |message|
|
|
|
|
set_now_flash_message :alert, message if params.try(:[], message) == "true"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
build_resource
|
|
|
|
render_with_scope :new
|
2009-10-07 20:46:40 -04:00
|
|
|
end
|
|
|
|
|
2009-10-17 11:10:15 -04:00
|
|
|
# POST /resource/sign_in
|
2009-10-07 20:46:40 -04:00
|
|
|
def create
|
2010-01-16 04:56:35 -05:00
|
|
|
if resource = authenticate(resource_name)
|
2010-01-20 14:46:14 -05:00
|
|
|
set_flash_message :notice, :signed_in
|
2010-01-16 04:56:35 -05:00
|
|
|
sign_in_and_redirect(resource_name, resource, true)
|
2009-10-10 13:14:09 -04:00
|
|
|
else
|
2010-02-02 07:21:00 -05:00
|
|
|
set_now_flash_message :alert, (warden.message || :invalid)
|
2010-02-08 17:14:03 -05:00
|
|
|
clean_up_passwords(build_resource)
|
2009-11-21 17:07:37 -05:00
|
|
|
render_with_scope :new
|
2009-10-10 13:14:09 -04:00
|
|
|
end
|
2009-10-07 20:46:40 -04:00
|
|
|
end
|
|
|
|
|
2009-10-17 11:10:15 -04:00
|
|
|
# GET /resource/sign_out
|
2009-10-07 20:46:40 -04:00
|
|
|
def destroy
|
2010-01-20 14:46:14 -05:00
|
|
|
set_flash_message :notice, :signed_out if signed_in?(resource_name)
|
2009-11-19 08:16:31 -05:00
|
|
|
sign_out_and_redirect(resource_name)
|
2009-10-07 20:46:40 -04:00
|
|
|
end
|
2009-10-12 07:37:28 -04:00
|
|
|
|
2010-02-08 11:15:12 -05:00
|
|
|
protected
|
|
|
|
|
|
|
|
def resource_just_signed_up?
|
|
|
|
flash[:"#{resource_name}_signed_up"]
|
|
|
|
end
|
2010-02-08 13:07:24 -05:00
|
|
|
|
2010-02-08 17:14:03 -05:00
|
|
|
def clean_up_passwords(object)
|
|
|
|
object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
|
2010-02-08 13:07:24 -05:00
|
|
|
end
|
2009-10-07 20:46:40 -04:00
|
|
|
end
|