forked from saurabh/orbit4-5
Compare commits
6 Commits
Author | SHA1 | Date |
---|---|---|
|
6b1fbd4844 | |
|
e918b3b644 | |
|
31adb1cf0c | |
|
180c1a4047 | |
|
f886a32615 | |
|
2bddb38c31 |
3
Gemfile
3
Gemfile
|
@ -47,6 +47,9 @@ gem 'ckeditor'
|
||||||
gem 'unicorn'
|
gem 'unicorn'
|
||||||
gem 'zhconv'
|
gem 'zhconv'
|
||||||
gem 'time_difference'
|
gem 'time_difference'
|
||||||
|
|
||||||
|
gem "net-ldap", "~> 0.3.1"
|
||||||
|
|
||||||
gem 'execjs'
|
gem 'execjs'
|
||||||
gem 'therubyracer'
|
gem 'therubyracer'
|
||||||
|
|
||||||
|
|
|
@ -121,8 +121,8 @@ class Admin::ImportController < OrbitAdminController
|
||||||
if(file['url'])
|
if(file['url'])
|
||||||
archive = ArchiveFileMultiple.new({
|
archive = ArchiveFileMultiple.new({
|
||||||
:file_title_translations=>file['title'],
|
:file_title_translations=>file['title'],
|
||||||
:choose_lang => @site_valid_locales,
|
:choose_lang => ["zh_tw", "en"],
|
||||||
:remote_file_url => file['url'],
|
:remote_file_url => file['url'],
|
||||||
:sort_number=>file['sort_number']
|
:sort_number=>file['sort_number']
|
||||||
})
|
})
|
||||||
archive.save
|
archive.save
|
||||||
|
@ -132,8 +132,8 @@ class Admin::ImportController < OrbitAdminController
|
||||||
if(file['url2'])
|
if(file['url2'])
|
||||||
archive = ArchiveFileMultiple.new({
|
archive = ArchiveFileMultiple.new({
|
||||||
:file_title_translations=>file['title'],
|
:file_title_translations=>file['title'],
|
||||||
:choose_lang => @site_valid_locales,
|
:choose_lang => ["zh_tw", "en"],
|
||||||
:remote_file_url => file['url2'],
|
:remote_file_url => file['url2'],
|
||||||
:sort_number=>file['sort_number']
|
:sort_number=>file['sort_number']
|
||||||
})
|
})
|
||||||
archive.save
|
archive.save
|
||||||
|
@ -204,7 +204,7 @@ class Admin::ImportController < OrbitAdminController
|
||||||
|
|
||||||
File.delete(file)
|
File.delete(file)
|
||||||
end
|
end
|
||||||
bulletin.approved = true
|
bulletin.approved = true rescue nil
|
||||||
bulletin.save!
|
bulletin.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -559,16 +559,29 @@ class Admin::ImportController < OrbitAdminController
|
||||||
data = JSON.parse(data)
|
data = JSON.parse(data)
|
||||||
albums = data["albums"]
|
albums = data["albums"]
|
||||||
current_locale = I18n.locale
|
current_locale = I18n.locale
|
||||||
I18n.locale = :en
|
|
||||||
category = Category.where(:title => "RSS2 Gallery").first
|
categories = data["categories"]
|
||||||
I18n.locale = current_locale
|
I18n.locale = :zh_tw
|
||||||
if category.nil?
|
module_app = ModuleApp.find_by_key("gallery")
|
||||||
module_app = ModuleApp.find_by_key("gallery")
|
categories.each do |category|
|
||||||
category = Category.new
|
cat = Category.where(:title => category[1]["zh_tw"], :module_app_id => module_app.id).first
|
||||||
category.title_translations = {"en" => "RSS2 Gallery", "zh_tw" => "RSS2畫廊"}
|
if cat.nil?
|
||||||
category.save
|
cat = Category.new
|
||||||
module_app.categories << category
|
cat.title_translations = {"en" => (category[1]["en"] || category[1]["zh_tw"]), "zh_tw" => (category[1]["zh_tw"] || category[1]["en"])}
|
||||||
|
cat.save
|
||||||
|
module_app.categories << cat
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
# I18n.locale = :en
|
||||||
|
# category = Category.where(:title => "RSS2 Gallery").first
|
||||||
|
# I18n.locale = current_locale
|
||||||
|
# if category.nil?
|
||||||
|
# module_app = ModuleApp.find_by_key("gallery")
|
||||||
|
# category = Category.new
|
||||||
|
# category.title_translations = {"en" => "RSS2 Gallery", "zh_tw" => "RSS2畫廊"}
|
||||||
|
# category.save
|
||||||
|
# module_app.categories << category
|
||||||
|
# end
|
||||||
@data_to_send = []
|
@data_to_send = []
|
||||||
albums.each do |album|
|
albums.each do |album|
|
||||||
if Album.where(:rss2_id => album["albumid"]).count == 0
|
if Album.where(:rss2_id => album["albumid"]).count == 0
|
||||||
|
@ -578,6 +591,7 @@ class Admin::ImportController < OrbitAdminController
|
||||||
"en" => (album["description"]["en"].nil? ? "" : album["description"]["en"]),
|
"en" => (album["description"]["en"].nil? ? "" : album["description"]["en"]),
|
||||||
"zh_tw" => (album["description"]["zh_tw"].nil? ? "" : album["description"]["zh_tw"])},
|
"zh_tw" => (album["description"]["zh_tw"].nil? ? "" : album["description"]["zh_tw"])},
|
||||||
:rss2_id => album["albumid"])
|
:rss2_id => album["albumid"])
|
||||||
|
category = Category.where(:title => album["category_name"], :module_app_id => module_app).first
|
||||||
newalbum.category_id = category.id
|
newalbum.category_id = category.id
|
||||||
newalbum.save
|
newalbum.save
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,16 +1,85 @@
|
||||||
class SessionsController < ApplicationController
|
class SessionsController < ApplicationController
|
||||||
layout "authentication"
|
layout "authentication"
|
||||||
|
|
||||||
def new
|
def new
|
||||||
if session[:user_id]
|
if session[:user_id]
|
||||||
redirect_to admin_dashboards_path
|
redirect_to admin_dashboards_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
user = User.find_by(user_name: params[:user_name]) rescue nil
|
login_password = params[:password]
|
||||||
if (user && user.authenticate(params[:password]) && user.is_confirmed?.eql?(true))
|
login_uid = params[:user_name]
|
||||||
# if user.is_approved? || user.is_admin?
|
result = false
|
||||||
|
ldap_filter = "(uid=#{login_uid})"
|
||||||
|
|
||||||
|
if login_uid != 'rulingcom'
|
||||||
|
|
||||||
|
NccuLdapConnection.establish
|
||||||
|
|
||||||
|
if ($nccu_ldap_connection.bind rescue false)
|
||||||
|
|
||||||
|
logger.info "=LDAP Binded password ok..."
|
||||||
|
|
||||||
|
result = check_auth_with_ldap(login_uid,login_password)
|
||||||
|
|
||||||
|
resource = User.find_by(user_name: params[:user_name]) rescue nil
|
||||||
|
|
||||||
|
if result && login_password!=''
|
||||||
|
|
||||||
|
logger.info "==LDAP password passed..."
|
||||||
|
# set_flash_message(:notice, :signed_in) if is_navigational_format?
|
||||||
|
|
||||||
|
if (resource.nil?)
|
||||||
|
logger.error "===LDAP passed local block... resource:#{resource.inspect}\n login_uid:#{login_uid}"
|
||||||
|
flash.now.alert = t('devise.failure.ldap_pass_but_account_not_in_orbit')
|
||||||
|
render "new"
|
||||||
|
else
|
||||||
|
logger.info "===ALL passed"
|
||||||
|
session[:user_id] = resource.id
|
||||||
|
session[:login_referer] = nil
|
||||||
|
if params[:referer_url]
|
||||||
|
redirect_to URI.parse(params[:referer_url]).path
|
||||||
|
else
|
||||||
|
redirect_to admin_dashboards_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
elsif !resource.nil?
|
||||||
|
|
||||||
|
if (resource.authenticate(login_password) && resource.is_confirmed?.eql?(true))
|
||||||
|
session[:user_id] = resource.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 = t('devise.failure.invalid')
|
||||||
|
render "new"
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
logger.error "==password LDAP fail..."
|
||||||
|
flash.now.alert = t('devise.failure.ldap_invalid')
|
||||||
|
render "new"
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
logger.error "=LDAP fail..."
|
||||||
|
flash.now.alert = t('devise.failure.ldap_connection_failed')
|
||||||
|
render "new"
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
else #if rulingcom account
|
||||||
|
logger.info "=======Rulingcom account======"
|
||||||
|
|
||||||
|
user = User.find_by(user_name: login_uid) rescue nil
|
||||||
|
if (user && user.authenticate(login_password) && user.is_confirmed?.eql?(true))
|
||||||
session[:user_id] = user.id
|
session[:user_id] = user.id
|
||||||
session[:login_referer] = nil
|
session[:login_referer] = nil
|
||||||
if params[:referer_url]
|
if params[:referer_url]
|
||||||
|
@ -18,14 +87,88 @@ class SessionsController < ApplicationController
|
||||||
else
|
else
|
||||||
redirect_to admin_dashboards_path
|
redirect_to admin_dashboards_path
|
||||||
end
|
end
|
||||||
# else
|
else
|
||||||
# flash.now.alert = "User not approved."
|
flash.now.alert = t('devise.failure.invalid')
|
||||||
# render "new"
|
render "new"
|
||||||
# end
|
end
|
||||||
else
|
|
||||||
flash.now.alert = "Invalid username or password"
|
|
||||||
render "new"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
logger.info "=======End Debugging======"
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def google_result
|
||||||
|
@code = params[:code]
|
||||||
|
if @code.nil?
|
||||||
|
redirect_to root_url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def google_callback
|
||||||
|
error = params[:error] rescue nil
|
||||||
|
if error == "access_denied"
|
||||||
|
redirect_to auth_failure_path and return
|
||||||
|
end
|
||||||
|
auth = env["omniauth.auth"]
|
||||||
|
user = Google.find_by("google_uid" => auth.uid).user rescue nil
|
||||||
|
if user.nil? && current_user.nil?
|
||||||
|
user_connected = false
|
||||||
|
else
|
||||||
|
user_connected = true
|
||||||
|
if user.nil? && !current_user.nil?
|
||||||
|
connection_successful = connect_account(auth)
|
||||||
|
else
|
||||||
|
if login_user(user,auth)
|
||||||
|
if params[:referer_url]
|
||||||
|
redirect_to URI.parse(params[:referer_url]).path and return
|
||||||
|
else
|
||||||
|
redirect_to admin_dashboards_path and return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if user_connected && connection_successful
|
||||||
|
code = 1
|
||||||
|
elsif user_connected && !connection_successful
|
||||||
|
code = 2
|
||||||
|
else !user_connected && !connection_successful
|
||||||
|
code = 3
|
||||||
|
end
|
||||||
|
redirect_to auth_google_result_path(:code => code)
|
||||||
|
end
|
||||||
|
|
||||||
|
def google_remove
|
||||||
|
current_user.google.destroy rescue ""
|
||||||
|
redirect_to admin_member_path(current_user.member_profile.to_param) and return
|
||||||
|
end
|
||||||
|
|
||||||
|
def google_faliure
|
||||||
|
@code = 2
|
||||||
|
render "google_result"
|
||||||
|
end
|
||||||
|
|
||||||
|
def connect_account(auth)
|
||||||
|
if !current_user.nil?
|
||||||
|
google = Google.new
|
||||||
|
google.google_uid = auth.uid
|
||||||
|
google.token = auth.credentials.token
|
||||||
|
google.connected = true
|
||||||
|
google.save
|
||||||
|
current_user.google = google
|
||||||
|
current_user.save
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def login_user(user,auth)
|
||||||
|
if user.google.token != auth.credentials.token
|
||||||
|
user.google.token = auth.credentials.token
|
||||||
|
user.google.save
|
||||||
|
end
|
||||||
|
session[:user_id] = user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
def google_result
|
def google_result
|
||||||
|
@ -106,4 +249,12 @@ class SessionsController < ApplicationController
|
||||||
session[:user_id] = nil
|
session[:user_id] = nil
|
||||||
redirect_to root_url
|
redirect_to root_url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def check_auth_with_ldap(login_uid,login_password)
|
||||||
|
ldap_filter = "(uid=#{login_uid})"
|
||||||
|
$nccu_ldap_connection.bind_as(:base => NccuLdapConnection::BASE,:filter => ldap_filter,:password=> login_password) rescue false
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
LDAP_CONFIG = YAML.load_file("#{Rails.root}/config/ldap.yml")[Rails.env]
|
|
@ -0,0 +1,16 @@
|
||||||
|
#encoding: utf-8
|
||||||
|
# require 'mysql2'
|
||||||
|
|
||||||
|
$nccu_ldap_connection
|
||||||
|
|
||||||
|
module NccuLdapConnection
|
||||||
|
BASE = 'ou=People,dc=nccu,dc=edu,dc=tw'
|
||||||
|
|
||||||
|
def self.establish
|
||||||
|
$nccu_ldap_connection = Net::LDAP.new
|
||||||
|
$nccu_ldap_connection.port =LDAP_CONFIG["port"]
|
||||||
|
$nccu_ldap_connection.host = LDAP_CONFIG["host"]
|
||||||
|
$nccu_ldap_connection.authenticate(LDAP_CONFIG["authenticate_info"],LDAP_CONFIG["authenticate_pwd"])
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,12 @@
|
||||||
|
defaults: &defaults
|
||||||
|
authenticate_info: 'cn=uccn,ou=profile,dc=nccu,dc=edu,dc=tw'
|
||||||
|
authenticate_pwd: 'nccu2ucc'
|
||||||
|
|
||||||
|
development:
|
||||||
|
<<: *defaults
|
||||||
|
host: '140.119.166.23'
|
||||||
|
port: 389
|
||||||
|
production:
|
||||||
|
<<: *defaults
|
||||||
|
host: '140.119.166.23'
|
||||||
|
port: 389
|
Loading…
Reference in New Issue