RememberMe
RememberMe is a simple remember-me login solution on Rails. Manages generating and clearing a token for remembering the user from a saved cookie.
Installation
Add this line to your application's Gemfile:
gem 'remember_me'
And then execute:
$ bundle
Or install it yourself as:
$ gem install remember_me
Usage
controllers/application_controller.rb:
class ApplicationController < ActionController::Base
include RememberMe::Controller
end
models/user.rb:
class User < ActiveRecord::Base
include RememberMe::Model
end
if mongoid
class User
include Mongoid::Document
include RememberMe::Model
end
controllers/sessions_controller.rb:
class SessionsController < ApplicationController
def create
# ... authenticated ...
self.current_user = @user
remember_me(current_user) if remember_me?
redirect_to root_path, notice: 'Success'
end
def destroy
forget_me(current_user)
self.current_user = nil
redirect_to login_path, notice: 'Success'
end
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Author
License
MIT