In The Redmine changed plugin openid. Added Simple Captcha.

atratsevskiy
Чистяков Илья 15 years ago
parent 6813331392
commit 5e4f1e630f

@ -1,2 +1,7 @@
AUX 10_redmine_vhost.conf 523 RMD160 080c5afc8cef54f2fbdf24b1ff262cc155d85ac5 SHA1 cac48370ffc7756173c0a759366ee8a7d3d7c716 SHA256 439017a65fabb0bd7cb49abd94864be372b73a4b953e31dc0db8449790406205
EBUILD redmine-9999.ebuild 4455 RMD160 f41c67ee21ecd3de52840092242247795c42a654 SHA1 f81c5eec6ed0ae3b7a51f7c5edb07fd5c8146a9c SHA256 8104242a9d314bfe05b1b87709b2b68f920269ecf1b807344e41b3b7d178bfb8
AUX install.sh 156 RMD160 84d0800e4fc9762a1438d721afe63b87899874c5 SHA1 8217fbd04e42e5c455469bd06cf923b2df8e9abc SHA256 115def32b307a837f1fe2677d02ba4f8f0d1b40e19fce1426d334f42d0edc8f5
AUX openid.patch 11280 RMD160 0bb3b8a5d1a9de9aa70373f1f4a87ee00ce14192 SHA1 2d3a39e3387fc623bfd117c1973b0aa449d94f44 SHA256 dbe97644be53dcc14c82c0dfb13c76ebb8f966c7f3340fab376612fb4a621fe1
AUX openid_install.sh 259 RMD160 a5b37ce91355a3bd56ee63f1d1f133974e381561 SHA1 b4016d8226cd6615e8c08268c99bf19a97ca16bf SHA256 3fa8bb9f624fa28c157f0346155a66eddadcb44d3a380caf13e0b89c9b0dcf8b
AUX simple_captcha.patch 1126 RMD160 a5316ed4d9b057eb4b6388c7cd0b4cd5d4d6f990 SHA1 ae8c7b66e6da4240bfae350826742636a1afa31a SHA256 b8e0f65c7ea2743a1c5cdd5e762f7b191a6ea0e9d499ed98c6d2479d3edb5027
AUX simple_captcha_install.sh 469 RMD160 4897fab0b702e0d784b3cda49cd2288f49cf00f0 SHA1 2ee407104659559917c0c35404f17188cf985220 SHA256 ef77c9c8dd2c7d34974e125bcb88d2d48516f0ed1c5bf3635cbb06bced406e87
EBUILD redmine-9999.ebuild 4582 RMD160 8a32a16519b79c7cc4015ba85fcbde331cc4fec8 SHA1 c870436c232744305389b016ea34f986cd9abe7e SHA256 7c55a778e464eadcd7c27590ffdc196b90bd1b414e3b2fbda435b510d918415b

