Class: Lato::AuthenticationController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#error, #index, #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

#accept_invitationObject

Accept invitation



166
167
168
# File 'app/controllers/lato/authentication_controller.rb', line 166

def accept_invitation
  @user = Lato::User.new(email: @invitation.email)
end

#accept_invitation_actionObject



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'app/controllers/lato/authentication_controller.rb', line 170

def accept_invitation_action
  @user = Lato::User.new(registration_params)

  respond_to do |format|
    if @user.accept_invitation(params.permit(:id, :accepted_code))
      session_create(@user.id)

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

#recover_passwordObject

Recover password



128
129
130
# File 'app/controllers/lato/authentication_controller.rb', line 128

def recover_password
  @user = Lato::User.new
end

#recover_password_actionObject



132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'app/controllers/lato/authentication_controller.rb', line 132

def recover_password_action
  @user = Lato::User.new

  respond_to do |format|
    if @user.request_recover_password(params.require(:user).permit(:email))
      format.html { redirect_to lato.authentication_update_password_path(id: @user.id) }
      format.json { render json: @user }
    else
      format.html { render :recover_password, status: :unprocessable_entity }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

#signinObject

Signin



19
20
21
# File 'app/controllers/lato/authentication_controller.rb', line 19

def 
  @user = Lato::User.new
end

#signin_actionObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/lato/authentication_controller.rb', line 23

def 
  @user = Lato::User.new

  respond_to do |format|
    if @user.(params.require(:user).permit(:email, :password).merge(
      ip_address: request.remote_ip,
      user_agent: request.user_agent
    ))
      session_create(@user.id)

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

#signoutObject

Signout



95
# File 'app/controllers/lato/authentication_controller.rb', line 95

def signout; end

#signout_actionObject



97
98
99
100
101
102
103
104
# File 'app/controllers/lato/authentication_controller.rb', line 97

def signout_action
  session_destroy

  respond_to do |format|
    format.html { redirect_to lato.root_path }
    format.json { render json: {} }
  end
end

#signupObject

Signup



72
73
74
# File 'app/controllers/lato/authentication_controller.rb', line 72

def 
  @user = Lato::User.new
end

#signup_actionObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/lato/authentication_controller.rb', line 76

def 
  @user = Lato::User.new(registration_params)

  respond_to do |format|
    if @user.(ip_address: request.remote_ip, user_agent: request.user_agent)
      session_create(@user.id)

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

#update_passwordObject

Update password



149
# File 'app/controllers/lato/authentication_controller.rb', line 149

def update_password; end

#update_password_actionObject



151
152
153
154
155
156
157
158
159
160
161
# File 'app/controllers/lato/authentication_controller.rb', line 151

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

#verify_emailObject

Verify email



109
110
111
# File 'app/controllers/lato/authentication_controller.rb', line 109

def verify_email
  @code = params[:code]
end

#verify_email_actionObject



113
114
115
116
117
118
119
120
121
122
123
# File 'app/controllers/lato/authentication_controller.rb', line 113

def verify_email_action
  respond_to do |format|
    if @user.verify_email(params.require(:user).permit(:code))
      format.html { redirect_to lato.root_path, notice: I18n.t('lato.authentication_controller.verify_email_action_notice') }
      format.json { render json: @user }
    else
      format.html { render :verify_email, status: :unprocessable_entity }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

#web3_signinObject



42
43
44
45
# File 'app/controllers/lato/authentication_controller.rb', line 42

def 
  @user = Lato::User.new
  session[:web3_nonce] = SecureRandom.hex(32)
end

#web3_signin_actionObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/lato/authentication_controller.rb', line 47

def 
  @user = Lato::User.new

  respond_to do |format|
    if @user.(params.require(:user).permit(:web3_address, :web3_signed_nonce).merge(
      ip_address: request.remote_ip,
      user_agent: request.user_agent,
      web3_nonce: session[:web3_nonce]
    ))
      session[:web3_nonce] = nil
      session_create(@user.id)

      format.html { redirect_to lato.root_path }
      format.json { render json: @user }
    else
      session[:web3_nonce] = nil
      format.html { render :web3_signin, status: :unprocessable_entity }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end