Skip to content

Commit

Permalink
base release
Browse files Browse the repository at this point in the history
  • Loading branch information
giano committed Feb 23, 2011
1 parent 626941a commit 2c0731f
Show file tree
Hide file tree
Showing 35 changed files with 1,212 additions and 61 deletions.
13 changes: 1 addition & 12 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,2 @@
source "http://rubygems.org"
# Add dependencies required to use your gem here.
# Example:
# gem "activesupport", ">= 2.3.5"
source 'http://rubygems.org'

# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.2"
gem "rcov", ">= 0"
end
23 changes: 23 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
GEM
remote: http://rubygems.org/
specs:
git (1.2.5)
jeweler (1.5.2)
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
mime-types (1.16)
moonshado-sms (1.1.0)
rest-client (= 1.6.0)
yajl-ruby (= 0.7.7)
rake (0.8.7)
rest-client (1.6.0)
mime-types (>= 1.16)
yajl-ruby (0.7.7)

PLATFORMS
ruby

DEPENDENCIES
jeweler (>= 1.5.2)
moonshado-sms (>= 1.1.0)
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2011 Stefano Valicchia

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.
56 changes: 55 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
= devise_sms_activable

Description goes here.
Devise Sms Activable is a snap-in for Devise that will make any resource activable via SMS.
The user will receive an SMS with a token that can be entered on the site to activate the account.
Ask the user his phone (and phone confirmation to double check) on registration and the token will be sended automagically.

== Installation for Rails ~> 3.0 and Devise ~> 1.1

Install DeviseSmsActivable gem, it will also install dependencies (such as devise and warden):

gem install devise_sms_activable

