Commit 7eb64715 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Added autologin feature (disabled by default).

To enable this feature, go to administration settings and choose a duration for autologin.
When enabled, a checkbox on the login form lets users activate autologin.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@514 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 56513a8c
...@@ -42,6 +42,11 @@ class AccountController < ApplicationController ...@@ -42,6 +42,11 @@ class AccountController < ApplicationController
user = User.try_to_login(params[:login], params[:password]) user = User.try_to_login(params[:login], params[:password])
if user if user
self.logged_in_user = user self.logged_in_user = user
# generate a key and set cookie if autologin
if params[:autologin] && Setting.autologin?
token = Token.create(:user => user, :action => 'autologin')
cookies[:autologin] = { :value => token.value, :expires => 1.year.from_now }
end
redirect_back_or_default :controller => 'my', :action => 'page' redirect_back_or_default :controller => 'my', :action => 'page'
else else
flash.now[:notice] = l(:notice_account_invalid_creditentials) flash.now[:notice] = l(:notice_account_invalid_creditentials)
...@@ -51,6 +56,8 @@ class AccountController < ApplicationController ...@@ -51,6 +56,8 @@ class AccountController < ApplicationController
# Log out current user and redirect to welcome page # Log out current user and redirect to welcome page
def logout def logout
cookies.delete :autologin
Token.delete_all(["user_id = ? AND action = ?", logged_in_user.id, "autologin"]) if logged_in_user
self.logged_in_user = nil self.logged_in_user = nil
redirect_to :controller => 'welcome' redirect_to :controller => 'welcome'
end end
......
...@@ -40,6 +40,13 @@ class ApplicationController < ActionController::Base ...@@ -40,6 +40,13 @@ class ApplicationController < ActionController::Base
# check if login is globally required to access the application # check if login is globally required to access the application
def check_if_login_required def check_if_login_required
# no check needed if user is already logged in
return true if logged_in_user
# auto-login feature
autologin_key = cookies[:autologin]
if autologin_key && Setting.autologin?
self.logged_in_user = User.find_by_autologin_key(autologin_key)
end
require_login if Setting.login_required? require_login if Setting.login_required?
end end
......
...@@ -49,7 +49,7 @@ class Setting < ActiveRecord::Base ...@@ -49,7 +49,7 @@ class Setting < ActiveRecord::Base
end end
def self.#{name}? def self.#{name}?
self[:#{name}].to_s == "1" self[:#{name}].to_i > 0
end end
def self.#{name}=(value) def self.#{name}=(value)
......
...@@ -141,6 +141,11 @@ class User < ActiveRecord::Base ...@@ -141,6 +141,11 @@ class User < ActiveRecord::Base
token = Token.find_by_value(key) token = Token.find_by_value(key)
token && token.user.active? ? token.user : nil token && token.user.active? ? token.user : nil
end end
def self.find_by_autologin_key(key)
token = Token.find_by_action_and_value('autologin', key)
token && (token.created_on > Setting.autologin.to_i.day.ago) && token.user.active? ? token.user : nil
end
def <=>(user) def <=>(user)
lastname == user.lastname ? firstname <=> user.firstname : lastname <=> user.lastname lastname == user.lastname ? firstname <=> user.firstname : lastname <=> user.lastname
......
...@@ -3,23 +3,26 @@ ...@@ -3,23 +3,26 @@
<h2 class="icon22 icon22-authent"><%=l(:label_please_login)%></h2> <h2 class="icon22 icon22-authent"><%=l(:label_please_login)%></h2>
<% form_tag({:action=> "login"}, :class => "tabular") do %> <% form_tag({:action=> "login"}, :class => "tabular") do %>
<p><label for="login"><%=l(:field_login)%>:</label> <p><label for="login"><%=l(:field_login)%>:</label>
<%= text_field_tag 'login', nil, :size => 25 %></p> <%= text_field_tag 'login', nil, :size => 25 %></p>
<p><label for="password"><%=l(:field_password)%>:</label> <p><label for="password"><%=l(:field_password)%>:</label>
<%= password_field_tag 'password', nil, :size => 25 %></p> <%= password_field_tag 'password', nil, :size => 25 %></p>
<p><center><input type="submit" name="login" value="<%=l(:button_login)%> &#187;" class="primary" /></center> <% if Setting.autologin? %>
<p><label for="autologin"><%= check_box_tag 'autologin' %> <%= l(:label_stay_logged_in) %></label></p>
<% end %>
<p><input type="submit" name="login" value="<%=l(:button_login)%> &#187;" class="primary" /></p>
<% end %> <% end %>
<%= javascript_tag "Form.Element.focus('login');" %> <%= javascript_tag "Form.Element.focus('login');" %>
<br>
<% links = [] <% links = []
links << link_to(l(:label_register), :action => 'register') if Setting.self_registration? links << link_to(l(:label_register), :action => 'register') if Setting.self_registration?
links << link_to(l(:label_password_lost), :action => 'lost_password') if Setting.lost_password? links << link_to(l(:label_password_lost), :action => 'lost_password') if Setting.lost_password?
%> %>
<%= links.join(" | ") %> <%= links.join(" | ") %>
</p>
</div> </div>
</center> </center>
\ No newline at end of file
...@@ -15,15 +15,6 @@ ...@@ -15,15 +15,6 @@
<p><label><%= l(:setting_default_language) %></label> <p><label><%= l(:setting_default_language) %></label>
<%= select_tag 'settings[default_language]', options_for_select( lang_options_for_select(false), Setting.default_language) %></p> <%= select_tag 'settings[default_language]', options_for_select( lang_options_for_select(false), Setting.default_language) %></p>
<p><label><%= l(:setting_login_required) %></label>
<%= check_box_tag 'settings[login_required]', 1, Setting.login_required? %><%= hidden_field_tag 'settings[login_required]', 0 %></p>
<p><label><%= l(:setting_self_registration) %></label>
<%= check_box_tag 'settings[self_registration]', 1, Setting.self_registration? %><%= hidden_field_tag 'settings[self_registration]', 0 %></p>
<p><label><%= l(:label_password_lost) %></label>
<%= check_box_tag 'settings[lost_password]', 1, Setting.lost_password? %><%= hidden_field_tag 'settings[lost_password]', 0 %></p>
<p><label><%= l(:setting_attachment_max_size) %></label> <p><label><%= l(:setting_attachment_max_size) %></label>
<%= text_field_tag 'settings[attachment_max_size]', Setting.attachment_max_size, :size => 6 %> KB</p> <%= text_field_tag 'settings[attachment_max_size]', Setting.attachment_max_size, :size => 6 %> KB</p>
...@@ -52,6 +43,20 @@ ...@@ -52,6 +43,20 @@
<%= check_box_tag 'settings[sys_api_enabled]', 1, Setting.sys_api_enabled? %><%= hidden_field_tag 'settings[sys_api_enabled]', 0 %></p> <%= check_box_tag 'settings[sys_api_enabled]', 1, Setting.sys_api_enabled? %><%= hidden_field_tag 'settings[sys_api_enabled]', 0 %></p>
</div> </div>
<fieldset class="box"><legend><%= l(:label_authentication) %></legend>
<p><label><%= l(:setting_login_required) %></label>
<%= check_box_tag 'settings[login_required]', 1, Setting.login_required? %><%= hidden_field_tag 'settings[login_required]', 0 %></p>
<p><label><%= l(:setting_autologin) %></label>
<%= select_tag 'settings[autologin]', options_for_select( [[l(:label_disabled), "0"]] + [1, 7, 30, 365].collect{|days| [lwr(:actionview_datehelper_time_in_words_day, days), days.to_s]}, Setting.autologin) %></p>
<p><label><%= l(:setting_self_registration) %></label>
<%= check_box_tag 'settings[self_registration]', 1, Setting.self_registration? %><%= hidden_field_tag 'settings[self_registration]', 0 %></p>
<p><label><%= l(:label_password_lost) %></label>
<%= check_box_tag 'settings[lost_password]', 1, Setting.lost_password? %><%= hidden_field_tag 'settings[lost_password]', 0 %></p>
</fieldset>
<fieldset class="box"><legend><%= l(:text_issues_ref_in_commit_messages) %></legend> <fieldset class="box"><legend><%= l(:text_issues_ref_in_commit_messages) %></legend>
<p><label><%= l(:setting_commit_ref_keywords) %></label> <p><label><%= l(:setting_commit_ref_keywords) %></label>
<%= text_field_tag 'settings[commit_ref_keywords]', Setting.commit_ref_keywords, :size => 30 %><br /><em><%= l(:text_coma_separated) %></em></p> <%= text_field_tag 'settings[commit_ref_keywords]', Setting.commit_ref_keywords, :size => 30 %><br /><em><%= l(:text_coma_separated) %></em></p>
......
...@@ -61,4 +61,8 @@ commit_fix_keywords: ...@@ -61,4 +61,8 @@ commit_fix_keywords:
commit_fix_status_id: commit_fix_status_id:
format: int format: int
default: 0 default: 0
# autologin duration in days
\ No newline at end of file # 0 means autologin is disabled
autologin:
format: int
default: 0
...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Автоматично обработване на ...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Автоматично обработване на
setting_sys_api_enabled: Разрешаване на WS за управление на SVN склада setting_sys_api_enabled: Разрешаване на WS за управление на SVN склада
setting_commit_ref_keywords: Отбелязващи ключови думи setting_commit_ref_keywords: Отбелязващи ключови думи
setting_commit_fix_keywords: Приключващи ключови думи setting_commit_fix_keywords: Приключващи ключови думи
setting_autologin: Autologin
label_user: Потребител label_user: Потребител
label_user_plural: Потребители label_user_plural: Потребители
...@@ -380,6 +381,8 @@ label_end_to_start: start to end ...@@ -380,6 +381,8 @@ label_end_to_start: start to end
label_end_to_end: end to end label_end_to_end: end to end
label_start_to_start: start to start label_start_to_start: start to start
label_start_to_end: start to end label_start_to_end: start to end
label_stay_logged_in: Stay logged in
label_disabled: disabled
button_login: Вход button_login: Вход
button_submit: Изпращане button_submit: Изпращане
......
...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Autofetch SVN commits ...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Autofetch SVN commits
setting_sys_api_enabled: Enable WS for repository management setting_sys_api_enabled: Enable WS for repository management
setting_commit_ref_keywords: Referencing keywords setting_commit_ref_keywords: Referencing keywords
setting_commit_fix_keywords: Fixing keywords setting_commit_fix_keywords: Fixing keywords
setting_autologin: Autologin
label_user: Benutzer label_user: Benutzer
label_user_plural: Benutzer label_user_plural: Benutzer
...@@ -380,6 +381,8 @@ label_end_to_start: start to end ...@@ -380,6 +381,8 @@ label_end_to_start: start to end
label_end_to_end: end to end label_end_to_end: end to end
label_start_to_start: start to start label_start_to_start: start to start
label_start_to_end: start to end label_start_to_end: start to end
label_stay_logged_in: Stay logged in
label_disabled: disabled
button_login: Einloggen button_login: Einloggen
button_submit: OK button_submit: OK
......
...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Autofetch SVN commits ...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Autofetch SVN commits
setting_sys_api_enabled: Enable WS for repository management setting_sys_api_enabled: Enable WS for repository management
setting_commit_ref_keywords: Referencing keywords setting_commit_ref_keywords: Referencing keywords
setting_commit_fix_keywords: Fixing keywords setting_commit_fix_keywords: Fixing keywords
setting_autologin: Autologin
label_user: User label_user: User
label_user_plural: Users label_user_plural: Users
...@@ -380,6 +381,8 @@ label_end_to_start: start to end ...@@ -380,6 +381,8 @@ label_end_to_start: start to end
label_end_to_end: end to end label_end_to_end: end to end
label_start_to_start: start to start label_start_to_start: start to start
label_start_to_end: start to end label_start_to_end: start to end
label_stay_logged_in: Stay logged in
label_disabled: disabled
button_login: Login button_login: Login
button_submit: Submit button_submit: Submit
......
...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Autofetch SVN commits ...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Autofetch SVN commits
setting_sys_api_enabled: Enable WS for repository management setting_sys_api_enabled: Enable WS for repository management
setting_commit_ref_keywords: Referencing keywords setting_commit_ref_keywords: Referencing keywords
setting_commit_fix_keywords: Fixing keywords setting_commit_fix_keywords: Fixing keywords
setting_autologin: Autologin
label_user: Usuario label_user: Usuario
label_user_plural: Usuarios label_user_plural: Usuarios
...@@ -380,6 +381,8 @@ label_end_to_start: start to end ...@@ -380,6 +381,8 @@ label_end_to_start: start to end
label_end_to_end: end to end label_end_to_end: end to end
label_start_to_start: start to start label_start_to_start: start to start
label_start_to_end: start to end label_start_to_end: start to end
label_stay_logged_in: Stay logged in
label_disabled: disabled
button_login: Conexión button_login: Conexión
button_submit: Someter button_submit: Someter
......
...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Récupération auto. des commits SVN ...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Récupération auto. des commits SVN
setting_sys_api_enabled: Activer les WS pour la gestion des dépôts setting_sys_api_enabled: Activer les WS pour la gestion des dépôts
setting_commit_ref_keywords: Mot-clés de référencement setting_commit_ref_keywords: Mot-clés de référencement
setting_commit_fix_keywords: Mot-clés de résolution setting_commit_fix_keywords: Mot-clés de résolution
setting_autologin: Autologin
label_user: Utilisateur label_user: Utilisateur
label_user_plural: Utilisateurs label_user_plural: Utilisateurs
...@@ -380,6 +381,8 @@ label_end_to_start: début à fin ...@@ -380,6 +381,8 @@ label_end_to_start: début à fin
label_end_to_end: fin à fin label_end_to_end: fin à fin
label_start_to_start: début à début label_start_to_start: début à début
label_start_to_end: début à fin label_start_to_end: début à fin
label_stay_logged_in: Rester connecté
label_disabled: désactivé
button_login: Connexion button_login: Connexion
button_submit: Soumettre button_submit: Soumettre
......
...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Acquisisci automaticamente le commit SVN ...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Acquisisci automaticamente le commit SVN
setting_sys_api_enabled: Abilita WS per la gestione del repository setting_sys_api_enabled: Abilita WS per la gestione del repository
setting_commit_ref_keywords: Referencing keywords setting_commit_ref_keywords: Referencing keywords
setting_commit_fix_keywords: Fixing keywords setting_commit_fix_keywords: Fixing keywords
setting_autologin: Autologin
label_user: Utente label_user: Utente
label_user_plural: Utenti label_user_plural: Utenti
...@@ -380,6 +381,8 @@ label_end_to_start: start to end ...@@ -380,6 +381,8 @@ label_end_to_start: start to end
label_end_to_end: end to end label_end_to_end: end to end
label_start_to_start: start to start label_start_to_start: start to start
label_start_to_end: start to end label_start_to_end: start to end
label_stay_logged_in: Stay logged in
label_disabled: disabled
button_login: Login button_login: Login
button_submit: Invia button_submit: Invia
......
...@@ -172,6 +172,7 @@ setting_autofetch_changesets: SVNコミットを自動取得する ...@@ -172,6 +172,7 @@ setting_autofetch_changesets: SVNコミットを自動取得する
setting_sys_api_enabled: リポジトリ管理用のWeb Serviceを有効化する setting_sys_api_enabled: リポジトリ管理用のWeb Serviceを有効化する
setting_commit_ref_keywords: Referencing keywords setting_commit_ref_keywords: Referencing keywords
setting_commit_fix_keywords: Fixing keywords setting_commit_fix_keywords: Fixing keywords
setting_autologin: Autologin
label_user: ユーザ label_user: ユーザ
label_user_plural: ユーザ label_user_plural: ユーザ
...@@ -381,6 +382,8 @@ label_end_to_start: start to end ...@@ -381,6 +382,8 @@ label_end_to_start: start to end
label_end_to_end: end to end label_end_to_end: end to end
label_start_to_start: start to start label_start_to_start: start to start
label_start_to_end: start to end label_start_to_end: start to end
label_stay_logged_in: Stay logged in
label_disabled: disabled
button_login: ログイン button_login: ログイン
button_submit: 変更 button_submit: 変更
......
...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Autofetch SVN commits ...@@ -171,6 +171,7 @@ setting_autofetch_changesets: Autofetch SVN commits
setting_sys_api_enabled: Ativa WS para gerenciamento do repositorio setting_sys_api_enabled: Ativa WS para gerenciamento do repositorio
setting_commit_ref_keywords: Referencing keywords setting_commit_ref_keywords: Referencing keywords
setting_commit_fix_keywords: Fixing keywords setting_commit_fix_keywords: Fixing keywords
setting_autologin: Autologin
label_user: Usuario label_user: Usuario
label_user_plural: Usuarios label_user_plural: Usuarios
...@@ -380,6 +381,8 @@ label_end_to_start: start to end ...@@ -380,6 +381,8 @@ label_end_to_start: start to end
label_end_to_end: end to end label_end_to_end: end to end
label_start_to_start: start to start label_start_to_start: start to start
label_start_to_end: start to end label_start_to_end: start to end
label_stay_logged_in: Stay logged in
label_disabled: disabled
button_login: Login button_login: Login
button_submit: Enviar button_submit: Enviar
......
...@@ -174,6 +174,7 @@ setting_autofetch_changesets: Autofetch SVN commits ...@@ -174,6 +174,7 @@ setting_autofetch_changesets: Autofetch SVN commits
setting_sys_api_enabled: Enable WS for repository management setting_sys_api_enabled: Enable WS for repository management
setting_commit_ref_keywords: Referencing keywords setting_commit_ref_keywords: Referencing keywords
setting_commit_fix_keywords: Fixing keywords setting_commit_fix_keywords: Fixing keywords
setting_autologin: Autologin
label_user: 用户 label_user: 用户
label_user_plural: 用户列表 label_user_plural: 用户列表
...@@ -383,6 +384,8 @@ label_end_to_start: start to end ...@@ -383,6 +384,8 @@ label_end_to_start: start to end
label_end_to_end: end to end label_end_to_end: end to end
label_start_to_start: start to start label_start_to_start: start to start
label_start_to_end: start to end label_start_to_end: start to end
label_stay_logged_in: Stay logged in
label_disabled: disabled
button_login: 登录 button_login: 登录
button_submit: 提交 button_submit: 提交
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment