<commit_before># Monban 門番

[![Build Status](https://travis-ci.org/halogenandtoast/monban.png?branch=master)](https://travis-ci.org/halogenandtoast/monban)
[![Code Climate](https://codeclimate.com/github/halogenandtoast/monban.png)](https://codeclimate.com/github/halogenandtoast/monban)


Monban is designed to be very simple and extensible user authentication. It's goal is to give all the power to the developer instead of
forcing them to make Monban work with their system

# Why use Monban?

Monban makes authentication simple:

- Uses warden
- Provides convenient controller helpers
- Provides a rails generator for default controllers and views
- TODO: Very customizable

Monban doesn't do the following:

- Doesn't automatically add routes to your application
- Doesn't force you to use engine based controllers or views
- Doesn't require you to make changes to your user model


## Installation

Monban was designed to work with Rails > 4.0. Add this line to your Gemfile:

    gem 'monban'

Then inside of your ApplicationController add the following:

    include Monban::ControllerHelpers

You may also generate a scaffold to start with:

    rails g monban:scaffold

This will generate a bare bones starting point. If you don't want the full stack you can just generate some controllers with:

    rails g monban:controllers

## Usage

Monban does currently have some out of the box expectations, but you can configure any of these:

- By default the model should be called `User`
- You should have an `email` and `password_digest` column on your `User`
- Passwords will be run through BCrypt

### Controller Additions

Monban provides the following controller methods:

- `sign_in(user)`
- `sign_out`
- `sign_up(user)`
- `authenticate_session(session_params)`
- `authenticate(user, password)`

These helpers:

- `current_user`
- `signed_in?`

And this filter:

- `require_login`

## Usage in Tests

### Test mode

Monban provides the follow:

```ruby
Monban.test_mode!
```

Which will change password encryption to provide plaintext responses instead of using BCrypt. This will allow you to write factories using the password_digest field:

```ruby
FactoryGirl.define do
  factory :user do
    username 'wombat'
    password_digest 'password'
  end
end
```

### Spec helpers

A couple of convenience methods are available in your tests.

```ruby
require 'monban/test/helpers'

RSpec.configure do |config|
  config.include Monban::Test::Helpers, type: :feature
end
```

## Advanced Functionality

You may perform a look up on a user using multiple fields by doing something like the following:

    class SessionsController < ApplicationController
      def create
        user = authenticate_session(session_params, email_or_username: [:email, :username])
        sign_in(user) do
          redirect_to(root_path) and return
        end
        render :new
      end

      private

      def session_params
        params.require(:session).permit(:email_or_username, :password)
      end

    end

This will allow the user to enter either their username or email to login

### Limitations

Here are a few of the current limitations of monban:

- Monban assumes you only have one user model.

## 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
<commit_msg>No longer considered a TODO.<commit_after># Monban 門番

[![Build Status](https://travis-ci.org/halogenandtoast/monban.png?branch=master)](https://travis-ci.org/halogenandtoast/monban)
[![Code Climate](https://codeclimate.com/github/halogenandtoast/monban.png)](https://codeclimate.com/github/halogenandtoast/monban)


Monban is designed to be very simple and extensible user authentication. It's goal is to give all the power to the developer instead of
forcing them to make Monban work with their system

# Why use Monban?

Monban makes authentication simple:

- Uses warden
- Provides convenient controller helpers
- Provides a rails generator for default controllers and views
- Very customizable

Monban doesn't do the following:

- Doesn't automatically add routes to your application
- Doesn't force you to use engine based controllers or views
- Doesn't require you to make changes to your user model


## Installation

Monban was designed to work with Rails > 4.0. Add this line to your Gemfile:

    gem 'monban'

Then inside of your ApplicationController add the following:

    include Monban::ControllerHelpers

You may also generate a scaffold to start with:

    rails g monban:scaffold

This will generate a bare bones starting point. If you don't want the full stack you can just generate some controllers with:

    rails g monban:controllers

## Usage

Monban does currently have some out of the box expectations, but you can configure any of these:

- By default the model should be called `User`
- You should have an `email` and `password_digest` column on your `User`
- Passwords will be run through BCrypt

### Controller Additions

Monban provides the following controller methods:

- `sign_in(user)`
- `sign_out`
- `sign_up(user)`
- `authenticate_session(session_params)`
- `authenticate(user, password)`

These helpers:

- `current_user`
- `signed_in?`

And this filter:

- `require_login`

## Usage in Tests

### Test mode

Monban provides the follow:

```ruby
Monban.test_mode!
```

Which will change password encryption to provide plaintext responses instead of using BCrypt. This will allow you to write factories using the password_digest field:

```ruby
FactoryGirl.define do
  factory :user do
    username 'wombat'
    password_digest 'password'
  end
end
```

### Spec helpers

A couple of convenience methods are available in your tests.

```ruby
require 'monban/test/helpers'

RSpec.configure do |config|
  config.include Monban::Test::Helpers, type: :feature
end
```

## Advanced Functionality

You may perform a look up on a user using multiple fields by doing something like the following:

    class SessionsController < ApplicationController
      def create
        user = authenticate_session(session_params, email_or_username: [:email, :username])
        sign_in(user) do
          redirect_to(root_path) and return
        end
        render :new
      end

      private

      def session_params
        params.require(:session).permit(:email_or_username, :password)
      end

    end

This will allow the user to enter either their username or email to login

### Limitations

Here are a few of the current limitations of monban:

- Monban assumes you only have one user model.

## 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

{'fraction_non_alphanumeric': 0.07482305358948432, 'fraction_numerical': 0.0020222446916076846, 'mean_word_length': 4.028322440087146, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3328019', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1924, 'n_words': 827}