Git Product home page Git Product logo

acts_as_hoc_user's Introduction

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 protected]","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.

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.