;]
[askyou.git] / app / controllers / auth_sources_controller.rb
blob872ae1856bca7db11b74da1cdc57e94907ce0024
1 # redMine - project management software
2 # Copyright (C) 2006  Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 class AuthSourcesController < ApplicationController
19   layout 'admin'
20   
21   before_filter :require_admin
23   # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
24   verify :method => :post, :only => [ :destroy, :create, :update ],
25          :redirect_to => { :template => :index }
27   def index
28     @auth_source_pages, @auth_sources = paginate auth_source_class.name.tableize, :per_page => 10
29     render "auth_sources/index"
30   end
32   def new
33     @auth_source = auth_source_class.new
34     render 'auth_sources/new'
35   end
37   def create
38     @auth_source = auth_source_class.new(params[:auth_source])
39     if @auth_source.save
40       flash[:notice] = l(:notice_successful_create)
41       redirect_to :action => 'index'
42     else
43       render 'auth_sources/new'
44     end
45   end
47   def edit
48     @auth_source = AuthSource.find(params[:id])
49     render 'auth_sources/edit'
50   end
52   def update
53     @auth_source = AuthSource.find(params[:id])
54     if @auth_source.update_attributes(params[:auth_source])
55       flash[:notice] = l(:notice_successful_update)
56       redirect_to :action => 'index'
57     else
58       render 'auth_sources/edit'
59     end
60   end
61   
62   def test_connection
63     @auth_method = AuthSource.find(params[:id])
64     begin
65       @auth_method.test_connection
66       flash[:notice] = l(:notice_successful_connection)
67     rescue => text
68       flash[:error] = l(:error_unable_to_connect, text.message)
69     end
70     redirect_to :action => 'index'
71   end
73   def destroy
74     @auth_source = AuthSource.find(params[:id])
75     unless @auth_source.users.find(:first)
76       @auth_source.destroy
77       flash[:notice] = l(:notice_successful_delete)
78     end
79     redirect_to :action => 'index'
80   end
82   protected
84   def auth_source_class
85     AuthSource
86   end
87 end