To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / auth_sources_controller.rb @ 1298:4f746d8966dd
History | View | Annotate | Download (2.8 KB)
| 1 | 909:cbb26bc654de | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 1295:622f24f53b42 | Chris | # Copyright (C) 2006-2013 Jean-Philippe Lang
|
| 3 | 0:513646585e45 | Chris | #
|
| 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 | 909:cbb26bc654de | Chris | #
|
| 9 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | #
|
| 14 | 0:513646585e45 | Chris | # 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.
|
||
| 17 | |||
| 18 | class AuthSourcesController < ApplicationController |
||
| 19 | layout 'admin'
|
||
| 20 | 1115:433d4f72a19b | Chris | menu_item :ldap_authentication
|
| 21 | 909:cbb26bc654de | Chris | |
| 22 | 0:513646585e45 | Chris | before_filter :require_admin
|
| 23 | 1295:622f24f53b42 | Chris | before_filter :find_auth_source, :only => [:edit, :update, :test_connection, :destroy] |
| 24 | 0:513646585e45 | Chris | |
| 25 | def index |
||
| 26 | 1295:622f24f53b42 | Chris | @auth_source_pages, @auth_sources = paginate AuthSource, :per_page => 25 |
| 27 | 0:513646585e45 | Chris | end
|
| 28 | |||
| 29 | def new |
||
| 30 | 1115:433d4f72a19b | Chris | klass_name = params[:type] || 'AuthSourceLdap' |
| 31 | @auth_source = AuthSource.new_subclass_instance(klass_name, params[:auth_source]) |
||
| 32 | 1295:622f24f53b42 | Chris | render_404 unless @auth_source |
| 33 | 0:513646585e45 | Chris | end
|
| 34 | |||
| 35 | def create |
||
| 36 | 1115:433d4f72a19b | Chris | @auth_source = AuthSource.new_subclass_instance(params[:type], params[:auth_source]) |
| 37 | 0:513646585e45 | Chris | if @auth_source.save |
| 38 | flash[:notice] = l(:notice_successful_create) |
||
| 39 | 1295:622f24f53b42 | Chris | redirect_to auth_sources_path |
| 40 | 0:513646585e45 | Chris | else
|
| 41 | 1115:433d4f72a19b | Chris | render :action => 'new' |
| 42 | 0:513646585e45 | Chris | end
|
| 43 | end
|
||
| 44 | |||
| 45 | def edit |
||
| 46 | end
|
||
| 47 | |||
| 48 | def update |
||
| 49 | if @auth_source.update_attributes(params[:auth_source]) |
||
| 50 | flash[:notice] = l(:notice_successful_update) |
||
| 51 | 1295:622f24f53b42 | Chris | redirect_to auth_sources_path |
| 52 | 0:513646585e45 | Chris | else
|
| 53 | 1115:433d4f72a19b | Chris | render :action => 'edit' |
| 54 | 0:513646585e45 | Chris | end
|
| 55 | end
|
||
| 56 | 909:cbb26bc654de | Chris | |
| 57 | 0:513646585e45 | Chris | def test_connection |
| 58 | begin
|
||
| 59 | 1115:433d4f72a19b | Chris | @auth_source.test_connection
|
| 60 | 0:513646585e45 | Chris | flash[:notice] = l(:notice_successful_connection) |
| 61 | 1115:433d4f72a19b | Chris | rescue Exception => e |
| 62 | flash[:error] = l(:error_unable_to_connect, e.message) |
||
| 63 | 0:513646585e45 | Chris | end
|
| 64 | 1295:622f24f53b42 | Chris | redirect_to auth_sources_path |
| 65 | 0:513646585e45 | Chris | end
|
| 66 | |||
| 67 | def destroy |
||
| 68 | 1295:622f24f53b42 | Chris | unless @auth_source.users.exists? |
| 69 | 0:513646585e45 | Chris | @auth_source.destroy
|
| 70 | flash[:notice] = l(:notice_successful_delete) |
||
| 71 | end
|
||
| 72 | 1295:622f24f53b42 | Chris | redirect_to auth_sources_path |
| 73 | end
|
||
| 74 | |||
| 75 | def autocomplete_for_new_user |
||
| 76 | results = AuthSource.search(params[:term]) |
||
| 77 | |||
| 78 | render :json => results.map {|result| {
|
||
| 79 | 'value' => result[:login], |
||
| 80 | 'label' => "#{result[:login]} (#{result[:firstname]} #{result[:lastname]})", |
||
| 81 | 'login' => result[:login].to_s, |
||
| 82 | 'firstname' => result[:firstname].to_s, |
||
| 83 | 'lastname' => result[:lastname].to_s, |
||
| 84 | 'mail' => result[:mail].to_s, |
||
| 85 | 'auth_source_id' => result[:auth_source_id].to_s |
||
| 86 | }} |
||
| 87 | end
|
||
| 88 | |||
| 89 | private |
||
| 90 | |||
| 91 | def find_auth_source |
||
| 92 | @auth_source = AuthSource.find(params[:id]) |
||
| 93 | rescue ActiveRecord::RecordNotFound |
||
| 94 | render_404 |
||
| 95 | 0:513646585e45 | Chris | end
|
| 96 | end |