Git Product home page Git Product logo

devise-verifiable's Introduction

DeviseVerifiable

Gem Version

DeviseVerifiable adds a second step to registration process.

This is useful to register users with additional information or verify the users identity through a third-party service such as BlockScore.

Instalation

Simply add DeviseVerifiable to your application's Gemfile:

gem 'devise'
gem 'devise-verifiable'

Configuration

DeviseVerifiable adds a configuration variable called fields_for_verification. It configures which fields will be filled in the verification step:

Devise.setup do |config|
  config.fields_for_verification = [:full_name, :address]
end

To include DeviseVerifiable in a model, add the verifiable module to Devise modules:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable, :verifiable
end

If you have multiple models configured with devise, define the fields for verification individually using the verify_fields method:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable, :verifiable

  verify_fields :full_name, :address
end

To restrict unverified users from access certain pages, use the helper :authenticate_verified_user!:

class HomeController < ApplicationController
  # Only verified users will have access to home controller actions
  before_action :authenticate_verified_user!

  # ...
end

Model

DeviseVerifiable will add some methods to your model:

#verified? -> this method will check if all fields used for verification are filled.

user = User.new

user.verified? # => false

user.full_name = 'Rodrigo Ra'
user.address = '555, Atomic Avenue'

user.verified? # => true

#valid_for_verification? -> this method will validate all fields used for verification and add errors messages for invalid fields. By default, it verifies if the fields are blank?

user = User.new

user.valid_for_verification? # => false
user.errors # => # <ActiveModel::Errors:0x007fe372bcc200 @base=...,
                 # @messages={:full_name=>["can't be blank"],
                 #            :address=>["can't be blank"]}>

user.full_name = 'Rodrigo Ra'
user.address = '555, Atomic Avenue'

user.valid_for_verification? # => true
user.errors.empty? # => true

#validate_for_verification -> You can customize the validation for fields.

Let's say that you need validate the zip_code:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable, :verifiable

  verify_fields :full_name, :address, :zip_code

  protected
    def validate_for_verification(field)
      if field == :zip_code
        # custom validation for zip_code
      else
        super
      end
    end
end

Customizing the verification

To use a third-party service to verify the user identity.

View

To customize the verification view, following the devise conventions, create a file in app/views/devise/verification called new.html.erb.

Controller

First, configure which controller you want to use in config/routes.rb:

devise_for :users, controllers: { verification: :custom_verification }

And create it (in this example, CustomVerificationController):

class CustomVerificationController << Devise::VerificationController

  def new
  end

  def create
  end

end

Example

This app exemplifies the usage of this gem.

Contributing

Questions or problems? Please post them on the issue tracker.

You can contribute by doing the following:

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

To test the application run bundle install and then rake test.

License

MIT License.

devise-verifiable's People

Contributors

ohrite avatar rodrigora avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

devise-verifiable's Issues

uninitialized constant Devise::Verifiable::Controller

Hl. i'm use ruby 2.5 and rails 5.2
when i installing the gem and run rails s or rails c it was error
uninitialized constant Devise::Verifiable::Controller
There was an error while trying to load the gem 'devise-verifiable'. (Bundler::GemRequireError) Gem Load Error is: uninitialized constant Devise::Verifiable::Controller

Does not work with Devise 4.4.1?

When I try and bundle and get 0.0.3, I get the following

Bundler could not find compatible versions for gem "devise":
  In snapshot (Gemfile.lock):
    devise (= 4.4.1)

  In Gemfile:
    devise-i18n was resolved to 1.6.0, which depends on
      devise (>= 4.4)

    devise-verifiable (~> 0.0.3) was resolved to 0.0.3, which depends on
      devise (~> 3.5)


Cannot use in Rails 5

Hi Rodrigora, when i try install this gem in my rails 5 app, show me this error:

Bundler could not find compatible versions for gem "devise":
In snapshot (Gemfile.lock):
devise (= 4.2.0)

In Gemfile:
devise

devise-verifiable was resolved to 0.0.1, which depends on
  devise (~> 3.5)

Running bundle update will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

This my Gemfile:

source 'https://rubygems.org'

Bundle edge Rails instead: gem 'rails', github: 'rails/rails'

gem 'rails', '5.0.0'

Use sqlite3 as the database for Active Record

gem 'sqlite3'

Use SCSS for stylesheets

gem "compass-rails"
gem 'sass-rails', '~> 5.0'

Use Uglifier as compressor for JavaScript assets

gem 'uglifier', '>= 1.3.0'

Use CoffeeScript for .coffee assets and views

gem 'coffee-rails', '~> 4.2'

See https://github.com/rails/execjs#readme for more supported runtimes

gem 'therubyracer', platforms: :ruby

gem 'rest-client'
gem 'rollbar'

Use jquery as the JavaScript library

gem 'jquery-rails'

Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks

gem 'turbolinks'
gem 'capistrano3-nginx', '> 2.0'
gem 'record_tag_helper', '
> 1.0'

Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder

gem 'jbuilder', '~> 2.5'

bundle exec rake doc:rails generates the API under doc/api.

gem 'sdoc', '~> 0.4.0', group: :doc

Images upload and proccessing

gem 'carrierwave'
gem 'mini_magick'
gem 'gon'
gem 'jquery-turbolinks'
gem "fog-aws"
gem 'kaminari'
gem 'groupdate'
gem "chartkick"
gem 'hightop'

gem "refile", require: "refile/rails"

gem "refile-mini_magick"

Semantic UI stylesheets css

gem 'semantic-ui-sass', github: 'doabit/semantic-ui-sass'
gem 'nokogiri'
gem 'premailer-rails'

Use ActiveModel has_secure_password

gem 'bcrypt'

I18n Translates

gem 'rails-i18n'

Use Unicorn as the app server

gem 'unicorn'

Use Capistrano for deployment

gem 'capistrano-rails', group: :development

Use Devise for user auth

gem 'devise'

group :development, :test do

Call 'byebug' anywhere in the code to stop execution and get a debugger console

gem 'byebug'
gem "better_errors"
end

group :development do

Access an IRB console on exception pages or by using <%= console %> in views

gem 'web-console', '> 2.0'
gem 'mysql2'
gem 'letter_opener_web', '
> 1.2.0'

Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring

gem 'spring'
gem 'capistrano'
gem 'capistrano3-puma'
gem 'capistrano-rails', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano-rvm'
gem 'capistrano-ext'
gem 'capistrano-rails-console'
end

group :production do
gem 'figaro'
gem 'puma'
gem 'mysql2'
gem 'rails_12factor'
gem 'redis', '~> 3.0'
end

gem 'devise-encryptable'
gem 'fog'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.