Giter VIP home page Giter VIP logo

devise_invitable's Introduction

devise_invitable

It adds support to devise for send invitations by email (it requires to be authenticated) and accept the invitation setting the password.

Installation

All gems are on gemcutter, so you need to add gemcutter to your sources if you haven’t yet:

sudo gem sources -a http://gemcutter.org/

Install devise_invitable gem, it should install dependencies (such as devise and warden):

sudo gem install devise_invitable

Configure devise_invitable inside your app (and warden and devise if you weren’t using them):

config.gem 'warden'
config.gem 'devise'
config.gem 'devise_invitable'

Basic Usage

Follow the walkthrough for devise with the following modifications.

Add t.invitable to the migration:

create_table :users do
  ...
  t.invitable
  ...
end
add_index :users, :invitation_token # for invitable

Add :invitable to the devise line in your model:

class User < ActiveRecord::Base
  devise ..., :invitable
end

If you are using devise :all, you can add :invitable to config.all in devise initializer:

Devise.setup do |config|
  ...
  config.all = [..., :invitable]
  ...
end

Model configuration

DeviseInvitable adds a new configuration option, :invite_for. It’s the time a invitation is valid for. Default value is nil, which means invitation doesn’t expire.

Controller filters

It adds authenticate_resource! filter to restrict who can send invitations. You can override this method in your ApplicationController. Default behavior is require authentication of the same resource_name, so if you only have a model with devise it will allow to all authenticated users to send invitations.

You have to configure mailer as it’s required for confirmable and recoverable.

I18n

It uses two flash messages, :send_invitation and :updated, which are translated as other flash messages from devise.

Adding Invitable to a running application

Define a migration to add invitable to your model:

change_table :your_table do |t|
  t.string :invitation_token, :limit => 20
  t.datetime :invitation_sent_at
  t.index :invitation_token
end

# Allow null encrypted_password and password_salt
change_column :your_table, :encrypted_password, :string, :null => true
change_column :your_table, :password_salt, :string, :null => true

Add :invitable to the devise line of your model, or to config.all in devise initializer if your model uses devise :all.

Override authenticate_resource! filter if you need to customize who can send invitations.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2009 Sergio Cambra. See LICENSE for details.

devise_invitable's People

Contributors

emk avatar harrikauhanen avatar jdewyea avatar jsmestad avatar pelle avatar rymai avatar tessro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jackdempsey

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.