recaptcha plugin

also some UI fixes for the plugin page

Change-Id: I161c458756c20e034c29d4515801fd9f6427aa53
Reviewed-on: https://gerrit.instructure.com/2093
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Ryan Shaw <ryan@instructure.com>
This commit is contained in:
Brian Whitmer 2011-01-29 11:46:09 -07:00
parent b866a18699
commit 629805db3c
14 changed files with 158 additions and 23 deletions

View File

@ -304,11 +304,11 @@ class UsersController < ApplicationController
# If a teacher created the student, and the student then comes to register, they
# should still be allowed to.
if @active_cc && @active_cc.user && !@pseudonym.user
@user = @active_cc.user
@user ||= @active_cc.user
elsif @any_cc && @any_cc.user && !@pseudonym.user
@user = @any_cc.user
@user ||= @any_cc.user
elsif @pseudonym && (!@pseudonym.user || @pseudonym.user.creation_pending?)
@user = @pseudonym.user
@user ||= @pseudonym.user
else
# If not creation_pending, we want to throw an already_exists error, which
# we'll get if we set this to nil, since then a few lines down will try to
@ -318,7 +318,7 @@ class UsersController < ApplicationController
@user ||= User.new
@user.attributes = params[:user]
@user.name ||= params[:pseudonym][:unique_id]
if @user.save
if @user.errors.empty? && @user.save
@pseudonym ||= @user.pseudonyms.build
@pseudonym.attributes = params[:pseudonym]
@pseudonym.account_id = @domain_root_account.id

View File

@ -13,7 +13,30 @@ body.modal
margin: 0
padding: 0
#modal-box
#modal-box-top
background: url(/images/login-bg.jpg) no-repeat
width: $modal_box_width
height: 10px
overflow: hidden
margin: 75px auto 0
padding: 10px 20px 0 20px
position: relative
#modal-box-bottom
background: url(/images/login-bg.jpg) no-repeat bottom center
width: $modal_box_width
height: 9px
overflow: hidden
margin: 0 auto 0
padding: 0px 20px 10px 20px
position: relative
#modal-box-arbitrary-size
margin-top: -30px !important
padding-top: 0 !important
height: auto !important
background-image: url(/images/login-bg-middle-tall.jpg) !important
#register_form
margin-top: 40px
#modal-box,#modal-box-arbitrary-size
background: url(/images/login-bg.jpg) no-repeat
width: $modal_box_width
height: 358px

View File

@ -0,0 +1,16 @@
table.plugins
border-collapse: collapse
th
border-bottom: 1px dotted #888
text-align: left
font-weight: bold
padding-left: 5px
td
border-bottom: 1px dotted #ccc
padding: 2px 5px
&.name
font-size: 1.2em
font-weight: bold
padding-right: 10px
&.description,&.tag
font-size: 0.8em

View File

@ -1,3 +1,10 @@
<% content_for :page_title do %>Canvas Plugins<% end %>
<%
add_crumb 'Plugins'
jammit_css 'plugins'
%>
<h2>Canvas Plugins</h2>
<% if @plugins.any? %>
@ -5,17 +12,18 @@
<tr>
<th>Name</th>
<th>Description</th>
<th>tag</th>
<th>Tag</th>
<th>Website</th>
<th>Author</th>
<th>Version</th>
<th>&nbsp;</th>
</tr>
<% @plugins.each do |plugin| %>
<tr class="<%= cycle('odd', 'even') %>">
<td><span class="name"><%= h plugin.name %></span></td>
<td><%= content_tag('span', h(plugin.description), :class => 'description') unless plugin.description.blank? %></td>
<td><%= h plugin.tag %></td>
<td><%= content_tag('span', link_to(h(plugin.website), plugin.website), :class => 'url') unless plugin.website.blank? %></td>
<td class='name'><span class="name"><%= h plugin.name %></span></td>
<td class='description'><%= content_tag('span', h(plugin.description), :class => 'description') unless plugin.description.blank? %></td>
<td class='tag'><%= h plugin.tag %></td>
<td class='website'><%= content_tag('span', link_to(h(plugin.website), plugin.website), :class => 'url') unless plugin.website.blank? %></td>
<td class="author"><%= plugin.author_website.blank? ? h(plugin.author) : link_to(h(plugin.author), plugin.author_website) %></td>
<td class="version"><%= h plugin.version %></td>
<td class="configure"><%= link_to("Configure", plugin_path(plugin.id)) if plugin.has_settings_partial? %></td>

View File

@ -1,4 +1,10 @@
<h2>Settings: <%=h @plugin.name %></h2>
<% content_for :page_title do %>Plugin Settings: <%=h @plugin.name %><% end %>
<%
add_crumb('Plugins', plugins_path)
add_crumb(@plugin.name)
%>
<h2>Plugin Settings: <%=h @plugin.name %></h2>
<%= render :partial => "settings_header" %>
@ -6,11 +12,14 @@
<% form_for(@plugin_setting, :url => plugin_path(@plugin.id), :html => {:method => :put}) do |f| %>
<% partial = render :partial => @plugin.settings_partial, :locals => {:settings => @plugin_setting.settings.merge(params[:settings] || {})} %>
<%= f.error_messages if !@error_messages_handled %>
<div class="box tabular">
<div class="box tabular">
<%= partial %>
</div>
<%= submit_tag "Apply" %>
</div>
<div class='button-container'>
<button type="submit" class="button">Apply</button>
<%=link_to("Return to plugins list", plugins_path,:class => 'button button-secondary')%>
</div>
<% end %>
</div>
<p><%=link_to("Return to plugins list", plugins_path)%></p>
<p></p>

