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
|
# File 'app/controllers/collavre_notion/notion_auth_controller.rb', line 6
def callback
auth = request.env["omniauth.auth"]
notion = CollavreNotion::NotionAccount.find_or_initialize_by(notion_uid: auth.uid)
if notion.new_record?
unless Current.user
redirect_to collavre.new_session_path, alert: I18n.t("collavre_notion.notion_auth.login_first")
return
end
notion.user = Current.user
end
notion.token = auth.credentials.token
notion.workspace_name = auth.info.name
notion.save!
if params[:popup] || request.referer&.include?("popup=true") || session[:oauth_popup]
session.delete(:oauth_popup)
@fallback_path = collavre.creatives_path
render template: "collavre_notion/notion_auth/callback_success", layout: false
else
redirect_to collavre.creatives_path, notice: I18n.t("collavre_notion.notion_auth.connected")
end
end
|