Project

admin_auth

0.0
No commit activity in last 3 years
No release in over 3 years
A gem for rails that helps with basic database authentication.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 4.0.0
>= 3.0.0

Runtime

>= 3.0.0
>= 4.0.0
 Project Readme

AdminAuth

This is a small gem for rails that extracts simple admin database authentication functionality.

It is written in a way that will work with both ActiveRecord and Mongoid and any other ORM that has the methods all, new, create, where, update_attributes, destroy (And they work in the same fashion).

It requires adding a few things to your code, but handles all the things related to authentication on this basic level, including controllers, views, routing, password encryption (with BCrypt).

Installation

Add this line to your application's Gemfile:

gem 'admin_auth'

And then execute:

$ bundle

Or install it yourself as:

$ gem install admin_auth

Usage

To use this gem you need to do few things:

  1. Create an Admin model that has two fields:
    • email (string)
    • encrypted_password (string)
  2. Add the line admin_auth_routes to your routes.rb file.
  3. Now if you add before_action :authenticate_admin! to any controller it will send the user to the admin login page.
  4. To create an admin you will need to do it in the rails console: Admin.create(email: 'email@email.com', password: 'password', password_confirmation: 'password')
  5. Optionally, add an after_login_path(locale = nil) method to your ApplicationController that returns the path you want to redirect to when logged in.
  6. Optionally, add an after_logout_path(locale = nil) method to your ApplicationController that returns the path you want to redirect to after logout.
  7. Optionally, you can copy the views in the gem to app/views/admin and modify then how you see fit.

Contributing

  1. Fork it ( https://github.com/pboksz/admin_auth/fork )
  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 a new Pull Request