-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathsessions_controller.rb
43 lines (32 loc) · 1.07 KB
/
sessions_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
# frozen_string_literal: true
class SessionsController < ApplicationController
include WithEmailAuth
def offline_login
user = User.find_by(nickname: params[:nickname])
sign_in(user)
redirect_to root_path, notice: 'Offline Login!'
end
def index; end
def create
begin
authorization = Authorization.handle_authorization(current_user, request.env['omniauth.auth'])
sign_in(authorization.user)
options = { notice: t('flash.logged_in', name: current_user.name) }
rescue User::DuplicateNickname => e
options = { alert: t('flash.duplicate_nick', name: e.nickname) }
end
redirect_path = request.env['omniauth.origin'].presence || root_path
if current_user&.missing_name?
options = { alert: t('flash.update_profile_details') }
redirect_path = edit_user_path(current_user)
end
redirect_to redirect_path, options
end
def destroy
sign_out
redirect_to root_path, notice: flash[:notice] || t('flash.logged_out')
end
def failure
redirect_to root_path, alert: t('flash.login_error')
end
end