Skip to content
Browse files

Require login/logout to loop through PG communityauth.

  • Loading branch information...
1 parent 3994e39 commit 3b8e2e864796ff30c705e7398199eb64e500d5dd @ashcmd ashcmd committed
View
2 init.rb
@@ -2,10 +2,8 @@
require 'dispatcher'
Dispatcher.to_prepare do
- require_dependency 'application_controller'
require_dependency 'account_controller'
- ApplicationController.send(:include, RedminePgcommunityauth::ApplicationControllerPatch)
AccountController.send(:include, RedminePgcommunityauth::AccountControllerPatch)
end
View
37 lib/redmine_pgcommunityauth/account_controller_patch.rb
@@ -8,8 +8,29 @@ module AccountControllerPatch
class AuthTokenExpiredError < RuntimeError; end
class InvalidAuthTokenError < RuntimeError; end
+ def self.included(base)
+ base.class_eval do
+ alias_method_chain :login, :pgcommunityauth
+ alias_method_chain :logout, :pgcommunityauth
+ end
+ end
+
+ def login_with_pgcommunityauth
+ redirect_to pgcommunityauth_login_url
+ end
+
+ def logout_with_pgcommunityauth
+ logout_user
+ redirect_to pgcommunityauth_logout_url
+ end
+
# GET /pgcommunityauth
def pgcommunityauth
+ if params[:s] == 'logout'
+ flash[:notice] = "Successfully logged out from PG community sites."
+ return
+ end
+
data = (params[:d] || "").tr('-_', '+/')
iv = (params[:i] || "").tr('-_', '+/')
@@ -49,6 +70,22 @@ def pgcommunityauth
private
+ def pgcommunityauth_settings
+ Setting['plugin_redmine_pgcommunityauth']
+ end
+
+ def pgcommunityauth_base_url
+ "https://www.postgresql.org/account/auth/#{pgcommunityauth_settings[:authsite_id]}"
+ end
+
+ def pgcommunityauth_login_url
+ "#{pgcommunityauth_base_url}/"
+ end
+
+ def pgcommunityauth_logout_url
+ "#{pgcommunityauth_base_url}/logout/"
+ end
+
def aes_decrypt(data, iv)
key = Base64.decode64(pgcommunityauth_settings[:cipher_key])
View
33 lib/redmine_pgcommunityauth/application_controller_patch.rb
@@ -1,33 +0,0 @@
-module RedminePgcommunityauth
- module ApplicationControllerPatch
- unloadable
-
- def self.included(base)
- base.class_eval do
- alias_method_chain :require_login, :pgcommunityauth
- end
- end
-
- def require_login_with_pgcommunityauth
- if User.current.logged?
- require_login_without_pgcommunityauth
- else
- respond_to do |format|
- format.html { redirect_to pgcommunityauth_url }
- end
- end
- end
-
- protected
-
- def pgcommunityauth_settings
- Setting['plugin_redmine_pgcommunityauth']
- end
-
- private
-
- def pgcommunityauth_url
- "https://www.postgresql.org/account/auth/#{pgcommunityauth_settings[:authsite_id]}/"
- end
- end
-end

0 comments on commit 3b8e2e8

Please sign in to comment.
Something went wrong with that request. Please try again.