currentuser-services

Offsite sign up and sign in forms for Currentuser.io.

If you want to manage your own sign_up, sign_in and sign_out actions you should use the gem currentuser-data instead.

Configuration

Create your project on Currentuser.io.

Add currentuser-services gem in your Gemfile:

# Gemfile
gem 'currentuser-services'

Add an initializer file:

# config/initializers/currentuser.rb (the exact name of the file has no impact)
Currentuser::Services.configure do |config|
  config.project_id = 'your_project_id'
end

Call currentuser in your routes definition:

# config/routes.rb
MyApplication::Application.routes.draw do
  currentuser
end

Usage

That’s all! Note that:

Example

Routes

# config/routes.rb
MyApplication::Application.routes.draw do
  root 'main#index'
  get :restricted, to: 'main#restricted'
  currentuser
end

Controller

class MainController < ApplicationController
  before_action :require_currentuser, only: :restricted
end

Views

-# views/home/index.html.haml
= render 'shared/menu'

%h1
  Welcome!
-# views/home/restricted.html.haml
= render 'shared/menu'

%h1
  Welcome back to this restricted area, #{currentuser_id}
-# views/shared/_menu.html.haml
%ul
  %li
    = link_to 'Home', :root
  - if currentuser_id
    %li
      = link_to 'Restricted', :restricted
    %li
      = button_to 'Sign out', currentuser_sign_out_url, method: :delete
  - else
    %li
      = link_to 'Sign up', currentuser_sign_up_url
    %li
      = link_to 'Sign in', currentuser_sign_in_url

Contributing to currentuser-services (not recommended yet)

Tests

TBD

Copyright © 2014 eric-currentuser. See LICENSE.txt for further details.