No commit activity in last 3 years
No release in over 3 years
This gem makes it easy to authenticate a user by email and password
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16.a
~> 10.0

Runtime

~> 3.1.7
>= 0
 Project Readme

ActsAsHocUser

acts_as_hoc_user makes it easy to authenticate users.

Installation

Add this line to your application's Gemfile:

gem 'acts_as_hoc_user'

And then execute:

$ bundle

Or install it yourself as:

$ gem install acts_as_hoc_user

Usage

Generate model

You can create the model and table migration with the following generator:

$ rails generate acts_as_hoc_user:hoc_user NAME FIELDS

Eg.

$ rails generate acts_as_hoc_user:hoc_user user age:integer phone_number:string address:string zip:string

Which will generate the following migration:

#db/migration/xxxxxxxxxxxx_create_users.rb
class CreateUsers < ActiveRecord::Migration[5.0]
  def self.up
    create_table :users do |t|
      t.string :email, index: {unique: true}, null: false
      t.string :password_digest
      t.string :name
      t.integer :age
      t.string :phone_number
      t.string :address
      t.string :zip
      t.timestamps
    end
  end

  def self.down
    drop_table :users
  end
end

and model

#app/model/user.rb
class User < ActiveRecord::Base
  acts_as_hoc_user
end

and initializer

#config/initializers/acts_as_hoc_user.rb
ActsAsHocUser.configure do |config|
  config.min_password_length = 6
  config.acts_as_hoc_user_secret = 'a very secret string'
end

Manual usage

If you prefer you can create the model yourself. Just make sure that the model has email:string, name:string and password_digest:string fields and add acts_as_hoc_user to the model

Authenticate user

Authenticate and get JWT token

auth_token = User.authenticate_with_credentials("email@test.com","s3cr3t")

Authenticate with JWT token

user = User.authenticate_with_authentication_token(auth_token)

Authenticate with http headers

user = User.authenticate_with_headers(request.headers)

Licence

The gem is available as open source under the terms of the MIT License.