oa-recruitmilitary 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ Gemfile.lock
data/README.md CHANGED
@@ -2,6 +2,60 @@
2
2
 
3
3
  OmniAuth integration for RecruitMilitary Connect.
4
4
 
5
+ ## Rails Integration
6
+
7
+ ### Gemfile
8
+
9
+ gem 'omniauth'
10
+ gem 'devise', :git => "http://github.com/plataformatec/devise.git"
11
+
12
+ ### Devise
13
+
14
+ rails generate devise:install
15
+ rails generate devise MODEL
16
+
17
+ ### Initializer
18
+
19
+ Devise.setup do |config|
20
+ # ...
21
+ config.omniauth :recruitmilitary, RECRUITMILITARY_APP_ID, RECRUITMILITARY_SECRET
22
+ end
23
+
24
+ ### Routes
25
+
26
+ devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
27
+
28
+ ### Controllers
29
+
30
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
31
+ def recruitmilitary
32
+ @user = User.find_for_recruitmilitary_oauth(env["omniauth.auth"], current_user)
33
+
34
+ if @user.persisted?
35
+ flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "RecruitMilitary"
36
+ sign_in_and_redirect @user, :event => :authentication
37
+ else
38
+ session["devise.recruitmilitary_data"] = env["omniauth.auth"]
39
+ redirect_to new_user_registration_url
40
+ end
41
+ end
42
+ end
43
+
44
+ ### Models
45
+
46
+ class User < ActiveRecord::Base
47
+ devise :database_authenticatable, :rememberable, :omniauthable
48
+
49
+ def self.find_for_recruitmilitary_oauth(access_token, signed_in_resource=nil)
50
+ data = access_token['extra']
51
+ if user = User.find_by_email(data["email"])
52
+ user
53
+ else # Create an user with a stub password.
54
+ User.create!(:email => data["email"], :password => Devise.friendly_token[0,20])
55
+ end
56
+ end
57
+ end
58
+
5
59
  ## TODO
6
60
 
7
61
  * unit tests
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Recruitmilitary
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -1,3 +1,5 @@
1
+ require 'omniauth/strategies/recruitmilitary'
2
+
1
3
  module OmniAuth
2
4
  module RecruitMilitary
3
5
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oa-recruitmilitary
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Guterl
@@ -35,8 +35,8 @@ files:
35
35
  - Rakefile
36
36
  - lib/oa-recruitmilitary.rb
37
37
  - lib/omniauth/recruitmilitary.rb
38
- - lib/omniauth/recruitmilitary/strategies/recruitmilitary.rb
39
38
  - lib/omniauth/recruitmilitary/version.rb
39
+ - lib/omniauth/strategies/recruitmilitary.rb
40
40
  - oa-recruitmilitary.gemspec
41
41
  has_rdoc: true
42
42
  homepage: http://connect.recruitmilitary.com