diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index eea1660e..3f925c5e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + def setup_user; end def render_404 diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 890d5573..6902a072 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -7,7 +7,5 @@ def check_signed_in redirect_to profile_path if signed_in? end - def index - - end + def index; end end diff --git a/app/controllers/profile_controller.rb b/app/controllers/profile_controller.rb index 5839fda5..0a95718d 100755 --- a/app/controllers/profile_controller.rb +++ b/app/controllers/profile_controller.rb @@ -11,9 +11,7 @@ def regen_auth redirect_to profile_path end - def show - - end + def show; end def user_admin @users = [] @@ -105,19 +103,20 @@ def authenticate_ms_chap def authenticate_cas - username = User.authenticate_cas request.env["HTTP_AUTHORIZATION"] + user = User.find_by(user_login_id: username) - ## cas-5.1.x expects {"@c":".SimplePrincipal","id":"casuser","attributes":{}} + ## cas-5.2.x expects {"@c":".SimplePrincipal","id":"casuser","attributes":{}} response_map = { - "@class":"org.apereo.cas.authentication.principal.SimplePrincipal", - "id" => username, - "attributes": {"backend": "gate-sso"} + '@class':'org.apereo.cas.authentication.principal.SimplePrincipal', + 'id' => username, + 'attributes': {'backend': 'gate-sso', 'email': user.try(:email), 'auth_token': user.try(:auth_key), 'admin': user.try(:admin)}, } if username.present? render json: response_map, status: :ok else + response_map['attributes'] = nil render json: response_map, status: 401 end end @@ -182,10 +181,7 @@ def update redirect_to user_path end - def user_edit - - - end + def user_edit; end def public_key_update @user = User.where(id: params[:id]).first diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index eb63c8a5..7e3cac98 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -5,10 +5,12 @@ def google_oauth2 # data = request.env['omniauth.auth'] domain = data['info']['email'].split('@').last + unless User.valid_domain? domain return render text: 'Your domain is unauthorized', status: :unauthorized end @user = User.create_user(data.info['name'], data.info['email']) + if @user.persisted? @user.generate_two_factor_auth sign_in_and_redirect @user, event: :authentication diff --git a/config/routes.rb b/config/routes.rb old mode 100755 new mode 100644