forked from External/greenlight
GRN2-6: Added the ability for admins to specify registration method (#520)
* Added the ability to invite users * Small bug fix * Added the ability to approve/decline users * Small bug fixes * More bug fixes * More minor changes * Final changes
This commit is contained in:
committed by
Jesus Federico
parent
adf4b68008
commit
720dac6012
@ -17,6 +17,8 @@
|
||||
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class SessionsController < ApplicationController
|
||||
include Registrar
|
||||
|
||||
skip_before_action :verify_authenticity_token, only: [:omniauth, :fail]
|
||||
|
||||
# GET /users/logout
|
||||
@ -32,11 +34,11 @@ class SessionsController < ApplicationController
|
||||
user = admin
|
||||
else
|
||||
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(signin_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(account_activation_path(email: user.email)) && return unless user.activated?
|
||||
end
|
||||
redirect_to(root_path, alert: I18n.t("invalid_credentials")) && return unless user.try(:authenticate,
|
||||
redirect_to(signin_path, alert: I18n.t("invalid_credentials")) && return unless user.try(:authenticate,
|
||||
session_params[:password])
|
||||
|
||||
login(user)
|
||||
@ -44,11 +46,26 @@ class SessionsController < ApplicationController
|
||||
|
||||
# GET/POST /auth/:provider/callback
|
||||
def omniauth
|
||||
user = User.from_omniauth(request.env['omniauth.auth'])
|
||||
login(user)
|
||||
rescue => e
|
||||
logger.error "Error authenticating via omniauth: #{e}"
|
||||
omniauth_fail
|
||||
begin
|
||||
@auth = request.env['omniauth.auth']
|
||||
@user_exists = check_user_exists
|
||||
|
||||
# If using invitation registration method, make sure user is invited
|
||||
return redirect_to root_path, flash: { alert: I18n.t("registration.invite.no_invite") } unless passes_invite_reqs
|
||||
|
||||
user = User.from_omniauth(@auth)
|
||||
|
||||
# Add pending role if approval method and is a new user
|
||||
if approval_registration && !@user_exists
|
||||
user.add_role :pending
|
||||
return redirect_to root_path, flash: { success: I18n.t("registration.approval.signup") }
|
||||
end
|
||||
|
||||
login(user)
|
||||
rescue => e
|
||||
logger.error "Error authenticating via omniauth: #{e}"
|
||||
omniauth_fail
|
||||
end
|
||||
end
|
||||
|
||||
# POST /auth/failure
|
||||
@ -61,4 +78,17 @@ class SessionsController < ApplicationController
|
||||
def session_params
|
||||
params.require(:session).permit(:email, :password)
|
||||
end
|
||||
|
||||
def check_user_exists
|
||||
provider = @auth['provider'] == "bn_launcher" ? @auth['info']['customer'] : @auth['provider']
|
||||
User.exists?(social_uid: @auth['uid'], provider: provider)
|
||||
end
|
||||
|
||||
# Check if the user already exists, if not then check for invitation
|
||||
def passes_invite_reqs
|
||||
return true if @user_exists
|
||||
|
||||
invitation = check_user_invited("", session[:invite_token], @user_domain)
|
||||
invitation[:present]
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user