This repository has been archived on 2021-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
greenlight/app/controllers/sessions_controller.rb

59 lines
2.0 KiB
Ruby
Raw Normal View History

2018-06-26 10:29:46 -04:00
# frozen_string_literal: true
2018-05-07 16:06:01 -04:00
2018-08-01 09:45:12 -04:00
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
2018-06-26 10:29:46 -04:00
class SessionsController < ApplicationController
2018-07-20 14:20:14 -04:00
skip_before_action :verify_authenticity_token, only: [:omniauth, :fail]
# GET /users/logout
2018-05-07 16:06:01 -04:00
def destroy
2018-05-11 15:57:31 -04:00
logout
redirect_to root_path
2018-05-07 16:06:01 -04:00
end
# POST /users/login
2018-05-07 16:06:01 -04:00
def create
user = User.find_by(email: session_params[:email], provider: @user_domain)
redirect_to(root_path, alert: I18n.t("invalid_user")) && return unless user
redirect_to(root_path, alert: I18n.t("invalid_login_method")) && return unless user.greenlight_account?
redirect_to(root_path, alert: I18n.t("invalid_credentials")) && return unless user.try(:authenticate,
session_params[:password])
redirect_to(account_activation_path(email: user.email)) && return unless user.activated?
login(user)
2018-05-09 16:31:52 -04:00
end
# GET/POST /auth/:provider/callback
2018-05-10 15:03:59 -04:00
def omniauth
2018-05-07 16:06:01 -04:00
user = User.from_omniauth(request.env['omniauth.auth'])
login(user)
2018-06-27 17:00:37 -04:00
rescue => e
logger.error "Error authenticating via omniauth: #{e}"
2018-07-23 12:07:26 -04:00
omniauth_fail
2018-05-07 16:06:01 -04:00
end
# POST /auth/failure
2018-07-23 12:07:26 -04:00
def omniauth_fail
redirect_to root_path, alert: I18n.t(params[:message], default: I18n.t("omniauth_error"))
2018-05-09 16:31:52 -04:00
end
private
2018-05-07 16:06:01 -04:00
2018-05-09 16:31:52 -04:00
def session_params
params.require(:session).permit(:email, :password)
2018-05-07 16:06:01 -04:00
end
end