Class: Lato::AccountController

Inherits:
ApplicationController show all
Defined in:
app/controllers/lato/account_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#error, #not_found, #offline, #switch_locale

Methods included from Componentable

#lato_index_collection

Methods included from Layoutable

#active_navbar, #active_sidebar, #hide_sidebar, #page_class, #page_classes, #page_title, #show_sidebar

Methods included from Sessionable

#authenticate_session, #limit_requests, #not_authenticate_session, #session_create, #session_destroy

Instance Method Details

#destroy_actionObject



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/lato/account_controller.rb', line 82

def destroy_action
  respond_to do |format|
    if @session.user.destroy_with_confirmation(params.require(:user).permit(:email_confirmation))
      session_destroy

      format.html { redirect_to lato.root_path }
      format.json { render json: {} }
    else
      format.html { render :index, status: :unprocessable_entity }
      format.json { render json: @session.user.errors, status: :unprocessable_entity }
    end
  end
end

#indexObject



6
# File 'app/controllers/lato/account_controller.rb', line 6

def index; end

#request_verify_email_actionObject



58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/lato/account_controller.rb', line 58

def request_verify_email_action
  respond_to do |format|
    if @session.user.request_verify_email
      format.html { redirect_to lato., notice: I18n.t('lato.account_controller.request_verify_email_action_notice') }
      format.json { render json: @session.user }
    else
      format.html { render :index, status: :unprocessable_entity }
      format.json { render json: @session.user.errors, status: :unprocessable_entity }
    end
  end
end

#update_accepted_privacy_policy_version_actionObject



96
97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/lato/account_controller.rb', line 96

def update_accepted_privacy_policy_version_action
  respond_to do |format|
    if @session.user.update_accepted_privacy_policy_version(params.require(:user).permit(:confirm))
      format.html { redirect_to lato. }
      format.json { render json: @session.user }
    else
      format.html { render :index, status: :unprocessable_entity }
      format.json { render json: @session.user.errors, status: :unprocessable_entity }
    end
  end
end

#update_accepted_terms_and_conditions_version_actionObject



108
109
110
111
112
113
114
115
116
117
118
# File 'app/controllers/lato/account_controller.rb', line 108

def update_accepted_terms_and_conditions_version_action
  respond_to do |format|
    if @session.user.update_accepted_terms_and_conditions_version(params.require(:user).permit(:confirm))
      format.html { redirect_to lato. }
      format.json { render json: @session.user }
    else
      format.html { render :index, status: :unprocessable_entity }
      format.json { render json: @session.user.errors, status: :unprocessable_entity }
    end
  end
end

#update_password_actionObject



70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/lato/account_controller.rb', line 70

def update_password_action
  respond_to do |format|
    if @session.user.update(params.require(:user).permit(:password, :password_confirmation))
      format.html { redirect_to lato., notice: I18n.t('lato.account_controller.update_password_action_notice') }
      format.json { render json: @session.user }
    else
      format.html { render :index, status: :unprocessable_entity }
      format.json { render json: @session.user.errors, status: :unprocessable_entity }
    end
  end
end

#update_user_actionObject



8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/lato/account_controller.rb', line 8

def update_user_action
  respond_to do |format|
    if @session.user.update(params.require(:user).permit(:first_name, :last_name, :email))
      format.html { redirect_to lato., notice: I18n.t('lato.account_controller.update_user_action_notice') }
      format.json { render json: @session.user }
    else
      format.html { render :index, status: :unprocessable_entity }
      format.json { render json: @session.user.errors, status: :unprocessable_entity }
    end
  end
end

#update_web3_actionObject



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 'app/controllers/lato/account_controller.rb', line 20

def update_web3_action
  return respond_to_with_not_found unless Lato.config.web3_connection

  if @session.user.web3_address
    respond_to do |format|
      if @session.user.remove_web3_connection
        format.html { redirect_to lato. }
        format.json { render json: @session.user }
      else
        format.html { render :index, status: :unprocessable_entity }
        format.json { render json: @session.user.errors, status: :unprocessable_entity }
      end
    end
  elsif session[:web3_nonce]
    respond_to do |format|
      if @session.user.add_web3_connection(params.require(:user).permit(:web3_address, :web3_signed_nonce).merge(web3_nonce: session[:web3_nonce]))
        session[:web3_nonce] = nil
        format.html { redirect_to lato. }
        format.json { render json: @session.user }
      else
        session[:web3_nonce] = nil
        format.html { render :index, status: :unprocessable_entity }
        format.json { render json: @session.user.errors, status: :unprocessable_entity }
      end
    end
  else
    respond_to do |format|
      if session[:web3_nonce] = SecureRandom.hex(32)
        format.html { redirect_to lato. }
        format.json { render json: @session.user }
      else
        format.html { render :index, status: :unprocessable_entity }
        format.json { render json: @session.user.errors, status: :unprocessable_entity }
      end
    end
  end
end