Add DeviseSmsActivable to your Gemfile (and Devise if you weren't using them):

gem 'devise', '>= 1.1.0'
gem 'devise_sms_activable', '~> 0.0.9'

=== Automatic installation

Run the following generator to add DeviseSmsActivable’s configuration option in the Devise configuration file (config/initializers/devise.rb) and the sms sender class in your lib folder:

rails generate devise_sms_activable:install

When you are done, you are ready to add DeviseSmsActivable to any of your Devise models using the following generator:

rails generate devise_sms_activable MODEL

Replace MODEL by the class name you want to add DeviseSmsActivable, like User, Admin, etc. This will add the :sms_activable flag to your model's Devise modules. The generator will also create a migration file (if your ORM support them). Continue reading this file to understand exactly what the generator produces and how to use it.

== Configuring views

All the views are packaged inside the gem. If you'd like to customize the views, invoke the following generator and it will copy all the views to your application:

rails generate devise_sms_activable:views

You can also use the generator to generate scoped views:

rails generate devise_sms_activable:views users

Please refer to {Devise's README}[http://github.com/plataformatec/devise] for more information about views.

== Usage

The model is specular to the Devise's own Confirmable model. It only requires the user to supply a valid phone number.

On registration it will send an SMS with a token to be inserted to complete activation process.
By default users MUST activate by SMS before entering.
If you want something more "relaxed" just override <tt>sms_confirmation_required?</tt> in your model and make it your way.
You can use the convenience filter <tt>require_sms_activated!</tt> in your controller to block sms-unactive users from specific pages.

== Controller filter

DeviseSmsActivable extends your controllers with a <tt>require_sms_activated!</tt> method. Use it to restrict part of the site to "confirmed users" only

== I18n

DeviseSmsActivable installs a localizable file in your config/locales folder.

== Contributing to devise_sms_activable

Expand Down
56 changes: 12 additions & 44 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,53 +1,21 @@
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'

require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "devise_sms_activable"
gem.homepage = "http://github.com/giano/devise_sms_activable"
gem.license = "MIT"
gem.summary = %Q{TODO: one-line summary of your gem}
gem.description = %Q{TODO: longer description of your gem}
gem.email = "stefano.valicchia@gmail.com"
gem.authors = ["Stefano Valicchia"]
# Include your dependencies below. Runtime dependencies are required when using your gem,
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
# gem.add_development_dependency 'rspec', '> 1.2.3'
end
Jeweler::RubygemsDotOrgTasks.new
require 'bundler'
Bundler::GemHelper.install_tasks

require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.pattern = 'test/**/*_test.rb'
test.verbose = true
end

require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end

task :default => :test
desc 'Default: run tests for all ORMs.'
task :default => :tests

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "devise_sms_activable #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
desc 'Run Devise tests for all ORMs.'
task :tests do
Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file|
orm = File.basename(file).split(".").first
system "rake test DEVISE_ORM=#{orm}"
end
end
39 changes: 39 additions & 0 deletions app/controllers/devise/sms_activations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Devise::SmsActivationsController < ApplicationController
include Devise::Controllers::InternalHelpers

# GET /resource/sms_activation/new
def new
build_resource({})
render_with_scope :new
end

# POST /resource/sms_activation
def create
self.resource = resource_class.send_sms_token(params[resource_name])

if resource.errors.empty?
set_flash_message :notice, :send_token, :phone => self.resource.phone
redirect_to new_session_path(resource_name)
else
render_with_scope :new
end
end

# GET /resource/sms_activation/insert
def insert
build_resource({})
end

# GET or POST /resource/sms_activation/consume?sms_token=abcdef
def consume
self.resource = resource_class.confirm_by_sms_token(params[:sms_token])

if resource.errors.empty?
set_flash_message :notice, :confirmed
sign_in_and_redirect(resource_name, resource)
else
render_with_scope :new
end
end

end
11 changes: 11 additions & 0 deletions app/views/devise/sms_activations/insert.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h2>Insert SMS Token</h2>

<%= form_for(resource, :as => resource_name, :url => consume_sms_activation_path(resource_name), :html => { :method => :post }) do |f| %>

<p><%=label_tag :sms_token %><br />
<%=text_field_tag :sms_token, "", :maxlength => 5%></p>

<p><%= f.submit "Activate" %></p>
<% end %>
<%= render :partial => "devise/shared/links" %>
12 changes: 12 additions & 0 deletions app/views/devise/sms_activations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h2>Resend SMS Token</h2>

<%= form_for(resource, :as => resource_name, :url => sms_activation_path(resource_name), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>

<p><%= f.label :email %><br />
<%= f.email_field :email %></p>

<p><%= f.submit "Resend SMS" %></p>
<% end %>
<%= render :partial => "devise/shared/links" %>
15 changes: 15 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
en:
errors:
messages:
no_phone_associated: "No phone associated"
sms_already_confirmed: "This token has been already used"
sms_token_invalid: "was not locked"
devise:
sms_activations:
send_token: 'An activation token was sent by SMS to %{phone}.'
sms_token_invalid: 'The sms token provided is not valid!'
confirmed: 'Your account has been activated. You are now signed in.'
sms_activation_required: 'SMS Activation is required'
sms_body: 'Your Activation Token is %{sms_confirmation_token}.'
unconfirmed_sms: 'Your account need to be activated with an SMS token'

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>documents</key>
<array>
<dict>
<key>name</key>
<string>devise_sms_activable</string>
<key>regexFolderFilter</key>
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
<key>selected</key>
<true/>
<key>sourceDirectory</key>
<string></string>
</dict>
</array>
<key>fileHierarchyDrawerWidth</key>
<integer>200</integer>
<key>metaData</key>
<dict/>
<key>showFileHierarchyDrawer</key>
<false/>
<key>windowFrame</key>
<string>{{210, 184}, {1362, 746}}</string>
</dict>
</plist>
Binary file added devise_sms_activable-0.0.8.gem
Binary file not shown.
Binary file added devise_sms_activable-0.0.9.gem
Binary file not shown.
35 changes: 35 additions & 0 deletions devise_sms_activable.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- encoding: utf-8 -*-
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
require 'devise_sms_activable/version'

Gem::Specification.new do |s|
s.name = "devise_sms_activable"
s.version = DeviseSmsActivable::VERSION.dup
s.platform = Gem::Platform::RUBY
s.authors = ["Stefano Valicchia"]
s.email = ["stefano.valicchia@gmail.com"]
s.homepage = "https://github.com/giano/devise_sms_activable"
s.summary = "An SMS based activation strategy for Devise"
s.description = "It adds support for sending activation tokens via SMS and accepting them."
s.files = Dir["{app,config,lib}/**/*"] + %w[LICENSE README.rdoc]
s.require_path = "lib"
s.rdoc_options = ["--main", "README.rdoc", "--charset=UTF-8"]

s.required_ruby_version = '>= 1.8.6'
s.required_rubygems_version = '>= 1.3.6'

{
'bundler' => '~> 1.0.7',
'rspec-rails' => '~> 2.5.0'
}.each do |lib, version|
s.add_development_dependency(lib, version)
end

{
'rails' => '~> 3.0.0',
'devise' => '>= 1.1.0'
}.each do |lib, version|
s.add_runtime_dependency(lib, version)
end

end
Loading

0 comments on commit 2c0731f

Please sign in to comment.