[DRE-commits] [redmine-recaptcha] 01/02: Imported Upstream version 0.1.0+git20121018
David Martínez
ender at moszumanska.debian.org
Tue Jan 7 06:46:23 UTC 2014
This is an automated email from the git hooks/post-receive script.
ender pushed a commit to annotated tag debian/0.1.0+git20121018-1
in repository redmine-recaptcha.
commit 3056de4113b6c16953368d2a0e71a137b9e9fb81
Author: David Martínez Moreno <ender at debian.org>
Date: Mon Jan 6 18:06:59 2014 -0800
Imported Upstream version 0.1.0+git20121018
---
Gemfile | 1 +
LICENSE | 19 +++++++++++
README.md | 37 +++++++++++++++++++++
app/views/account/register.rhtml | 46 ++++++++++++++++++++++++++
app/views/settings/_redmine_recaptcha.rhtml | 13 ++++++++
init.rb | 32 ++++++++++++++++++
lib/account_controller_patch.rb | 51 +++++++++++++++++++++++++++++
lib/client_helper_patch.rb | 16 +++++++++
8 files changed, 215 insertions(+)
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..1d63a50
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1 @@
+gem "recaptcha", :require => "recaptcha/rails"
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..7a6908d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Shane R StClair
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..9c0b93f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,37 @@
+# redmine_recaptcha
+
+srstclair at gmail.com
+
+Simple Redmine/ChiliProject plugin to add a reCAPTCHA to user self registration.
+
+Relies on ambethia's recaptcha for rails plugin (http://github.com/ambethia/recaptcha/)
+
+To install:
+
+* make sure you have git installed!
+
+* cd to your Redmine/ChiliProject directory
+
+* install the plugin (use sudo if needed)
+
+ * Redmine users
+
+ ruby script/plugin install git://github.com/ambethia/recaptcha.git
+ ruby script/plugin install git://github.com/srstclair/redmine_recaptcha.git
+
+ * Chiliproject users
+
+ ruby script/plugin install git://github.com/srstclair/redmine_recaptcha.git
+ bundle install
+
+* restart Redmine/ChiliProject
+
+* sign in as an administrator
+
+* go to Administration/Plugins/reCAPTCHA/Configure
+
+* sign up for a recaptcha key at http://www.google.com/recaptcha (if you haven't already)
+
+* enter your public and private recaptcha keys
+
+* go to self registration page to see captcha!
diff --git a/app/views/account/register.rhtml b/app/views/account/register.rhtml
new file mode 100644
index 0000000..d846323
--- /dev/null
+++ b/app/views/account/register.rhtml
@@ -0,0 +1,46 @@
+<h2><%=l(:label_register)%> <%=link_to l(:label_login_with_open_id_option), signin_url if Setting.openid? %></h2>
+
+<% form_tag({:action => 'register'}, :class => "tabular") do %>
+<%= error_messages_for 'user' %>
+
+<div class="box">
+<!--[form:user]-->
+<% if @user.auth_source_id.nil? %>
+<p><label for="user_login"><%=l(:field_login)%> <span class="required">*</span></label>
+<%= text_field 'user', 'login', :size => 25 %></p>
+
+<p><label for="password"><%=l(:field_password)%> <span class="required">*</span></label>
+<%= password_field_tag 'password', nil, :size => 25 %><br />
+<em><%= l(:text_caracters_minimum, :count => Setting.password_min_length) %></em></p>
+
+<p><label for="password_confirmation"><%=l(:field_password_confirmation)%> <span class="required">*</span></label>
+<%= password_field_tag 'password_confirmation', nil, :size => 25 %></p>
+<% end %>
+
+<p><label for="user_firstname"><%=l(:field_firstname)%> <span class="required">*</span></label>
+<%= text_field 'user', 'firstname' %></p>
+
+<p><label for="user_lastname"><%=l(:field_lastname)%> <span class="required">*</span></label>
+<%= text_field 'user', 'lastname' %></p>
+
+<p><label for="user_mail"><%=l(:field_mail)%> <span class="required">*</span></label>
+<%= text_field 'user', 'mail' %></p>
+
+<p><label for="user_language"><%=l(:field_language)%></label>
+<%= select("user", "language", lang_options_for_select) %></p>
+
+<% if Setting.openid? %>
+<p><label for="user_identity_url"><%=l(:field_identity_url)%></label>
+<%= text_field 'user', 'identity_url' %></p>
+<% end %>
+
+<% @user.custom_field_values.select {|v| v.editable? || v.required?}.each do |value| %>
+ <p><%= custom_field_tag_with_label :user, value %></p>
+<% end %>
+<!--[eoform:user]-->
+</div>
+
+<%= recaptcha_tags :public_key => Setting.plugin_redmine_recaptcha['recaptcha_public_key'], :ssl => true %>
+
+<%= submit_tag l(:button_submit) %>
+<% end %>
diff --git a/app/views/settings/_redmine_recaptcha.rhtml b/app/views/settings/_redmine_recaptcha.rhtml
new file mode 100644
index 0000000..01a32ed
--- /dev/null
+++ b/app/views/settings/_redmine_recaptcha.rhtml
@@ -0,0 +1,13 @@
+<table>
+ <tr>
+ <td colspan="2">Sign up for a <a href="http://www.google.com/recaptcha">reCAPTCHA</a> account, then set keys below.</td>
+ </tr>
+ <tr>
+ <td>Private Key</td>
+ <td><%= text_field_tag("settings[recaptcha_private_key]", @settings['recaptcha_private_key'], :size => 52 ) %></td>
+ </tr>
+ <tr>
+ <td>Public Key</td>
+ <td><%= text_field_tag("settings[recaptcha_public_key]", @settings['recaptcha_public_key'], :size => 52 ) %></td>
+ </tr>
+</table>
diff --git a/init.rb b/init.rb
new file mode 100644
index 0000000..da8abcd
--- /dev/null
+++ b/init.rb
@@ -0,0 +1,32 @@
+# Rails plugin initialization.
+
+require 'recaptcha'
+require 'net/http'
+require 'recaptcha/rails'
+require 'redmine'
+require 'dispatcher'
+
+Dispatcher.to_prepare :redmine_recaptcha do
+ require_dependency 'recaptcha/client_helper'
+ require_dependency 'client_helper_patch'
+ Recaptcha::ClientHelper.send(:include, ClientHelperPatch)
+
+ require_dependency 'account_controller'
+ require_dependency 'account_controller_patch'
+ AccountController.send(:include, AccountControllerPatch)
+end
+
+Redmine::Plugin.register :redmine_recaptcha do
+ name 'reCAPTCHA for user self registration'
+ author 'Shane StClair'
+ description 'Adds a recaptcha to the user self registration screen to combat spam'
+ version '0.1.0'
+ url 'http://github.com/srstclair/redmine_recaptcha'
+ #requires_redmine :version_or_higher => '0.9.0'
+ settings :default => {
+ 'recaptcha_private_key' => '',
+ 'recaptcha_public_key' => ''
+ }, :partial => 'settings/redmine_recaptcha'
+
+end
+
diff --git a/lib/account_controller_patch.rb b/lib/account_controller_patch.rb
new file mode 100644
index 0000000..35b2d8c
--- /dev/null
+++ b/lib/account_controller_patch.rb
@@ -0,0 +1,51 @@
+module AccountControllerPatch
+ def self.included(base)
+ base.send(:include, InstanceMethods)
+
+ base.class_eval do
+ alias_method_chain :register, :recaptcha_verification
+ end
+ end
+
+ module InstanceMethods
+ def register_with_recaptcha_verification
+ redirect_to(home_url) && return unless Setting.self_registration? || session[:auth_source_registration]
+
+ if request.get?
+ session[:auth_source_registration] = nil
+ @user = User.new(:language => Setting.default_language)
+ else
+ @user = User.new(params[:user])
+ @user.admin = false
+ @user.register
+ if session[:auth_source_registration]
+ @user.activate
+ @user.login = session[:auth_source_registration][:login]
+ @user.auth_source_id = session[:auth_source_registration][:auth_source_id]
+ if @user.save
+ session[:auth_source_registration] = nil
+ self.logged_user = @user
+ flash[:notice] = l(:notice_account_activated)
+ redirect_to :controller => 'my', :action => 'account'
+ end
+ else
+ @user.login = params[:user][:login]
+ @user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
+ if verify_recaptcha( :private_key => Setting.plugin_redmine_recaptcha['recaptcha_private_key'], :model => @user, :message => "There was an error with the recaptcha code below. Please re-enter the code and click submit." )
+ case Setting.self_registration
+ when '1'
+ register_by_email_activation(@user)
+ when '3'
+ register_automatically(@user)
+ else
+ register_manually_by_administrator(@user)
+ end
+ end
+ end
+
+ #the old method is accessible here:
+ #register_without_recaptcha_verification
+ end
+ end
+ end
+end
diff --git a/lib/client_helper_patch.rb b/lib/client_helper_patch.rb
new file mode 100644
index 0000000..c0488e4
--- /dev/null
+++ b/lib/client_helper_patch.rb
@@ -0,0 +1,16 @@
+module ClientHelperPatch
+ def self.included(base)
+ base.send(:include, InstanceMethods)
+ base.class_eval do
+ alias_method_chain :recaptcha_tags, :flash_remove
+ end
+ end
+
+ module InstanceMethods
+ def recaptcha_tags_with_flash_remove(options={})
+ html = recaptcha_tags_without_flash_remove( options )
+ flash.delete( :recaptcha_error )
+ return html
+ end
+ end
+end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/redmine-recaptcha.git
More information about the Pkg-ruby-extras-commits
mailing list