Sha256: 6ef20e23857ea6ffc505460b8ab55c6225e704abd5c3ce9416bdcbeb25be21b1

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

# Authentication

We use the gem Devise for authentication. In this example, two different user types will be set up:
Admin and normal User. Only admins have access to the headmin back office. It is optional if normal users
are allowed to login/register from the website.

##Installation

#### Setup devise
Add the gem devise and bundle install. Create a user model:

```
rails generate devise User
```

Add the field "type" to the user model
```
rails g migration AddTypeToUsers type:string
rails db:migrate
```

In models/ add the file admin.rb
```
class Admin < User
end
```

#### Setup routes
In routes.rb
```
namespace(:admin) do
    devise_for :admins, path: 'users', singular: 'admin', controllers: {
        sessions: 'admin/users/sessions',
        registrations: 'admin/users/registrations',
        passwords: 'admin/users/passwords',
        unlocks: 'admin/users/unlocks',
        confirmations: 'admin/users/confirmations',
    }
end
```

In case, no normal users are necessary, you can discard the next step:
``` 
scope module: 'website' do
    devise_for :users, controllers: {
        sessions: 'website/users/sessions',
        registrations: 'website/users/registrations',
        passwords: 'website/users/passwords',
        unlocks: 'website/users/unlocks',
        confirmations: 'website/users/confirmations',
    }
end
```

#### Setup protected routes and configuration for headmin
In controllers/admin_controller.rb
```
class AdminController < ApplicationController
  alias_method :devise_current_user, :current_user
  include Headmin::Authentication
end
```

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
headmin-0.1.2 docs/devise.md
headmin-0.1.1 docs/devise.md