mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Stub out other views for Registerable.
This commit is contained in:
parent
9798ad7455
commit
8a15ac6e4a
8 changed files with 112 additions and 61 deletions
|
@ -1,6 +1,23 @@
|
||||||
class ConfirmationsController < ApplicationController
|
class ConfirmationsController < ApplicationController
|
||||||
include Devise::Controllers::InternalHelpers
|
include Devise::Controllers::InternalHelpers
|
||||||
include Devise::Controllers::Common
|
|
||||||
|
# GET /resource/confirmation/new
|
||||||
|
def new
|
||||||
|
build_resource
|
||||||
|
render_with_scope :new
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /resource/confirmation
|
||||||
|
def create
|
||||||
|
self.resource = resource_class.send_confirmation_instructions(params[resource_name])
|
||||||
|
|
||||||
|
if resource.errors.empty?
|
||||||
|
set_flash_message :notice, :send_instructions
|
||||||
|
redirect_to new_session_path(resource_name)
|
||||||
|
else
|
||||||
|
render_with_scope :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# GET /resource/confirmation?confirmation_token=abcdef
|
# GET /resource/confirmation?confirmation_token=abcdef
|
||||||
def show
|
def show
|
||||||
|
@ -13,10 +30,4 @@ class ConfirmationsController < ApplicationController
|
||||||
render_with_scope :new
|
render_with_scope :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def send_instructions_with
|
|
||||||
:send_confirmation_instructions
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,26 @@
|
||||||
class PasswordsController < ApplicationController
|
class PasswordsController < ApplicationController
|
||||||
include Devise::Controllers::InternalHelpers
|
include Devise::Controllers::InternalHelpers
|
||||||
include Devise::Controllers::Common
|
|
||||||
|
|
||||||
before_filter :require_no_authentication
|
before_filter :require_no_authentication
|
||||||
|
|
||||||
|
# GET /resource/password/new
|
||||||
|
def new
|
||||||
|
build_resource
|
||||||
|
render_with_scope :new
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /resource/password
|
||||||
|
def create
|
||||||
|
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
|
||||||
|
|
||||||
|
if resource.errors.empty?
|
||||||
|
set_flash_message :notice, :send_instructions
|
||||||
|
redirect_to new_session_path(resource_name)
|
||||||
|
else
|
||||||
|
render_with_scope :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# GET /resource/password/edit?reset_password_token=abcdef
|
# GET /resource/password/edit?reset_password_token=abcdef
|
||||||
def edit
|
def edit
|
||||||
self.resource = resource_class.new
|
self.resource = resource_class.new
|
||||||
|
@ -22,10 +39,4 @@ class PasswordsController < ApplicationController
|
||||||
render_with_scope :edit
|
render_with_scope :edit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def send_instructions_with
|
|
||||||
:send_reset_password_instructions
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
class RegistrationsController < ApplicationController
|
class RegistrationsController < ApplicationController
|
||||||
include Devise::Controllers::InternalHelpers
|
include Devise::Controllers::InternalHelpers
|
||||||
include Devise::Controllers::Common
|
|
||||||
|
|
||||||
# POST /resource/registration
|
before_filter :require_no_authentication, :only => [ :new, :create ]
|
||||||
|
before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
|
||||||
|
|
||||||
|
# GET /resource/sign_in
|
||||||
|
def new
|
||||||
|
build_resource
|
||||||
|
render_with_scope :new
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /resource/sign_up
|
||||||
def create
|
def create
|
||||||
self.resource = resource_class.new(params[resource_name])
|
build_resource
|
||||||
|
|
||||||
if resource.save
|
if resource.save
|
||||||
flash[:"#{resource_name}_signed_up"] = true
|
flash[:"#{resource_name}_signed_up"] = true
|
||||||
|
@ -14,4 +22,33 @@ class RegistrationsController < ApplicationController
|
||||||
render_with_scope :new
|
render_with_scope :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
# GET /resource/edit
|
||||||
|
def edit
|
||||||
|
render_with_scope :edit
|
||||||
|
end
|
||||||
|
|
||||||
|
# PUT /resource
|
||||||
|
def update
|
||||||
|
if self.resource.update_with_password(params[resource_name])
|
||||||
|
set_flash_message :notice, :updated
|
||||||
|
redirect_to after_sign_in_path_for(self.resource)
|
||||||
|
else
|
||||||
|
render_with_scope :edit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /resource
|
||||||
|
def destroy
|
||||||
|
self.resource.destroy
|
||||||
|
sign_out_and_redirect(self.resource)
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
# Authenticates the current scope and dup the resource
|
||||||
|
def authenticate_scope!
|
||||||
|
send(:"authenticate_#{resource_name}!")
|
||||||
|
self.resource = send(:"current_#{resource_name}").dup
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,15 +1,18 @@
|
||||||
class SessionsController < ApplicationController
|
class SessionsController < ApplicationController
|
||||||
include Devise::Controllers::InternalHelpers
|
include Devise::Controllers::InternalHelpers
|
||||||
include Devise::Controllers::Common
|
|
||||||
|
|
||||||
before_filter :require_no_authentication, :only => [ :new, :create ]
|
before_filter :require_no_authentication, :only => [ :new, :create ]
|
||||||
|
|
||||||
# GET /resource/sign_in
|
# GET /resource/sign_in
|
||||||
def new
|
def new
|
||||||
Devise::FLASH_MESSAGES.each do |message|
|
unless resource_just_signed_up?
|
||||||
set_now_flash_message :alert, message if params.try(:[], message) == "true"
|
Devise::FLASH_MESSAGES.each do |message|
|
||||||
end unless resource_just_signed_up?
|
set_now_flash_message :alert, message if params.try(:[], message) == "true"
|
||||||
super
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
build_resource
|
||||||
|
render_with_scope :new
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /resource/sign_in
|
# POST /resource/sign_in
|
||||||
|
@ -19,7 +22,7 @@ class SessionsController < ApplicationController
|
||||||
sign_in_and_redirect(resource_name, resource, true)
|
sign_in_and_redirect(resource_name, resource, true)
|
||||||
else
|
else
|
||||||
set_now_flash_message :alert, (warden.message || :invalid)
|
set_now_flash_message :alert, (warden.message || :invalid)
|
||||||
build_resource
|
clean_up_password_methods(build_resource)
|
||||||
render_with_scope :new
|
render_with_scope :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -35,4 +38,10 @@ class SessionsController < ApplicationController
|
||||||
def resource_just_signed_up?
|
def resource_just_signed_up?
|
||||||
flash[:"#{resource_name}_signed_up"]
|
flash[:"#{resource_name}_signed_up"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def clean_up_password_methods(object)
|
||||||
|
[:password=, :password_confirmation=].each do |method|
|
||||||
|
object.send(method, nil) if object.respond_to?(method)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,23 @@
|
||||||
class UnlocksController < ApplicationController
|
class UnlocksController < ApplicationController
|
||||||
include Devise::Controllers::InternalHelpers
|
include Devise::Controllers::InternalHelpers
|
||||||
include Devise::Controllers::Common
|
|
||||||
|
# GET /resource/unlock/new
|
||||||
|
def new
|
||||||
|
build_resource
|
||||||
|
render_with_scope :new
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /resource/unlock
|
||||||
|
def create
|
||||||
|
self.resource = resource_class.send_unlock_instructions(params[resource_name])
|
||||||
|
|
||||||
|
if resource.errors.empty?
|
||||||
|
set_flash_message :notice, :send_instructions
|
||||||
|
redirect_to new_session_path(resource_name)
|
||||||
|
else
|
||||||
|
render_with_scope :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# GET /resource/unlock?unlock_token=abcdef
|
# GET /resource/unlock?unlock_token=abcdef
|
||||||
def show
|
def show
|
||||||
|
@ -13,10 +30,4 @@ class UnlocksController < ApplicationController
|
||||||
render_with_scope :new
|
render_with_scope :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def send_instructions_with
|
|
||||||
:send_unlock_instructions
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,6 @@ module Devise
|
||||||
autoload :TestHelpers, 'devise/test_helpers'
|
autoload :TestHelpers, 'devise/test_helpers'
|
||||||
|
|
||||||
module Controllers
|
module Controllers
|
||||||
autoload :Common, 'devise/controllers/common'
|
|
||||||
autoload :Helpers, 'devise/controllers/helpers'
|
autoload :Helpers, 'devise/controllers/helpers'
|
||||||
autoload :InternalHelpers, 'devise/controllers/internal_helpers'
|
autoload :InternalHelpers, 'devise/controllers/internal_helpers'
|
||||||
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
module Devise
|
|
||||||
module Controllers
|
|
||||||
# Common actions shared between Devise controllers
|
|
||||||
module Common #:nodoc:
|
|
||||||
# GET /resource/controller/new
|
|
||||||
def new
|
|
||||||
build_resource
|
|
||||||
render_with_scope :new
|
|
||||||
end
|
|
||||||
|
|
||||||
# POST /resource/controller
|
|
||||||
def create
|
|
||||||
self.resource = resource_class.send(send_instructions_with, params[resource_name])
|
|
||||||
|
|
||||||
if resource.errors.empty?
|
|
||||||
set_flash_message :notice, :send_instructions
|
|
||||||
redirect_to new_session_path(resource_name)
|
|
||||||
else
|
|
||||||
render_with_scope :new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -70,12 +70,9 @@ module Devise
|
||||||
instance_variable_set(:"@#{resource_name}", new_resource)
|
instance_variable_set(:"@#{resource_name}", new_resource)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Build a devise resource without setting password and password confirmation fields.
|
# Build a devise resource.
|
||||||
def build_resource
|
def build_resource
|
||||||
self.resource ||= begin
|
self.resource ||= resource_class.new(params[resource_name] || {})
|
||||||
attributes = params[resource_name].try(:except, :password, :password_confirmation)
|
|
||||||
resource_class.new(attributes || {})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Helper for use in before_filters where no authentication is required.
|
# Helper for use in before_filters where no authentication is required.
|
||||||
|
|
Loading…
Add table
Reference in a new issue