sso-auth 0.0.1 → 0.0.1.1

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.
@@ -2,17 +2,8 @@
2
2
 
3
3
  class SsoAuth::OmniauthCallbacksController < Devise::OmniauthCallbacksController
4
4
  def identity
5
- user = User.find_or_initialize_by_uid(request.env['omniauth.auth']['uid']).tap do |user|
6
- attributes = request.env['omniauth.auth']['extra']['raw_info']['user']
7
- attributes = attributes.merge(request.env['omniauth.auth']['info'])
8
- attributes.each do |attribute, value|
9
- user.send("#{attribute}=", value) if user.respond_to?("#{attribute}=")
10
- end
11
- user.save(:validate => false)
12
- end
13
-
14
- flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "системы аутентификации"
15
- sign_in user, :event => :authentication
5
+ sign_in User.find_or_create_by_omniauth_hash(request.env['omniauth.auth']), :event => :authentication
6
+ flash[:notice] = I18n.t('devise.omniauth_callbacks.success', :kind => I18n.t('sso-auth.provider.title'))
16
7
  redirect_to stored_location_for(:user) || main_app.root_path
17
8
  end
18
9
 
@@ -1,4 +1,8 @@
1
- ru:
1
+ en:
2
+ sso-auth:
3
+ provider:
4
+ title: Identity
5
+
2
6
  activerecord:
3
7
  attributes:
4
8
  permission:
@@ -1,4 +1,8 @@
1
1
  ru:
2
+ sso-auth:
3
+ provider:
4
+ title: Системы аутентификации
5
+
2
6
  activerecord:
3
7
  attributes:
4
8
  permission:
@@ -6,6 +6,6 @@ class CreatePermissions < ActiveRecord::Migration
6
6
  t.string :role
7
7
  t.timestamps
8
8
  end
9
- add_index :permissions, [:user_id, :role, :context_id, :context_type], :name => 'by_user_and_role_and_context'
9
+ add_index :permissions, [:user_id, :role, :context_id, :context_type], :name => 'by_user_and_role_and_context', :uniq => true
10
10
  end
11
11
  end
@@ -23,18 +23,22 @@ module SsoAuth
23
23
 
24
24
  config.to_prepare do
25
25
  ActionController::Base.class_eval do
26
- define_singleton_method :sso_load_and_authorize_resource do
26
+ define_singleton_method :sso_authenticate_and_authorize do
27
27
  before_filter :authenticate_user!
28
- before_filter :authorize_user_can_manage_application!
29
- load_and_authorize_resource
28
+ before_filter :authorize_manage_application!
30
29
  rescue_from CanCan::AccessDenied do |exception|
31
30
  render :file => "#{Rails.root}/public/403", :formats => [:html], :status => 403, :layout => false
32
31
  end
33
32
  end
34
33
 
34
+ define_singleton_method :sso_load_and_authorize_resource do
35
+ sso_authenticate_and_authorize
36
+ load_and_authorize_resource
37
+ end
38
+
35
39
  protected
36
40
 
37
- define_method :authorize_user_can_manage_application! do
41
+ define_method :authorize_manage_application! do
38
42
  authorize! :manage, :application
39
43
  end
40
44
  end
@@ -56,6 +60,19 @@ module SsoAuth
56
60
  define_method :sso_auth_name do
57
61
  email? ? "#{name} <#{email}>" : name
58
62
  end
63
+
64
+ define_singleton_method :find_or_create_by_omniauth_hash do |omniauth_hash|
65
+ user = User.find_by_uid(omniauth_hash[:uid])
66
+ user ||= User.find_by_email(omniauth_hash[:info][:email]) if omniauth_hash[:info][:email].present?
67
+ user ||= User.new { |user| user.uid = omniauth_hash[:uid] }
68
+ attributes = omniauth_hash[:extra][:raw_info][:user] || {}
69
+ attributes = attributes.merge(omniauth_hash[:info])
70
+ attributes.each do |attribute, value|
71
+ user.send("#{attribute}=", value) if user.respond_to?("#{attribute}=")
72
+ end
73
+ user.save(:validate => false)
74
+ user
75
+ end
59
76
  end
60
77
 
61
78
  def self.sso_auth_permission(options)
@@ -8,7 +8,10 @@ module SsoAuth
8
8
  def create_user
9
9
  @sequence ||= 0
10
10
  @sequence += 1
11
- User.create! :uid => @sequence, :name => "user #{@sequence}"
11
+ User.new.tap do |user|
12
+ user.uid = @sequence
13
+ user.save(:validate => false)
14
+ end
12
15
  end
13
16
 
14
17
  def user_with_role(role, context=nil, prefix=nil)
@@ -1,3 +1,3 @@
1
1
  module SsoAuth
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sso-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-16 00:00:00.000000000 Z
12
+ date: 2012-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cancan
@@ -217,7 +217,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
217
  version: '0'
218
218
  segments:
219
219
  - 0
220
- hash: 4589756721612764360
220
+ hash: 2057994539849800836
221
221
  required_rubygems_version: !ruby/object:Gem::Requirement
222
222
  none: false
223
223
  requirements:
@@ -226,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
226
  version: '0'
227
227
  segments:
228
228
  - 0
229
- hash: 4589756721612764360
229
+ hash: 2057994539849800836
230
230
  requirements: []
231
231
  rubyforge_project:
232
232
  rubygems_version: 1.8.24