From 8fb3b408b489a4c9e6eaf6548ca8863d27973d00 Mon Sep 17 00:00:00 2001 From: Spen Date: Fri, 20 Dec 2013 11:08:16 +0800 Subject: [PATCH] ntu coph sso --- app/controllers/sessions_controller.rb | 40 ++++++++++++++ app/views/devise/sessions/new.html.erb | 73 ++++++++++++++------------ app/views/layouts/_right_menu.html.erb | 7 ++- config/routes.rb | 5 ++ 4 files changed, 89 insertions(+), 36 deletions(-) create mode 100644 app/controllers/sessions_controller.rb diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 00000000..f5df51b5 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,40 @@ +# encoding: utf-8 + +class SessionsController < Devise::SessionsController + prepend_before_filter :require_no_authentication, :only => [ :new, :create ] + + + def create + @site = Site.first + + private_key = OpenSSL::PKey::RSA.new(@site.private_key) + wresult = private_key.private_decrypt(request.params['wresult']) + + @ids = wresult.split("@") + + login_uid = @ids[0] + + resource = User.first(conditions:{user_id: login_uid}) + + if !resource.blank? + resource_name = resource.class.to_s.downcase + sign_in(resource_name, resource) + session[:user_id_type] = "myntucoph" + redirect_to after_sign_in_path_for(resource) + else + flash[:error] = "很抱歉,您無此權限或帳號登入本站,請洽本站管理員
Sorry, you don't have the account or authority to login. Please contact the website administrator." + redirect_to :root + end + end + + def destroy + @user_id_type = session[:user_id_type] + sign_out + if @user_id_type == "myntucoph" + redirect_to "https://adfs.ntu.edu.tw/adfs/ls/?wa=wsignout1.0&wreply=https://cophlogin.ntu.edu.tw" + else + redirect_to root_path + end + end + +end \ No newline at end of file diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 1b77fce2..03150e51 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,59 +1,62 @@ -
+ + -
\ No newline at end of file diff --git a/app/views/layouts/_right_menu.html.erb b/app/views/layouts/_right_menu.html.erb index b4efb307..bcda6caf 100644 --- a/app/views/layouts/_right_menu.html.erb +++ b/app/views/layouts/_right_menu.html.erb @@ -56,6 +56,11 @@ <% end %> - \ No newline at end of file + diff --git a/config/routes.rb b/config/routes.rb index b2164716..626594e6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,11 @@ Orbit::Application.routes.draw do resources :passwords, :except => [:index, :show, :destroy] match "/users_passwd" => "desktop/registrations#update", :as => :users_passwd, :via => :put end + + devise_scope :user do + get 'user_login' => 'sessions#create' + match 'user_logout' => 'sessions#destroy' + end mount Resque::Server, :at => "/admin/resque" mount Rack::GridFS::Endpoint.new(:db => Mongoid.database,:lookup=>:path), :at => "gridfs"