forked from heartcombo/devise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registrations_controller.rb
57 lines (48 loc) · 1.38 KB
/
registrations_controller.rb
1
2
3
4
5
6
7
8
9
10
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
45
46
47
48
49
50
51
52
53
54
55
56
57
class RegistrationsController < ApplicationController
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
include Devise::Controllers::InternalHelpers
# GET /resource/sign_up
def new
build_resource
render_with_scope :new
end
# Overriding the default devise create action
# instead of signing in, we just redirect to the new users domain
# POST /resource
def create
logger.info "OVERRIDDEN CREATE"
build_resource
if resource.save
set_flash_message :notice, :signed_up
redirect_to after_sign_in_path_for(resource)
else
render_with_scope :new
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
set_flash_message :notice, :destroyed
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