To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / auth_sources_controller.rb @ 1533:59e13100ea95

History | View | Annotate | Download (2.8 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2014  Jean-Philippe Lang
3
#
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.
17

    
18
class AuthSourcesController < ApplicationController
19
  layout 'admin'
20
  menu_item :ldap_authentication
21

    
22
  before_filter :require_admin
23
  before_filter :find_auth_source, :only => [:edit, :update, :test_connection, :destroy]
24

    
25
  def index
26
    @auth_source_pages, @auth_sources = paginate AuthSource, :per_page => 25
27
  end
28

    
29
  def new
30
    klass_name = params[:type] || 'AuthSourceLdap'
31
    @auth_source = AuthSource.new_subclass_instance(klass_name, params[:auth_source])
32
    render_404 unless @auth_source
33
  end
34

    
35
  def create
36
    @auth_source = AuthSource.new_subclass_instance(params[:type], params[:auth_source])
37
    if @auth_source.save
38
      flash[:notice] = l(:notice_successful_create)
39
      redirect_to auth_sources_path
40
    else
41
      render :action => 'new'
42
    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
      redirect_to auth_sources_path
52
    else
53
      render :action => 'edit'
54
    end
55
  end
56

    
57
  def test_connection
58
    begin
59
      @auth_source.test_connection
60
      flash[:notice] = l(:notice_successful_connection)
61
    rescue Exception => e
62
      flash[:error] = l(:error_unable_to_connect, e.message)
63
    end
64
    redirect_to auth_sources_path
65
  end
66

    
67
  def destroy
68
    unless @auth_source.users.exists?
69
      @auth_source.destroy
70
      flash[:notice] = l(:notice_successful_delete)
71
    end
72
    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
  end
96
end