Class: AccountController

Inherits:
Devise::RegistrationsController
  • Object
show all
Defined in:
app/controllers/account_controller.rb

Overview

Devise User Controller

Instance Method Summary collapse

Instance Method Details

#createObject

POST /resource


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/account_controller.rb', line 16

def create
  build_resource()
  resource. = params[resource_name][:login]
  resource.email = params[resource_name][:email]
  if verify_rucaptcha?(resource) && resource.save
    if resource.active_for_authentication?
      set_flash_message :notice, :signed_up if is_navigational_format?
      (resource_name, resource)
      respond_with resource, location: (resource)
    else
      set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
      expire_session_data_after_sign_in!
      respond_with resource, location: (resource)
    end
  else
    clean_up_passwords resource
    respond_with resource
  end
end

#destroyObject


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/account_controller.rb', line 36

def destroy
  current_password = params[:user][:current_password]

  if current_user.valid_password?(current_password)
    resource.soft_delete
    sign_out
    redirect_to root_path
    set_flash_message :notice, :destroyed
  else
    current_user.errors.add(:current_password, :invalid)
    render 'edit'
  end
end

#editObject


5
6
7
8
9
# File 'app/controllers/account_controller.rb', line 5

def edit
  @user = current_user
  # 首次生成用户 Token
  @user.ensure_private_token!
end

#updateObject


11
12
13
# File 'app/controllers/account_controller.rb', line 11

def update
  super
end