forked from saurabh/orbit4-5
ydu
This commit is contained in:
parent
4b302c8b2a
commit
bd1ce335a3
2
Gemfile
2
Gemfile
|
@ -4,6 +4,8 @@ source 'https://rubygems.org'
|
|||
gem 'rails', '~> 4.1.0'
|
||||
gem 'sanitize'
|
||||
|
||||
gem 'savon', '~> 2.2.0'
|
||||
|
||||
#assets and templates
|
||||
gem 'sass-rails', '~> 4.0.2'
|
||||
gem 'uglifier', '>= 1.3.0'
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
class SessionsController < ApplicationController
|
||||
layout "authentication"
|
||||
|
||||
require 'savon'
|
||||
|
||||
def new
|
||||
if session[:user_id]
|
||||
redirect_to admin_dashboards_path
|
||||
|
@ -8,8 +10,16 @@ class SessionsController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
user = User.find_by(user_name: params[:user_name]) rescue nil
|
||||
if (user && user.authenticate(params[:password]) && user.is_confirmed?.eql?(true))
|
||||
|
||||
@SYS_USER = "rulingcom"
|
||||
@SYS_PASS = "pxm87912tkx"
|
||||
@LDAP_USER = params[:user_name]
|
||||
@LDAP_PASS = params[:password]
|
||||
|
||||
if @LDAP_USER == 'rulingcom'
|
||||
|
||||
user = User.find_by(user_name: @LDAP_USER) rescue nil
|
||||
if (user && user.authenticate(@LDAP_PASS) && user.is_confirmed?.eql?(true))
|
||||
if user.is_approved? || user.is_admin?
|
||||
session[:user_id] = user.id
|
||||
session[:login_referer] = nil
|
||||
|
@ -26,6 +36,58 @@ class SessionsController < ApplicationController
|
|||
flash.now.alert = "Invalid username or password"
|
||||
render "new"
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
errors = ["很抱歉,您無此權限或帳號登入本站,請洽本站管理員", "Sorry, you don't have the account or authority to login. Please contact the website administrator."]
|
||||
|
||||
client = Savon.client(wsdl: 'http://ap.ydu.edu.tw/LDAP_WS/RulingcomDataService.asmx?wsdl',filters: [:SYS_USER, :SYS_PASS, :LDAP_USER, :LDAP_PASS])
|
||||
|
||||
client.operations
|
||||
|
||||
response = client.call(:login_chk, message: {
|
||||
"SYS_USER" => @SYS_USER,
|
||||
"SYS_PASS" => @SYS_PASS,
|
||||
"LDAP_USER" => @LDAP_USER,
|
||||
"LDAP_PASS" => @LDAP_PASS,
|
||||
"User_IP" => request.remote_ip
|
||||
})
|
||||
|
||||
@datas = response.body[:login_chk_response][:login_chk_result][:string]
|
||||
|
||||
if !@datas[0].blank? and ( @datas[0] == 'P' or @datas[0] == 'U' ) #使用者帳號回傳P,單位帳號回傳U
|
||||
|
||||
user = User.find_by(user_name: @LDAP_USER) rescue nil
|
||||
|
||||
if !user.blank?
|
||||
|
||||
if user.is_approved? || user.is_admin?
|
||||
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 approved."
|
||||
render "new"
|
||||
end
|
||||
|
||||
else #認證通過無帳號不通過
|
||||
|
||||
flash.now.alert = errors.join("<br/>").html_safe
|
||||
render "new"
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
flash.now.alert = errors.join("<br/>").html_safe
|
||||
render "new"
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
|
|
@ -24,8 +24,8 @@ class User
|
|||
has_one :desktop, :dependent => :destroy
|
||||
|
||||
|
||||
validates :user_name, uniqueness: true
|
||||
validates :password, :on => :create, length: {:in => 8..20}
|
||||
validates :user_name, uniqueness: true, length: {:minimum => 2, :maximum => 50, :message => I18n.t("users.user_id_length") }
|
||||
validates :password, presence: true, :on => :create, length: {:in => 8..20}
|
||||
|
||||
#Add getter and setter for email virtual field
|
||||
attr_accessor :email, :first_name, :last_name
|
||||
|
|
|
@ -659,9 +659,9 @@ en:
|
|||
sex: Gender
|
||||
gender: Gender
|
||||
user_id: User Account
|
||||
user_id_note: Should be more than 3 characters and less than 50 characters
|
||||
user_id_note: Should be more than 2 characters and less than 50 characters
|
||||
user_id_not_null: User account cannot be null
|
||||
user_id_length: User account should be more than 3 characters
|
||||
user_id_length: User account should be more than 2 characters
|
||||
user_id_error: Someone already use that user account
|
||||
user_basic_id_form: Account Info.
|
||||
user_basic_data: Personal Profile
|
||||
|
|
|
@ -650,9 +650,9 @@ zh_tw:
|
|||
sex: 性別
|
||||
gender: 性別
|
||||
user_id: 使用者帳號
|
||||
user_id_note: 需介於3個字元至50個字元之間
|
||||
user_id_note: 需介於2個字元至50個字元之間
|
||||
user_id_not_null: 使用者帳號不能是空值
|
||||
user_id_length: 使用者帳號至少需要3個字元
|
||||
user_id_length: 使用者帳號至少需要2個字元
|
||||
user_id_error: 該使用者帳號已被使用
|
||||
user_basic_id_form: 帳號資料
|
||||
user_basic_data: 個人資料
|
||||
|
|
Loading…
Reference in New Issue