##// END OF EJS Templates
* replaced :controller => '' broken statements by :controller => 'welcome'...
Jean-Philippe Lang -
r172:4e03668eec2c
parent child
Show More
@@ -1,133 +1,133
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class AccountController < ApplicationController
19 19 layout 'base'
20 20 helper :custom_fields
21 21 include CustomFieldsHelper
22 22
23 23 # prevents login action to be filtered by check_if_login_required application scope filter
24 24 skip_before_filter :check_if_login_required, :only => [:login, :lost_password, :register]
25 25 before_filter :require_login, :except => [:show, :login, :lost_password, :register]
26 26
27 27 # Show user's account
28 28 def show
29 29 @user = User.find(params[:id])
30 30 @custom_values = @user.custom_values.find(:all, :include => :custom_field)
31 31 rescue ActiveRecord::RecordNotFound
32 32 render_404
33 33 end
34 34
35 35 # Login request and validation
36 36 def login
37 37 if request.get?
38 38 # Logout user
39 39 self.logged_in_user = nil
40 40 else
41 41 # Authenticate user
42 42 user = User.try_to_login(params[:login], params[:password])
43 43 if user
44 44 self.logged_in_user = user
45 45 redirect_back_or_default :controller => 'my', :action => 'page'
46 46 else
47 47 flash.now[:notice] = l(:notice_account_invalid_creditentials)
48 48 end
49 49 end
50 50 end
51 51
52 52 # Log out current user and redirect to welcome page
53 53 def logout
54 54 self.logged_in_user = nil
55 redirect_to :controller => ''
55 redirect_to :controller => 'welcome'
56 56 end
57 57
58 58 # Enable user to choose a new password
59 59 def lost_password
60 60 if params[:token]
61 61 @token = Token.find_by_action_and_value("recovery", params[:token])
62 redirect_to :controller => '' and return unless @token and !@token.expired?
62 redirect_to :controller => 'welcome' and return unless @token and !@token.expired?
63 63 @user = @token.user
64 64 if request.post?
65 65 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
66 66 if @user.save
67 67 @token.destroy
68 68 flash[:notice] = l(:notice_account_password_updated)
69 69 redirect_to :action => 'login'
70 70 return
71 71 end
72 72 end
73 73 render :template => "account/password_recovery"
74 74 return
75 75 else
76 76 if request.post?
77 77 user = User.find_by_mail(params[:mail])
78 78 # user not found in db
79 79 flash.now[:notice] = l(:notice_account_unknown_email) and return unless user
80 80 # user uses an external authentification
81 81 flash.now[:notice] = l(:notice_can_t_change_password) and return if user.auth_source_id
82 82 # create a new token for password recovery
83 83 token = Token.new(:user => user, :action => "recovery")
84 84 if token.save
85 85 # send token to user via email
86 86 Mailer.set_language_if_valid(user.language)
87 87 Mailer.deliver_lost_password(token)
88 88 flash[:notice] = l(:notice_account_lost_email_sent)
89 89 redirect_to :action => 'login'
90 90 return
91 91 end
92 92 end
93 93 end
94 94 end
95 95
96 96 # User self-registration
97 97 def register
98 redirect_to :controller => '' and return unless Setting.self_registration?
98 redirect_to :controller => 'welcome' and return unless Setting.self_registration?
99 99 if params[:token]
100 100 token = Token.find_by_action_and_value("register", params[:token])
101 redirect_to :controller => '' and return unless token and !token.expired?
101 redirect_to :controller => 'welcome' and return unless token and !token.expired?
102 102 user = token.user
103 redirect_to :controller => '' and return unless user.status == User::STATUS_REGISTERED
103 redirect_to :controller => 'welcome' and return unless user.status == User::STATUS_REGISTERED
104 104 user.status = User::STATUS_ACTIVE
105 105 if user.save
106 106 token.destroy
107 107 flash[:notice] = l(:notice_account_activated)
108 108 redirect_to :action => 'login'
109 109 return
110 110 end
111 111 else
112 112 if request.get?
113 113 @user = User.new(:language => Setting.default_language)
114 114 @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
115 115 else
116 116 @user = User.new(params[:user])
117 117 @user.admin = false
118 118 @user.login = params[:user][:login]
119 119 @user.status = User::STATUS_REGISTERED
120 120 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
121 121 @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
122 122 @user.custom_values = @custom_values
123 123 token = Token.new(:user => @user, :action => "register")
124 124 if @user.save and token.save
125 125 Mailer.set_language_if_valid(@user.language)
126 126 Mailer.deliver_register(token)
127 127 flash[:notice] = l(:notice_account_register_done)
128 redirect_to :controller => ''
128 redirect_to :controller => 'welcome' and return
129 129 end
130 130 end
131 131 end
132 132 end
133 133 end
@@ -1,132 +1,132
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class ApplicationController < ActionController::Base
19 19 before_filter :check_if_login_required, :set_localization
20 20
21 21 def logged_in_user=(user)
22 22 @logged_in_user = user
23 23 session[:user_id] = (user ? user.id : nil)
24 24 end
25 25
26 26 def logged_in_user
27 27 if session[:user_id]
28 28 @logged_in_user ||= User.find(session[:user_id])
29 29 else
30 30 nil
31 31 end
32 32 end
33 33
34 34 # check if login is globally required to access the application
35 35 def check_if_login_required
36 36 require_login if Setting.login_required?
37 37 end
38 38
39 39 def set_localization
40 40 lang = begin
41 41 if self.logged_in_user and self.logged_in_user.language and !self.logged_in_user.language.empty? and GLoc.valid_languages.include? self.logged_in_user.language.to_sym
42 42 self.logged_in_user.language
43 43 elsif request.env['HTTP_ACCEPT_LANGUAGE']
44 44 accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.split('-').first
45 45 if accept_lang and !accept_lang.empty? and GLoc.valid_languages.include? accept_lang.to_sym
46 46 accept_lang
47 47 end
48 48 end
49 49 rescue
50 50 nil
51 51 end || Setting.default_language
52 52 set_language_if_valid(lang)
53 53 end
54 54
55 55 def require_login
56 56 unless self.logged_in_user
57 57 store_location
58 58 redirect_to :controller => "account", :action => "login"
59 59 return false
60 60 end
61 61 true
62 62 end
63 63
64 64 def require_admin
65 65 return unless require_login
66 66 unless self.logged_in_user.admin?
67 67 render :nothing => true, :status => 403
68 68 return false
69 69 end
70 70 true
71 71 end
72 72
73 73 # authorizes the user for the requested action.
74 74 def authorize(ctrl = params[:controller], action = params[:action])
75 75 # check if action is allowed on public projects
76 76 if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ ctrl, action ]
77 77 return true
78 78 end
79 79 # if action is not public, force login
80 80 return unless require_login
81 81 # admin is always authorized
82 82 return true if self.logged_in_user.admin?
83 83 # if not admin, check membership permission
84 84 @user_membership ||= Member.find(:first, :conditions => ["user_id=? and project_id=?", self.logged_in_user.id, @project.id])
85 85 if @user_membership and Permission.allowed_to_role( "%s/%s" % [ ctrl, action ], @user_membership.role_id )
86 86 return true
87 87 end
88 88 render :nothing => true, :status => 403
89 89 false
90 90 end
91 91
92 92 # store current uri in session.
93 93 # return to this location by calling redirect_back_or_default
94 94 def store_location
95 session[:return_to] = request.request_uri
95 session[:return_to_params] = params
96 96 end
97 97
98 98 # move to the last store_location call or to the passed default one
99 99 def redirect_back_or_default(default)
100 if session[:return_to].nil?
100 if session[:return_to_params].nil?
101 101 redirect_to default
102 102 else
103 redirect_to_url session[:return_to]
104 session[:return_to] = nil
103 redirect_to session[:return_to_params]
104 session[:return_to_params] = nil
105 105 end
106 106 end
107 107
108 108 def render_404
109 109 @html_title = "404"
110 110 render :template => "common/404", :layout => true, :status => 404
111 111 return false
112 112 end
113 113
114 114 # qvalues http header parser
115 115 # code taken from webrick
116 116 def parse_qvalues(value)
117 117 tmp = []
118 118 if value
119 119 parts = value.split(/,\s*/)
120 120 parts.each {|part|
121 121 if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
122 122 val = m[1]
123 123 q = (m[2] or 1).to_f
124 124 tmp.push([val, q])
125 125 end
126 126 }
127 127 tmp = tmp.sort_by{|val, q| -q}
128 128 tmp.collect!{|val, q| val}
129 129 end
130 130 return tmp
131 131 end
132 132 end No newline at end of file
@@ -1,20 +1,20
1 1 xml.instruct!
2 2 xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
3 3 xml.channel do
4 4 xml.title "#{Setting.app_title}: #{l(:label_news_latest)}"
5 xml.link url_for(:controller => '', :only_path => false)
5 xml.link url_for(:controller => 'welcome', :only_path => false)
6 6 xml.pubDate CGI.rfc1123_date(@news.first.created_on)
7 7 xml.description l(:label_news_latest)
8 8 @news.each do |news|
9 9 xml.item do
10 10 xml.title "#{news.project.name}: #{news.title}"
11 11 news_url = url_for(:controller => 'news' , :action => 'show', :id => news, :only_path => false)
12 12 xml.link news_url
13 13 xml.description h(news.summary)
14 14 xml.pubDate CGI.rfc1123_date(news.created_on)
15 15 xml.guid news_url
16 16 xml.author h(news.author.name)
17 17 end
18 18 end
19 19 end
20 20 end No newline at end of file
@@ -1,143 +1,143
1 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
2 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3 3 <head>
4 4 <title><%= Setting.app_title + (@html_title ? ": #{@html_title}" : "") %></title>
5 5 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6 6 <meta name="description" content="redMine" />
7 7 <meta name="keywords" content="issue,bug,tracker" />
8 8 <!--[if IE]>
9 9 <style type="text/css">
10 10 body {behavior: url(<%= stylesheet_path "csshover.htc" %>);}
11 11 </style>
12 12 <![endif]-->
13 13 <%= stylesheet_link_tag "application" %>
14 14 <%= stylesheet_link_tag "print", :media => "print" %>
15 15 <%= javascript_include_tag :defaults %>
16 16 <%= javascript_include_tag 'menu' %>
17 17 <%= stylesheet_link_tag 'jstoolbar' %>
18 18 <!-- page specific tags --><%= yield :header_tags %>
19 19 </head>
20 20
21 21 <body>
22 22 <div id="container" >
23 23
24 24 <div id="header">
25 25 <div style="float: left;">
26 26 <h1><%= Setting.app_title %></h1>
27 27 <h2><%= Setting.app_subtitle %></h2>
28 28 </div>
29 29 <div style="float: right; padding-right: 1em; padding-top: 0.2em;">
30 30 <% if loggedin? %><small><%=l(:label_logged_as)%> <b><%= @logged_in_user.login %></b></small><% end %>
31 31 </div>
32 32 </div>
33 33
34 34 <div id="navigation">
35 35 <ul>
36 <li><%= link_to l(:label_home), { :controller => '' }, :class => "icon icon-home" %></li>
36 <li><%= link_to l(:label_home), { :controller => 'welcome' }, :class => "icon icon-home" %></li>
37 37 <li><%= link_to l(:label_my_page), { :controller => 'my', :action => 'page'}, :class => "icon icon-mypage" %></li>
38 38 <li><%= link_to l(:label_project_plural), { :controller => 'projects' }, :class => "icon icon-projects" %></li>
39 39
40 40 <% unless @project.nil? || @project.id.nil? %>
41 41 <li class="submenu"><%= link_to @project.name, { :controller => 'projects', :action => 'show', :id => @project }, :class => "icon icon-projects", :onmouseover => "buttonMouseover(event, 'menuProject');" %></li>
42 42 <% end %>
43 43
44 44 <% if loggedin? %>
45 45 <li><%= link_to l(:label_my_account), { :controller => 'my', :action => 'account' }, :class => "icon icon-user" %></li>
46 46 <% end %>
47 47
48 48 <% if admin_loggedin? %>
49 49 <li class="submenu"><%= link_to l(:label_administration), { :controller => 'admin' }, :class => "icon icon-admin", :onmouseover => "buttonMouseover(event, 'menuAdmin');" %></li>
50 50 <% end %>
51 51
52 52 <li class="right"><%= link_to l(:label_help), { :controller => 'help', :ctrl => params[:controller], :page => params[:action] }, :onclick => "window.open(this.href); return false;", :class => "icon icon-help" %></li>
53 53
54 54 <% if loggedin? %>
55 55 <li class="right"><%= link_to l(:label_logout), { :controller => 'account', :action => 'logout' }, :class => "icon icon-user" %></li>
56 56 <% else %>
57 57 <li class="right"><%= link_to l(:label_login), { :controller => 'account', :action => 'login' }, :class => "icon icon-user" %></li>
58 58 <% end %>
59 59 </ul>
60 60 </div>
61 61
62 62 <% if admin_loggedin? %>
63 63 <div id="menuAdmin" class="menu" onmouseover="menuMouseover(event)">
64 64 <a class="menuItem" href="/admin/projects" onmouseover="menuItemMouseover(event,'menuProjects');"><span class="menuItemText"><%=l(:label_project_plural)%></span><span class="menuItemArrow">&#9654;</span></a>
65 65 <a class="menuItem" href="/users" onmouseover="menuItemMouseover(event,'menuUsers');"><span class="menuItemText"><%=l(:label_user_plural)%></span><span class="menuItemArrow">&#9654;</span></a>
66 66 <a class="menuItem" href="/roles"><%=l(:label_role_and_permissions)%></a>
67 67 <a class="menuItem" href="/trackers" onmouseover="menuItemMouseover(event,'menuTrackers');"><span class="menuItemText"><%=l(:label_tracker_plural)%></span><span class="menuItemArrow">&#9654;</span></a>
68 68 <a class="menuItem" href="/custom_fields"><%=l(:label_custom_field_plural)%></a>
69 69 <a class="menuItem" href="/enumerations"><%=l(:label_enumerations)%></a>
70 70 <a class="menuItem" href="/admin/mail_options"><%=l(:field_mail_notification)%></a>
71 71 <a class="menuItem" href="/auth_sources"><%=l(:label_authentication)%></a>
72 72 <a class="menuItem" href="/settings"><%=l(:label_settings)%></a>
73 73 <a class="menuItem" href="/admin/info"><%=l(:label_information_plural)%></a>
74 74 </div>
75 75 <div id="menuTrackers" class="menu">
76 76 <a class="menuItem" href="/issue_statuses"><%=l(:label_issue_status_plural)%></a>
77 77 <a class="menuItem" href="/roles/workflow"><%=l(:label_workflow)%></a>
78 78 </div>
79 79 <div id="menuProjects" class="menu"><a class="menuItem" href="/projects/add"><%=l(:label_new)%></a></div>
80 80 <div id="menuUsers" class="menu"><a class="menuItem" href="/users/add"><%=l(:label_new)%></a></div>
81 81 <% end %>
82 82
83 83 <% unless @project.nil? || @project.id.nil? %>
84 84 <div id="menuProject" class="menu" onmouseover="menuMouseover(event)">
85 85 <%= link_to l(:label_calendar), {:controller => 'projects', :action => 'calendar', :id => @project }, :class => "menuItem" %>
86 86 <%= link_to l(:label_gantt), {:controller => 'projects', :action => 'gantt', :id => @project }, :class => "menuItem" %>
87 87 <%= link_to l(:label_issue_plural), {:controller => 'projects', :action => 'list_issues', :id => @project }, :class => "menuItem" %>
88 88 <%= link_to l(:label_report_plural), {:controller => 'reports', :action => 'issue_report', :id => @project }, :class => "menuItem" %>
89 89 <%= link_to l(:label_activity), {:controller => 'projects', :action => 'activity', :id => @project }, :class => "menuItem" %>
90 90 <%= link_to l(:label_news_plural), {:controller => 'projects', :action => 'list_news', :id => @project }, :class => "menuItem" %>
91 91 <%= link_to l(:label_change_log), {:controller => 'projects', :action => 'changelog', :id => @project }, :class => "menuItem" %>
92 92 <%= link_to l(:label_document_plural), {:controller => 'projects', :action => 'list_documents', :id => @project }, :class => "menuItem" %>
93 93 <%= link_to l(:label_member_plural), {:controller => 'projects', :action => 'list_members', :id => @project }, :class => "menuItem" %>
94 94 <%= link_to l(:label_attachment_plural), {:controller => 'projects', :action => 'list_files', :id => @project }, :class => "menuItem" %>
95 95 <%= link_to l(:label_repository), {:controller => 'repositories', :action => 'show', :id => @project}, :class => "menuItem" if @project.repository and !@project.repository.new_record? %>
96 96 <%= link_to_if_authorized l(:label_settings), {:controller => 'projects', :action => 'settings', :id => @project }, :class => "menuItem" %>
97 97 </div>
98 98 <% end %>
99 99
100 100
101 101 <div id="subcontent">
102 102
103 103 <% unless @project.nil? || @project.id.nil? %>
104 104 <h2><%= @project.name %></h2>
105 105 <ul class="menublock">
106 106 <li><%= link_to l(:label_overview), :controller => 'projects', :action => 'show', :id => @project %></li>
107 107 <li><%= link_to l(:label_calendar), :controller => 'projects', :action => 'calendar', :id => @project %></li>
108 108 <li><%= link_to l(:label_gantt), :controller => 'projects', :action => 'gantt', :id => @project %></li>
109 109 <li><%= link_to l(:label_issue_plural), :controller => 'projects', :action => 'list_issues', :id => @project %></li>
110 110 <li><%= link_to l(:label_report_plural), :controller => 'reports', :action => 'issue_report', :id => @project %></li>
111 111 <li><%= link_to l(:label_activity), :controller => 'projects', :action => 'activity', :id => @project %></li>
112 112 <li><%= link_to l(:label_news_plural), :controller => 'projects', :action => 'list_news', :id => @project %></li>
113 113 <li><%= link_to l(:label_change_log), :controller => 'projects', :action => 'changelog', :id => @project %></li>
114 114 <li><%= link_to l(:label_document_plural), :controller => 'projects', :action => 'list_documents', :id => @project %></li>
115 115 <li><%= link_to l(:label_member_plural), :controller => 'projects', :action => 'list_members', :id => @project %></li>
116 116 <li><%= link_to l(:label_attachment_plural), :controller => 'projects', :action => 'list_files', :id => @project %></li>
117 117 <li><%= link_to l(:label_repository), :controller => 'repositories', :action => 'show', :id => @project if @project.repository and !@project.repository.new_record? %></li>
118 118 <li><%= link_to_if_authorized l(:label_settings), :controller => 'projects', :action => 'settings', :id => @project %></li>
119 119 </ul>
120 120 <% end %>
121 121
122 122 <% if loggedin? and @logged_in_user.memberships.length > 0 %>
123 123 <h2><%=l(:label_my_projects) %></h2>
124 124 <ul class="menublock">
125 125 <% for membership in @logged_in_user.memberships %>
126 126 <li><%= link_to membership.project.name, :controller => 'projects', :action => 'show', :id => membership.project %></li>
127 127 <% end %>
128 128 </ul>
129 129 <% end %>
130 130 </div>
131 131
132 132 <div id="content">
133 133 <% if flash[:notice] %><p style="color: green"><%= flash[:notice] %></p><% end %>
134 134 <%= @content_for_layout %>
135 135 </div>
136 136
137 137 <div id="footer">
138 138 <p><a href="http://redmine.rubyforge.org/">redMine</a> <%= Redmine::VERSION %> &copy 2006-2007 Jean-Philippe Lang</p>
139 139 </div>
140 140
141 141 </div>
142 142 </body>
143 143 </html> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now