apit 0.0.35 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/apit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Apit
2
- VERSION = "0.0.35"
2
+ VERSION = "0.0.36"
3
3
  end
@@ -12,18 +12,14 @@ module Apit
12
12
  gem("simple_form")
13
13
  end
14
14
  #Devise
15
- if yes?("Would you like to use Devise for authentication?")
16
- gem("devise", :git => 'git://github.com/plataformatec/devise', :branch => 'master')
15
+ if yes?("Would you like to use OmniAuth authentication?")
17
16
  gem("omniauth")
18
- run('bundle install')
19
- generate("devise:install")
20
- template "user_token.rb", "app/models/user_token.rb"
17
+ generate("model", "provider:string uid:string name:string")
18
+ template "sessions_controller.rb", "app/controllers/sessions_controller.rb"
21
19
  template "user.rb", "app/models/user.rb"
22
-
23
- model_name = "user" if model_name.blank?
24
- generate("devise", model_name)
25
- generate("devise:views")
26
-
20
+ route("match \"/auth/:provider/callback\" => \"sessions#create\"")
21
+ route("match \"/signout\" => \"sessions#destroy\", :as => :signout\"")
22
+ template "omniauth_initalizer.rb", "config/initializers/omniauth.rb"
27
23
 
28
24
  #CanCan
29
25
  if yes?("Would you like to use CanCan for authorization?")
@@ -32,10 +28,8 @@ module Apit
32
28
  @single=model_name
33
29
  #insert_into_file "config/environment.rb", "config.gem :thor", :after => "Rails::Initializer.run do |config|\n"
34
30
  inject_into_class "app/models/user.rb", model_name.camelcase, "has_and_belongs_to_many :roles\n"
35
-
36
31
 
37
32
  template "role.rb", "app/models/role.rb"
38
-
39
33
 
40
34
  migration_template 'create_roles_migration.rb', "db/migrate/create_roles_migration.rb"
41
35
  end
@@ -0,0 +1,3 @@
1
+ Rails.application.config.middleware.use OmniAuth::Builder do
2
+ provider :twitter, 'CONSUMER_KEY', 'CONSUMER_SECRET'
3
+ end
@@ -0,0 +1,13 @@
1
+ class SessionsController < ApplicationController
2
+ def create
3
+ auth = request.env["omniauth.auth"]
4
+ user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
5
+ session[:user_id] = user.id
6
+ redirect_to root_url, :notice => "Signed in!"
7
+ end
8
+
9
+ def destroy
10
+ session[:user_id] = nil
11
+ redirect_to root_url, :notice => "Signed out!"
12
+ end
13
+ end
@@ -1,39 +1,9 @@
1
1
  class User < ActiveRecord::Base
2
- has_many :user_tokens
3
- # Include default devise modules. Others available are:
4
- # :token_authenticatable, :confirmable, :lockable and :timeoutable
5
- devise :database_authenticatable, :registerable,
6
- :recoverable, :rememberable, :trackable, :validatable, :omniauthable
7
-
8
- # Setup accessible (or protected) attributes for your model
9
- attr_accessible :email, :password, :password_confirmation, :remember_me
10
-
11
- def self.new_with_session(params, session)
12
- super.tap do |user|
13
- if data = session[:omniauth]
14
- user.user_tokens.build(:provider => data['provider'], :uid => data['uid'])
15
- end
16
- end
17
- end
18
-
19
- def apply_omniauth(omniauth)
20
- #add some info about the user
21
- #self.name = omniauth['user_info']['name'] if name.blank?
22
- #self.nickname = omniauth['user_info']['nickname'] if nickname.blank?
23
-
24
- unless omniauth['credentials'].blank?
25
- user_tokens.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
26
- #user_tokens.build(:provider => omniauth['provider'],
27
- # :uid => omniauth['uid'],
28
- # :token => omniauth['credentials']['token'],
29
- # :secret => omniauth['credentials']['secret'])
30
- else
31
- user_tokens.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
32
- end
33
- #self.confirm!# unless user.email.blank?
34
- end
35
-
36
- def password_required?
37
- (user_tokens.empty? || !password.blank?) && super
38
- end
2
+ def self.create_with_omniauth(auth)
3
+ create! do |user|
4
+ user.provider = auth["provider"]
5
+ user.uid = auth["uid"]
6
+ user.name = auth["user_info"]["name"]
7
+ end
8
+ end
39
9
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 35
9
- version: 0.0.35
8
+ - 36
9
+ version: 0.0.36
10
10
  platform: ruby
11
11
  authors:
12
12
  - Avocado
@@ -43,10 +43,11 @@ files:
43
43
  - lib/generators/apit/templates/ability.rb
44
44
  - lib/generators/apit/templates/create_roles_migration.rb
45
45
  - lib/generators/apit/templates/layout.html.erb
46
+ - lib/generators/apit/templates/omniauth_initializer.rb
46
47
  - lib/generators/apit/templates/role.rb
48
+ - lib/generators/apit/templates/sessions_controller.rb
47
49
  - lib/generators/apit/templates/stylesheet.css
48
50
  - lib/generators/apit/templates/user.rb
49
- - lib/generators/apit/templates/user_token.rb
50
51
  has_rdoc: true
51
52
  homepage: http://www.avocado.nl
52
53
  licenses: []
@@ -1,3 +0,0 @@
1
- class UserToken < ActiveRecord::Base
2
- belongs_to :user
3
- end