All Projects → IcaliaLabs → acts_as_user

IcaliaLabs / acts_as_user

Licence: MIT license
A gem which handles multiple types of users on a rails app

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to acts as user

Milia
Easy multi-tenanting for Rails5 (or Rails4) + Devise
Stars: ✭ 326 (+1258.33%)
Mutual labels:  gem, devise
Devise masquerade
Extension for devise, enable login as functionality. Add link to the masquerade_path(resource) and use it.
Stars: ✭ 380 (+1483.33%)
Mutual labels:  gem, devise
Graphql devise
GraphQL interface on top devise_token_auth
Stars: ✭ 100 (+316.67%)
Mutual labels:  gem, devise
Unimidi
Realtime MIDI IO for Ruby
Stars: ✭ 229 (+854.17%)
Mutual labels:  gem
Api Fuzzer
API Fuzzer which allows to fuzz request attributes using common pentesting techniques and lists vulnerabilities
Stars: ✭ 238 (+891.67%)
Mutual labels:  gem
schked
Framework agnostic scheduler to run recurring jobs.
Stars: ✭ 78 (+225%)
Mutual labels:  gem
react-devise-token-auth-sample
React on Rails using devise_token_auth for authentication
Stars: ✭ 25 (+4.17%)
Mutual labels:  devise
Localer
Automatic detecting missing I18n translations tool.
Stars: ✭ 219 (+812.5%)
Mutual labels:  gem
vrt-ruby
Ruby library for interacting with Bugcrowd's VRT
Stars: ✭ 15 (-37.5%)
Mutual labels:  gem
omniauth-multi-provider-saml
An extension to omniauth-saml for handling multiple identity providers
Stars: ✭ 14 (-41.67%)
Mutual labels:  gem
graphql authorize
Authorization helpers for ruby-graphql fields
Stars: ✭ 23 (-4.17%)
Mutual labels:  gem
Forest Rails
🌱 Rails Liana for Forest Admin
Stars: ✭ 247 (+929.17%)
Mutual labels:  gem
lightly
Ruby file cache for performing heavy tasks, lightly.
Stars: ✭ 37 (+54.17%)
Mutual labels:  gem
Victor
Ruby SVG Image Builder
Stars: ✭ 237 (+887.5%)
Mutual labels:  gem
google holiday calendar
Get holidays via Google Calendar.
Stars: ✭ 21 (-12.5%)
Mutual labels:  gem
Localeapp
Send and retrieve your ruby i18n localizations to the Locale translation service
Stars: ✭ 225 (+837.5%)
Mutual labels:  gem
slackify
Build Slackbot on Rails using Slack Event API
Stars: ✭ 20 (-16.67%)
Mutual labels:  gem
devise-uncommon password
Devise extension to prevent users from using a common password.
Stars: ✭ 24 (+0%)
Mutual labels:  devise
memo wise
The wise choice for Ruby memoization
Stars: ✭ 486 (+1925%)
Mutual labels:  gem
ibandit
Convert national banking details into IBANs, and vice-versa.
Stars: ✭ 90 (+275%)
Mutual labels:  gem

Acts as user

Build Status Code Climate Dependency Status Gem Version

Acts as user handles multiple user roles on a rails app. It uses polymorphic associations to relate other models and behave like a user.

Getting started

ActsAsUser 1.2.1 works with rails 3 onwards. You can add it to your Gemfile with:

gem 'acts_as_user'

Then run the bundle command to install it.

After you install ActsAsUser you need to run the generator:

rails g acts_as_user:install

The generator will install in initializer which describes all the ActsAsUser configuration options, so we recommend you take a look at it. When you are done you are ready to start your user model:

rails g acts_as_user User <attributes>

Next you'll probably want to run the migrations "rake db:migrate", as the generator will create a migration file (open it modify if you need to).

Configuration

For the models you want to inherit to you just have to add this line of code into them:

class Member
	acts_as_user
end

A little note on the User model...just in case!

class User
	is_user
end

Ignore attributes to delegate from the user

If you want to ignore some attributes from your user model to the childs, you can do it on the acts_as_user.rb initializer like so:

ActsAsUser.setup do |config|
	config.ignored_attributes = ["name", "bio"]
end

By default it ignores the following attributes:

["created_at", "updated_at", "id", "userable_type", "userable_id"]

Devise support

Yes we do!

Acts as a user plays well with Devise as it ignores and adds the corresponding attributes to delegate to.

When using devise, ActsAsUser will also ignore the encrypted_password attribute from the user. No further configuration needs to be done.

Getting to know the user

ActsAsUser gem now adds some handy instance user methods that returns true or false wheter the current user is a specific type or not, for example:

A simple configuration may look something similar to:

class User < ActiveRecord::Base
 is_user
end

class Customer < ActiveRecord::Base
 acts_as_user
end

class Admin < ActiveRecord::Base
 acts_as_user
end

Just a little configuration is needed, you can do it on the acts_as_user.rb initializer like so:

ActsAsUser.setup do |config|
	config.models_acting_as_users = [:admin, :customer]
end

Now we will instantiate a Customer object:

customer = Customer.find(1)
current_user = customer.user

You now should be able to detect in this case if the current_user is wheter an admin or a customer by simply calling:

current_user.customer?
 => true
current_user.admin?
 => false

Enjoy!

Contributing

  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

Psst! Here is a live example in rails

Rails acts as user example

Devs

Future

  • Support for Mongoid
  • Add wiki

Credits

Icalia Labs - [email protected]

Follow us

Like us on Facebook

License

MIT License. Copyright 2012-2013 IcaliaLabs. http://icalialabs.com

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].