##// END OF EJS Templates
Added a named route for the home page....
Jean-Philippe Lang -
r749:650888c73b73
parent child
Show More
@@ -1,153 +1,153
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class AccountController < ApplicationController
18 class AccountController < ApplicationController
19 layout 'base'
19 layout 'base'
20 helper :custom_fields
20 helper :custom_fields
21 include CustomFieldsHelper
21 include CustomFieldsHelper
22
22
23 # prevents login action to be filtered by check_if_login_required application scope filter
23 # prevents login action to be filtered by check_if_login_required application scope filter
24 skip_before_filter :check_if_login_required, :only => [:login, :lost_password, :register]
24 skip_before_filter :check_if_login_required, :only => [:login, :lost_password, :register]
25
25
26 # Show user's account
26 # Show user's account
27 def show
27 def show
28 @user = User.find_active(params[:id])
28 @user = User.find_active(params[:id])
29 @custom_values = @user.custom_values.find(:all, :include => :custom_field)
29 @custom_values = @user.custom_values.find(:all, :include => :custom_field)
30
30
31 # show only public projects and private projects that the logged in user is also a member of
31 # show only public projects and private projects that the logged in user is also a member of
32 @memberships = @user.memberships.select do |membership|
32 @memberships = @user.memberships.select do |membership|
33 membership.project.is_public? || (User.current.role_for_project(membership.project))
33 membership.project.is_public? || (User.current.role_for_project(membership.project))
34 end
34 end
35 rescue ActiveRecord::RecordNotFound
35 rescue ActiveRecord::RecordNotFound
36 render_404
36 render_404
37 end
37 end
38
38
39 # Login request and validation
39 # Login request and validation
40 def login
40 def login
41 if request.get?
41 if request.get?
42 # Logout user
42 # Logout user
43 self.logged_user = nil
43 self.logged_user = nil
44 else
44 else
45 # Authenticate user
45 # Authenticate user
46 user = User.try_to_login(params[:login], params[:password])
46 user = User.try_to_login(params[:login], params[:password])
47 if user
47 if user
48 self.logged_user = user
48 self.logged_user = user
49 # generate a key and set cookie if autologin
49 # generate a key and set cookie if autologin
50 if params[:autologin] && Setting.autologin?
50 if params[:autologin] && Setting.autologin?
51 token = Token.create(:user => user, :action => 'autologin')
51 token = Token.create(:user => user, :action => 'autologin')
52 cookies[:autologin] = { :value => token.value, :expires => 1.year.from_now }
52 cookies[:autologin] = { :value => token.value, :expires => 1.year.from_now }
53 end
53 end
54 redirect_back_or_default :controller => 'my', :action => 'page'
54 redirect_back_or_default :controller => 'my', :action => 'page'
55 else
55 else
56 flash.now[:error] = l(:notice_account_invalid_creditentials)
56 flash.now[:error] = l(:notice_account_invalid_creditentials)
57 end
57 end
58 end
58 end
59 end
59 end
60
60
61 # Log out current user and redirect to welcome page
61 # Log out current user and redirect to welcome page
62 def logout
62 def logout
63 cookies.delete :autologin
63 cookies.delete :autologin
64 Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) if User.current.logged?
64 Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) if User.current.logged?
65 self.logged_user = nil
65 self.logged_user = nil
66 redirect_to :controller => 'welcome'
66 redirect_to home_url
67 end
67 end
68
68
69 # Enable user to choose a new password
69 # Enable user to choose a new password
70 def lost_password
70 def lost_password
71 redirect_to :controller => 'welcome' and return unless Setting.lost_password?
71 redirect_to(home_url) && return unless Setting.lost_password?
72 if params[:token]
72 if params[:token]
73 @token = Token.find_by_action_and_value("recovery", params[:token])
73 @token = Token.find_by_action_and_value("recovery", params[:token])
74 redirect_to :controller => 'welcome' and return unless @token and !@token.expired?
74 redirect_to(home_url) && return unless @token and !@token.expired?
75 @user = @token.user
75 @user = @token.user
76 if request.post?
76 if request.post?
77 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
77 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
78 if @user.save
78 if @user.save
79 @token.destroy
79 @token.destroy
80 flash[:notice] = l(:notice_account_password_updated)
80 flash[:notice] = l(:notice_account_password_updated)
81 redirect_to :action => 'login'
81 redirect_to :action => 'login'
82 return
82 return
83 end
83 end
84 end
84 end
85 render :template => "account/password_recovery"
85 render :template => "account/password_recovery"
86 return
86 return
87 else
87 else
88 if request.post?
88 if request.post?
89 user = User.find_by_mail(params[:mail])
89 user = User.find_by_mail(params[:mail])
90 # user not found in db
90 # user not found in db
91 flash.now[:error] = l(:notice_account_unknown_email) and return unless user
91 flash.now[:error] = l(:notice_account_unknown_email) and return unless user
92 # user uses an external authentification
92 # user uses an external authentification
93 flash.now[:error] = l(:notice_can_t_change_password) and return if user.auth_source_id
93 flash.now[:error] = l(:notice_can_t_change_password) and return if user.auth_source_id
94 # create a new token for password recovery
94 # create a new token for password recovery
95 token = Token.new(:user => user, :action => "recovery")
95 token = Token.new(:user => user, :action => "recovery")
96 if token.save
96 if token.save
97 Mailer.deliver_lost_password(token)
97 Mailer.deliver_lost_password(token)
98 flash[:notice] = l(:notice_account_lost_email_sent)
98 flash[:notice] = l(:notice_account_lost_email_sent)
99 redirect_to :action => 'login'
99 redirect_to :action => 'login'
100 return
100 return
101 end
101 end
102 end
102 end
103 end
103 end
104 end
104 end
105
105
106 # User self-registration
106 # User self-registration
107 def register
107 def register
108 redirect_to :controller => 'welcome' and return unless Setting.self_registration?
108 redirect_to(home_url) && return unless Setting.self_registration?
109 if params[:token]
109 if params[:token]
110 token = Token.find_by_action_and_value("register", params[:token])
110 token = Token.find_by_action_and_value("register", params[:token])
111 redirect_to :controller => 'welcome' and return unless token and !token.expired?
111 redirect_to(home_url) && return unless token and !token.expired?
112 user = token.user
112 user = token.user
113 redirect_to :controller => 'welcome' and return unless user.status == User::STATUS_REGISTERED
113 redirect_to(home_url) && return unless user.status == User::STATUS_REGISTERED
114 user.status = User::STATUS_ACTIVE
114 user.status = User::STATUS_ACTIVE
115 if user.save
115 if user.save
116 token.destroy
116 token.destroy
117 flash[:notice] = l(:notice_account_activated)
117 flash[:notice] = l(:notice_account_activated)
118 redirect_to :action => 'login'
118 redirect_to :action => 'login'
119 return
119 return
120 end
120 end
121 else
121 else
122 if request.get?
122 if request.get?
123 @user = User.new(:language => Setting.default_language)
123 @user = User.new(:language => Setting.default_language)
124 @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
124 @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
125 else
125 else
126 @user = User.new(params[:user])
126 @user = User.new(params[:user])
127 @user.admin = false
127 @user.admin = false
128 @user.login = params[:user][:login]
128 @user.login = params[:user][:login]
129 @user.status = User::STATUS_REGISTERED
129 @user.status = User::STATUS_REGISTERED
130 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
130 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
131 @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
131 @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
132 @user.custom_values = @custom_values
132 @user.custom_values = @custom_values
133 token = Token.new(:user => @user, :action => "register")
133 token = Token.new(:user => @user, :action => "register")
134 if @user.save and token.save
134 if @user.save and token.save
135 Mailer.deliver_register(token)
135 Mailer.deliver_register(token)
136 flash[:notice] = l(:notice_account_register_done)
136 flash[:notice] = l(:notice_account_register_done)
137 redirect_to :controller => 'account', :action => 'login'
137 redirect_to :controller => 'account', :action => 'login'
138 end
138 end
139 end
139 end
140 end
140 end
141 end
141 end
142
142
143 private
143 private
144 def logged_user=(user)
144 def logged_user=(user)
145 if user && user.is_a?(User)
145 if user && user.is_a?(User)
146 User.current = user
146 User.current = user
147 session[:user_id] = user.id
147 session[:user_id] = user.id
148 else
148 else
149 User.current = User.anonymous
149 User.current = User.anonymous
150 session[:user_id] = nil
150 session[:user_id] = nil
151 end
151 end
152 end
152 end
153 end
153 end
@@ -1,80 +1,80
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3 <head>
3 <head>
4 <title><%=h html_title %></title>
4 <title><%=h html_title %></title>
5 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6 <meta name="description" content="<%= Redmine::Info.app_name %>" />
6 <meta name="description" content="<%= Redmine::Info.app_name %>" />
7 <meta name="keywords" content="issue,bug,tracker" />
7 <meta name="keywords" content="issue,bug,tracker" />
8 <%= stylesheet_link_tag "application" %>
8 <%= stylesheet_link_tag "application" %>
9 <%= stylesheet_link_tag "print", :media => "print" %>
9 <%= stylesheet_link_tag "print", :media => "print" %>
10 <%= javascript_include_tag :defaults %>
10 <%= javascript_include_tag :defaults %>
11 <%= stylesheet_link_tag 'jstoolbar' %>
11 <%= stylesheet_link_tag 'jstoolbar' %>
12 <!--[if IE]>
12 <!--[if IE]>
13 <style type="text/css">
13 <style type="text/css">
14 * html body{ width: expression( document.documentElement.clientWidth < 900 ? '900px' : '100%' ); }
14 * html body{ width: expression( document.documentElement.clientWidth < 900 ? '900px' : '100%' ); }
15 body {behavior: url(<%= stylesheet_path "csshover.htc" %>);}
15 body {behavior: url(<%= stylesheet_path "csshover.htc" %>);}
16 </style>
16 </style>
17 <![endif]-->
17 <![endif]-->
18
18
19 <!-- page specific tags --><%= yield :header_tags %>
19 <!-- page specific tags --><%= yield :header_tags %>
20 </head>
20 </head>
21 <body>
21 <body>
22 <div id="top-menu">
22 <div id="top-menu">
23 <div id="account">
23 <div id="account">
24 <% if User.current.logged? %>
24 <% if User.current.logged? %>
25 <%=l(:label_logged_as)%> <%= User.current.login %> -
25 <%=l(:label_logged_as)%> <%= User.current.login %> -
26 <%= link_to l(:label_my_account), { :controller => 'my', :action => 'account' } %>
26 <%= link_to l(:label_my_account), { :controller => 'my', :action => 'account' } %>
27 <%= link_to l(:label_logout), { :controller => 'account', :action => 'logout' } %>
27 <%= link_to l(:label_logout), { :controller => 'account', :action => 'logout' } %>
28 <% else %>
28 <% else %>
29 <%= link_to l(:label_login), { :controller => 'account', :action => 'login' } %>
29 <%= link_to l(:label_login), { :controller => 'account', :action => 'login' } %>
30 <%= link_to(l(:label_register), :controller => 'account',:action => 'register') if Setting.self_registration? %>
30 <%= link_to(l(:label_register), :controller => 'account',:action => 'register') if Setting.self_registration? %>
31 <% end %>
31 <% end %>
32 </div>
32 </div>
33 <%= link_to l(:label_home), { :controller => 'welcome' } %>
33 <%= link_to l(:label_home), home_url %>
34 <%= link_to l(:label_my_page), { :controller => 'my', :action => 'page'} if User.current.logged? %>
34 <%= link_to l(:label_my_page), { :controller => 'my', :action => 'page'} if User.current.logged? %>
35 <%= link_to l(:label_project_plural), { :controller => 'projects' } %>
35 <%= link_to l(:label_project_plural), { :controller => 'projects' } %>
36 <%= link_to l(:label_administration), { :controller => 'admin' } if User.current.admin? %>
36 <%= link_to l(:label_administration), { :controller => 'admin' } if User.current.admin? %>
37 </div>
37 </div>
38
38
39 <div id="header">
39 <div id="header">
40 <div id="quick-search">
40 <div id="quick-search">
41 <% form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %>
41 <% form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %>
42 <%= link_to l(:label_search), :controller => 'search', :action => 'index', :id => @project %>: <%= text_field_tag 'q', @question, :size => 20, :class => 'small' %>
42 <%= link_to l(:label_search), :controller => 'search', :action => 'index', :id => @project %>: <%= text_field_tag 'q', @question, :size => 20, :class => 'small' %>
43 <% end %>
43 <% end %>
44 <%= render :partial => 'layouts/project_selector' if User.current.memberships.any? %>
44 <%= render :partial => 'layouts/project_selector' if User.current.memberships.any? %>
45 </div>
45 </div>
46
46
47 <h1><%= h(@project ? @project.name : Setting.app_title) %></h1>
47 <h1><%= h(@project ? @project.name : Setting.app_title) %></h1>
48
48
49 <div id="main-menu">
49 <div id="main-menu">
50 <ul>
50 <ul>
51 <% Redmine::MenuManager.allowed_items(:project_menu, User.current, @project).each do |item| %>
51 <% Redmine::MenuManager.allowed_items(:project_menu, User.current, @project).each do |item| %>
52 <% unless item.condition && !item.condition.call(@project) %>
52 <% unless item.condition && !item.condition.call(@project) %>
53 <li><%= link_to l(item.name), {item.param => @project}.merge(item.url) %></li>
53 <li><%= link_to l(item.name), {item.param => @project}.merge(item.url) %></li>
54 <% end %>
54 <% end %>
55 <% end if @project && !@project.new_record? %>
55 <% end if @project && !@project.new_record? %>
56 </ul>
56 </ul>
57 </div>
57 </div>
58 </div>
58 </div>
59
59
60 <%= tag('div', {:id => 'main', :class => (has_content?(:sidebar) ? '' : 'nosidebar')}, true) %>
60 <%= tag('div', {:id => 'main', :class => (has_content?(:sidebar) ? '' : 'nosidebar')}, true) %>
61 <div id="sidebar">
61 <div id="sidebar">
62 <%= yield :sidebar %>
62 <%= yield :sidebar %>
63 </div>
63 </div>
64
64
65 <div id="content">
65 <div id="content">
66 <div id="flash">
66 <div id="flash">
67 <%= content_tag('div', flash[:error], :class => 'error') if flash[:error] %>
67 <%= content_tag('div', flash[:error], :class => 'error') if flash[:error] %>
68 <%= content_tag('div', flash[:notice], :class => 'notice') if flash[:notice] %>
68 <%= content_tag('div', flash[:notice], :class => 'notice') if flash[:notice] %>
69 </div>
69 </div>
70 <%= yield %>
70 <%= yield %>
71 </div>
71 </div>
72 </div>
72 </div>
73
73
74 <div id="ajax-indicator" style="display:none;"><span><%= l(:label_loading) %></span></div>
74 <div id="ajax-indicator" style="display:none;"><span><%= l(:label_loading) %></span></div>
75
75
76 <div id="footer">
76 <div id="footer">
77 <%= link_to Redmine::Info.app_name, Redmine::Info.url %> <%= Redmine::VERSION %> &copy 2006-2007 Jean-Philippe Lang
77 <%= link_to Redmine::Info.app_name, Redmine::Info.url %> <%= Redmine::VERSION %> &copy 2006-2007 Jean-Philippe Lang
78 </div>
78 </div>
79 </body>
79 </body>
80 </html>
80 </html>
@@ -1,29 +1,27
1 ActionController::Routing::Routes.draw do |map|
1 ActionController::Routing::Routes.draw do |map|
2 # Add your own custom routes here.
2 # Add your own custom routes here.
3 # The priority is based upon order of creation: first created -> highest priority.
3 # The priority is based upon order of creation: first created -> highest priority.
4
4
5 # Here's a sample route:
5 # Here's a sample route:
6 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
6 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
7 # Keep in mind you can assign values other than :controller and :action
7 # Keep in mind you can assign values other than :controller and :action
8
8
9 # You can have the root of your site routed by hooking up ''
9 map.home '', :controller => 'welcome'
10 # -- just remember to delete public/index.html.
11 map.connect '', :controller => "welcome"
12
10
13 map.connect 'wiki/:id/:page/:action', :controller => 'wiki', :page => nil
11 map.connect 'wiki/:id/:page/:action', :controller => 'wiki', :page => nil
14 map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
12 map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
15 map.connect 'help/:ctrl/:page', :controller => 'help'
13 map.connect 'help/:ctrl/:page', :controller => 'help'
16 #map.connect ':controller/:action/:id/:sort_key/:sort_order'
14 #map.connect ':controller/:action/:id/:sort_key/:sort_order'
17
15
18 map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations'
16 map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations'
19 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
17 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
20 map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
18 map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
21
19
22 # Allow downloading Web Service WSDL as a file with an extension
20 # Allow downloading Web Service WSDL as a file with an extension
23 # instead of a file named 'wsdl'
21 # instead of a file named 'wsdl'
24 map.connect ':controller/service.wsdl', :action => 'wsdl'
22 map.connect ':controller/service.wsdl', :action => 'wsdl'
25
23
26
24
27 # Install the default route as the lowest priority.
25 # Install the default route as the lowest priority.
28 map.connect ':controller/:action/:id'
26 map.connect ':controller/:action/:id'
29 end
27 end
General Comments 0
You need to be logged in to leave comments. Login now