first commit

This commit is contained in:
chiu 2020-05-08 11:10:28 +08:00
parent 06e8148634
commit 99d63dbaed
5 changed files with 8 additions and 30 deletions

View File

@ -1,30 +1,3 @@
require 'mcrypt'
class SsoLoginBoxController < SessionsController
def tku_login
redirect_to root_url and return if !params[:t].present?
str_decoded = Base64.decode64(params[:sso_userid].to_s)
mc = Mcrypt.new(:des,:ecb)
mc.padding = :pkcs
mc.key = "3M7PvTSE"
plain = mc.decrypt(str_decoded)
t = mc.decrypt(Base64.decode64(params[:t])).to_i
nt = DateTime.now.to_time.to_i
if (nt - t) < 10
user = MemberProfile.where(:sid => plain).first.user rescue nil
if !user.nil?
session[:user_id] = user.id
session[:login_referer] = nil
if params[:referer_url]
redirect_to URI.parse(params[:referer_url]).path
else
redirect_to admin_dashboards_path
end
else
flash.now.alert = "User not found."
render "new"
end
else
redirect_to root_url
end
end
end

2
config/locales/en.yml Normal file
View File

@ -0,0 +1,2 @@
en:
nccu_lib_login: Library acoount login

2
config/locales/zh_tw.yml Normal file
View File

@ -0,0 +1,2 @@
zh_tw:
nccu_lib_login: 圖書館帳號登入

View File

@ -4,7 +4,7 @@ module SsoLoginBox
initializer "sso_login_box" do
OrbitApp.registration "SsoLoginBox", :type => "ModuleApp" do
base_url File.expand_path File.dirname(__FILE__)
set_keyword_contstraints ['/sso/tku_redirect']
#set_keyword_contstraints ['/sso/tku_redirect']
end
end
end

View File

@ -1,6 +1,7 @@
module SsoLoginBox::LoginTag
def self.show
url_for_sso = File.read("#{ENV['PWD']}/sso_url.txt").force_encoding('utf-8').gsub(/\n/,'')
"<div class=\"pull-right\"><a href=\"#{url_for_sso}\">SSO Login</a></div>"
"<div style=\"text-align: right;\" class=\"pull-right\">
<a style=\"border: 0.1em solid;padding: 0.5em;\" href=\"#{url_for_sso}\">#{t('nccu_lib_login')}</a></div>"
end
end