Module: Revise::Controllers::Accounts

Defined in:
lib/revise/controllers/accounts.rb

Class Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object



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
# File 'lib/revise/controllers/accounts.rb', line 4

def self.extended(klass)
  klass.controllers :accounts do
    before(:show, :edit, :update, :destroy) do  
      @account =    
      halt 403, 'Login first' unless @account
    end

    get :new, :map => '/accounts/new', :priority => :low do
      @account = Account.new
      render 'accounts/new'
    end

    post :create, :map => '/accounts', :priority => :low do
      if   
        flash[:notice] = "You are already registered"  
        redirect_back_or_default(url(:main, :index))
      end 

      @account = Account.new(params[:account])   
      if @account.save  
        redirect url(:main, :index)
      else
        status 400
        render 'accounts/new'
      end
    end

    get :edit, :map => '/accounts/edit', :priority => :low do
      respond(@account)
    end

    put :update, :map => '/accounts', :priority => :low do  
      @account.update_attributes!(params[:account])  
      respond(@account, url(:accounts, :edit))
    end   

    delete :destroy, :map => '/accounts', :priority => :low do
      if .respond_to?(:archive)
        destroyed = .archive
      else
        destroyed = .destroy
      end

      if destroyed
        flash[:notice] = "You have successfully deleted your account. It is disabled for now and will be completely 
          removed within 48 hours."  
      else
        flash[:warning] = "Couldn't Delete Your Account"
      end
      redirect_back_or_default(url(:main, :index))
    end   
  end
end