View File

@ -43,14 +43,30 @@ $(function(){
});
</script>
<% end %>
<div id="modal-box" class="modal-box-tall">
<div style="margin: 120px 80px 0; position: relative;">
<h2>Register a new account</h2>
<div id="modal-box-top"></div>
<div id="modal-box-arbitrary-size">
<div style="margin: 30px 80px 0; position: relative;">
<h2>Register for a new account</h2>
<% form_for @pseudonym, :url => users_path, :html => {:id => "register_form", :method => :post} do |form| %>
<input type="hidden" name="new_teacher" value="1"/>
<span class="field-with-fancyplaceholder"><%= label :user, :name, "Your name" %><%= text_field :user, :name, :class => "text" %></span>
<span class="field-with-fancyplaceholder"><%= form.label :unique_id, "Email address" %><%= form.text_field :unique_id, :class => "text", :value => !@pseudonym || @pseudonym.deleted? ? (@pseudonym.deleted_unique_id rescue nil) : @pseudonym.unique_id %></span>
<button type="submit" class="button">Register</button>
<table>
<tr>
<td colspan="2">
<input type="hidden" name="new_teacher" value="1"/>
<span class="field-with-fancyplaceholder"><%= label :user, :name, "Your name" %><%= text_field :user, :name, :class => "text" %></span>
<span class="field-with-fancyplaceholder"><%= form.label :unique_id, "Email address" %><%= form.text_field :unique_id, :class => "text", :value => !@pseudonym || @pseudonym.deleted? ? (@pseudonym.deleted_unique_id rescue nil) : @pseudonym.unique_id %></span>
</td>
</tr>
<% Canvas::Plugin.all_for_tag('registration_form').each do |plugin| %>
<%= render :partial => plugin.settings[:registration_partial] %>
<% end %>
<tr>
<td colspan="2">
<button type="submit" class="button">Register</button>
</td>
</tr>
</table>
<% end %>
</div>
<div class="clear"></div>
</div>
<div id="modal-box-bottom"></div>

View File

@ -200,6 +200,8 @@ stylesheets:
speed_grader:
- public/stylesheets/static/ui.selectmenu.css
- public/stylesheets/compiled/speed_grader.css
plugins:
- public/stylesheets/compiled/plugins.css
gradebook_uploads:
- public/stylesheets/static/slick.grid.css
- public/stylesheets/compiled/gradebook_uploads.css

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -0,0 +1 @@
gem 'recaptcha', '0.3.1', :require => 'recaptcha/rails'

View File

@ -0,0 +1,23 @@
<% fields_for :settings, OpenObject.new(settings) do |f| %>
<table style="width: 500px;">
<tr>
<td colspan="2" style="padding-bottom: 20px;">
<p>Before you can use the ReCaptcha plugin you'll need to
<a href="https://www.google.com/recaptcha/admin">sign up for an account on ReCaptcha.</a>
Make sure to set your domain correctly to handle your site domain(s). After
you've set up an account, enter your public and private keys below.
</p>
<p><b>Note:</b> any changes you make to these settings won't be
updated until you restart your server.</p>
</td>
</tr>
<tr>
<td><%= f.label :public_key, "ReCaptcha Public Key:" %></td>
<td><%= f.text_field :public_key %></td>
</tr>
<tr>
<td><%= f.label :private_key, "ReCaptcha Private Key:" %></td>
<td><%= f.text_field :private_key %></td>
</tr>
</table>
<% end %>

View File

@ -0,0 +1,8 @@
<% plugin = Canvas::Plugin.find('registration_form_recaptcha') %>
<% if plugin && !plugin.settings[:public_key].blank? && !plugin.settings[:private_key].blank? %>
<tr>
<td colspan="2">
<%= recaptcha_tags(:public_key => plugin.settings[:public_key], :ssl => true) %>
</td>
</tr>
<% end %>

View File

@ -0,0 +1,7 @@
require 'recaptcha/rails'
require 'canvas/plugin'
Rails.configuration.to_prepare do
require_dependency 'users_controller_recaptcha'
require_dependency 'register_recaptcha_plugin'
end

View File

@ -0,0 +1,11 @@
plugin = Canvas::Plugin.register('registration_form_recaptcha', 'registration_form', {
:description => 'captcha plugin for the registration form',
:website => 'http://www.instructure.com',
:author => 'Instructure',
:author_website => 'http://www.instructure.com',
:version => 1.0,
:settings_partial => 'users/recaptcha_settings',
:settings => {
:registration_partial => 'users/registration_form_recaptcha'
}
})

View File

@ -0,0 +1,11 @@
UsersController.class_eval do
alias :create_original :create
def create
@user = User.new(params[:user])
recap = Canvas::Plugin.find('registration_form_recaptcha')
if recap && !recap.settings[:public_key].blank? && !recap.settings[:private_key].blank?
@user = nil if verify_recaptcha(:model => @user, :private_key => recap.settings[:private_key])
end
create_original
end
end