@ -0,0 +1,8 @@
#!/usr/bin/bash
BASE=`dirname $0`
if [[ "$0" != /* ]]
then
BASE=`pwd`/$BASE
fi
bash $BASE/simple_captcha_install.sh || exit 1
bash $BASE/openid_install.sh

@ -0,0 +1,270 @@
--- app/controllers/account_controller.rb
+++ app/controllers/account_controller.rb
@@ -29,11 +29,34 @@ class AccountController < ApplicationController
self.logged_user = nil
else
# Authenticate user
- if Setting.openid? && using_open_id?
- open_id_authenticate(params[:openid_url])
- else
- password_authentication
+ password_authentication
+ end
+ end
+
+ def openid_login
+ if !Setting.openid?
+ render_404
+ end
+ if Setting.openid_only?
+ open_id_authenticate('iduser.net')
+ return
+ end
+ @server = '0'
+ if request.get?
+ # Logout user
+ self.logged_user = nil
+ elsif using_open_id?
+ # Authenticate user
+ if params[:server]
+ if params[:server] == '0'
+ params[:openid_url] = 'iduser.net'
+ elsif !simple_captcha_valid?
+ flash.now[:error] = l(:notice_account_invalid_captcha)
+ @server = params[:server]
+ return
+ end
end
+ open_id_authenticate(params[:openid_url])
end
end
@@ -153,7 +176,7 @@ class AccountController < ApplicationController
def open_id_authenticate(openid_url)
- authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => signin_url) do |result, identity_url, registration|
+ authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => url_for(:action => 'openid_login')) do |result, identity_url, registration|
if result.successful?
user = User.find_or_initialize_by_identity_url(identity_url)
if user.new_record?
--- app/models/setting.rb
+++ app/models/setting.rb
@@ -143,6 +143,10 @@ class Setting < ActiveRecord::Base
def self.openid?
Object.const_defined?(:OpenID) && self[:openid].to_i > 0
end
+
+ def self.openid_only?
+ Object.const_defined?(:OpenID) && self[:openid_only].to_i > 0
+ end
# Checks if settings have changed since the values were read
# and clears the cache hash if it's the case
--- app/views/account/login.rhtml
+++ app/views/account/login.rhtml
@@ -10,12 +10,6 @@
<td align="right"><label for="password"><%=l(:field_password)%>:</label></td>
<td align="left"><%= password_field_tag 'password', nil, :tabindex => '2' %></td>
</tr>
-<% if Setting.openid? %>
-<tr>
- <td align="right"><label for="openid_url"><%=l(:field_identity_url)%></label></td>
- <td align="left"><%= text_field_tag "openid_url", nil, :tabindex => '3' %></td>
-</tr>
-<% end %>
<tr>
<td></td>
<td align="left">
--- app/views/settings/_authentication.rhtml
+++ app/views/settings/_authentication.rhtml
@@ -29,6 +29,11 @@
<%= hidden_field_tag 'settings[openid]', 0 %>
<%= check_box_tag 'settings[openid]', 1, Setting.openid?, :disabled => !Object.const_defined?(:OpenID) %>
</p>
+
+<p><label><%= l(:setting_openid_only) %></label>
+<%= hidden_field_tag 'settings[openid_only]', 0 %>
+<%= check_box_tag 'settings[openid_only]', 1, Setting.openid_only?, :disabled => !Object.const_defined?(:OpenID) %>
+</p>
</div>
<div style="float:right;">
--- config/locales/en.yml
+++ config/locales/en.yml
@@ -125,6 +125,7 @@ en:
notice_account_updated: Account was successfully updated.
notice_account_invalid_creditentials: Invalid user or password
+ notice_account_invalid_captcha: You did not enter the correct code. Please try again.
notice_account_password_updated: Password was successfully updated.
notice_account_wrong_password: Wrong password
notice_account_register_done: Account was successfully created. To activate your account, click on the link that was emailed to you.
@@ -265,6 +266,9 @@ en:
field_editable: Editable
field_watcher: Watcher
field_identity_url: OpenID URL
+ field_login_with: Sign In with a
+ field_other_openid: other OpenID
+ field_captcha_valid: Verification
field_content: Content
field_group_by: Group results by
@@ -311,6 +315,7 @@ en:
setting_file_max_size_displayed: Max size of text files displayed inline
setting_repository_log_display_limit: Maximum number of revisions displayed on file log
setting_openid: Allow OpenID login and registration
+ setting_openid_only: Allow only OpenID
setting_password_min_length: Minimum password length
setting_new_project_user_role_id: Role given to a non-admin user who creates a project
setting_default_projects_modules: Default enabled modules for new projects
@@ -425,6 +430,7 @@ en:
label_information_plural: Information
label_please_login: Please log in
label_register: Register
+ label_openid_register: Register OpenID
label_login_with_open_id_option: or login with OpenID
label_password_lost: Lost password
label_home: Home
@@ -433,6 +438,7 @@ en:
label_my_projects: My projects
label_administration: Administration
label_login: Sign in
+ label_openid_login: Sign in with OpenID
label_logout: Sign out
label_help: Help
label_reported_issues: Reported issues
--- config/locales/ru.yml
+++ config/locales/ru.yml
@@ -315,6 +315,9 @@ ru:
field_hours: час(а,ов)
field_identifier: Уникальный идентификатор
field_identity_url: OpenID URL
+ field_login_with: Войти как
+ field_other_openid: другой OpenID
+ field_captcha_valid: Проверка
field_is_closed: Задача закрыта
field_is_default: Значение по умолчанию
field_is_filter: Используется в качестве фильтра
@@ -543,6 +546,7 @@ ru:
label_loading: Загрузка...
label_logged_as: Вошел как
label_login: Войти
+ label_openid_login: Вход с помощью OpenID
label_login_with_open_id_option: или войти с помощью OpenID
label_logout: Выйти
label_max_size: Максимальный размер
@@ -616,6 +620,7 @@ ru:
label_query_plural: Сохраненные запросы
label_read: Чтение...
label_register: Регистрация
+ label_openid_register: Регистрация OpenID
label_registered_on: Зарегистрирован(а)
label_registration_activation_by_email: активация учетных записей по email
label_registration_automatic_activation: автоматическая активация учетных записей
@@ -736,6 +740,7 @@ ru:
notice_account_activated: Ваша учетная запись активирована. Вы можете войти.
notice_account_invalid_creditentials: Неправильное имя пользователя или пароль
+ notice_account_invalid_captcha: Вы ввели не верный код. Пожалуйста, попробуйте еще раз.
notice_account_lost_email_sent: Вам отправлено письмо с инструкциями по выбору нового пароля.
notice_account_password_updated: Пароль успешно обновлен.
notice_account_pending: "Ваша учетная запись уже создана и ожидает подтверждения администратора."
@@ -846,6 +851,7 @@ ru:
setting_mail_handler_api_enabled: Включить веб-сервис для входящих сообщений
setting_mail_handler_api_key: API ключ
setting_openid: Разрешить OpenID для входа и регистрации
+ setting_openid_only: Разрешить только OpenID
setting_per_page_options: Количество строк на страницу
setting_plain_text_mail: Только простой текст (без HTML)
setting_protocol: Протокол
--- config/settings.yml
+++ config/settings.yml
@@ -168,5 +168,7 @@ gravatar_enabled:
default: 0
openid:
default: 0
+openid_only:
+ default: 0
gravatar_default:
default: ''
--- lib/redmine.rb
+++ lib/redmine.rb
@@ -124,8 +124,9 @@ Redmine::MenuManager.map :top_menu do |menu|
end
Redmine::MenuManager.map :account_menu do |menu|
- menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? }
- menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
+ menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? && !Setting.openid_only?}
+ menu.push :openid_login, { :controller => 'account', :action => 'openid_login' }, :if => Proc.new { !User.current.logged? && Setting.openid?}
+ menu.push :register, { :controller => 'account', :action => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? && !Setting.openid_only? }
menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? }
menu.push :logout, :signout_path, :if => Proc.new { User.current.logged? }
end
--- vendor/plugins/open_id_authentication/lib/open_id_authentication.rb
+++ vendor/plugins/open_id_authentication/lib/open_id_authentication.rb
@@ -118,7 +118,7 @@ module OpenIdAuthentication
# because that's what the specification dictates in order to get browser auto-complete working across sites
def using_open_id?(identity_url = nil) #:doc:
identity_url ||= params[:openid_identifier] || params[:openid_url]
- !identity_url.blank? || params[:open_id_complete]
+ !identity_url.blank? || params[:server] || params[:open_id_complete]
end
def authenticate_with_open_id(identity_url = nil, options = {}, &block) #:doc:
--- /dev/null
+++ b/app/views/account/openid_login.rhtml
@@ -0,0 +1,52 @@
+<div id="login-form">
+<% form_tag({:action=> "openid_login"}) do %>
+<%= back_url_hidden_field_tag %>
+<table style="width: 400px">
+<tr>
+ <td align="right" style="width: 100px"><label for="server"><%=l(:field_login_with)%></label></td>
+ <td>
+<%= select_tag 'server',
+ options_for_select( [['iduser.net', "0"],
+ [l(:field_other_openid), "1"],
+ ], @server ) %>
+ <input type="submit" name="login" value="<%=l(:button_login)%> &#187;" tabindex="5"/>
+ </td>
+</tr>
+<tbody id="other_ident"<% if @server != '1' %> style="display:none"<% end %>>
+<tr>
+ <td align="right"><label for="openid_url"><%=l(:field_identity_url)%>:</label></td>
+ <td align="left"><input id="openid_url" name="openid_url" type="text" /></td>
+</tr>
+<tr>
+ <td align="right"><label for="captcha"><%=l(:field_captcha_valid)%>:</label></td>
+ <td align="left"><%= show_simple_captcha(:label => '') %></td>
+</tr>
+</tbody>
+<tr>
+ <td></td>
+ <td align="left">
+ <% if Setting.autologin? %>
+ <label for="autologin"><%= check_box_tag 'autologin', 1, false, :tabindex => 4 %> <%= l(:label_stay_logged_in) %></label>
+ <% end %>
+ </td>
+</tr>
+<tr>
+ <td align="left">
+ </td>
+ <td align="right">
+ <%= link_to l(:label_openid_register), 'http://iduser.net/register/' %>
+ </td>
+</tr>
+<script type="text/javascript">
+$('server').observe('change', function () {
+ var vl = this.value;
+ if (vl == 0) {
+ $('other_ident').hide();
+ } else if (vl == 1) {
+ $('other_ident').show();
+ }
+});
+</script>
+</table>
+</div>
+<% end %>

@ -0,0 +1,20 @@
#!/usr/bin/bash
REDMINE_DIR=/var/lib/redmine
if [[ $BASE == '' ]]
then
BASE=`dirname $0`
if [[ "$0" != /* ]]
then
BASE=`pwd`/$BASE
fi
fi
if [ -d $REDMINE_DIR ]
then
cd $REDMINE_DIR
patch -p0 -i $BASE/openid.patch
else
echo "Redmine not found."
fi

@ -0,0 +1,30 @@
--- app/controllers/application_controller.rb
+++ app/controllers/application_controller.rb
@@ -19,6 +19,7 @@ require 'uri'
require 'cgi'
class ApplicationController < ActionController::Base
+ include SimpleCaptcha::ControllerHelpers
include Redmine::I18n
layout 'base'
--- config/routes.rb
+++ config/routes.rb
@@ -269,4 +269,6 @@ ActionController::Routing::Routes.draw do |map|
map.connect 'robots.txt', :controller => 'welcome', :action => 'robots'
# Used for OpenID
map.root :controller => 'account', :action => 'login'
+ # Captcha
+ map.simple_captcha '/simple_captcha/:action', :controller => 'simple_captcha'
end
--- vendor/plugins/simple_captcha/lib/simple_captcha_config.rb
+++ vendor/plugins/simple_captcha/lib/simple_captcha_config.rb
@@ -12,7 +12,7 @@ module SimpleCaptcha #:nodoc
end
def simple_captcha_key #:nodoc
- session[:simple_captcha] ||= Digest::SHA1.hexdigest(Time.now.to_s + session.session_id.to_s)
+ session[:simple_captcha] ||= Digest::SHA1.hexdigest(Time.now.to_s)
end
def simple_captcha_value(key = simple_captcha_key) #:nodoc

@ -0,0 +1,25 @@
#!/usr/bin/bash
REDMINE_DIR="/var/lib/redmine"
PLUGIN_REP="svn://rubyforge.org/var/svn/expressica/plugins/simple_captcha"
if [[ $BASE == '' ]]
then
BASE=`dirname $0`
if [[ "$0" != /* ]]
then
BASE=`pwd`/$BASE
fi
fi
echo $BASE
if [ -d $REDMINE_DIR ]
then
cd $REDMINE_DIR
ruby script/plugin install $PLUGIN_REP || exit 1
rake simple_captcha:setup || exit 1
rake db:migrate || exit 1
patch -p0 -i $BASE/simple_captcha.patch
else
echo "Redmine not found."
fi

@ -64,6 +64,11 @@ src_install() {
doins -r . || die
keepdir "${REDMINE_DIR}/files"
if use specopenid ; then
einfo "Install packs special OpenID and Simple Captcha:"
bash ${FILESDIR}/install.sh || die
fi
if use mongrel ; then
has_apache
insinto "${APACHE_VHOSTS_CONFDIR}"

Loading…
Cancel
Save