easy_login 1.3.1 → 1.3.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90c1b0dfb4a988eb8730d3e2d5eb629c27f3204f
4
- data.tar.gz: 65b1f32113d62cbb1969aab015a08f72f906105d
3
+ metadata.gz: 9e51def3be4d60b249dae811431eedb238af9faa
4
+ data.tar.gz: bb720e50dfbf828a46d7f62058330d96355f57e5
5
5
  SHA512:
6
- metadata.gz: 7ea9abf0ecbfdc5817f520b2e559de2f86fc55122c10ba151e6c24bfafcd29b396402b96d5447d9f6cd90ee9064ea2aeaca22b9ba10c9978e01408b5885f1bdd
7
- data.tar.gz: 6653bf4823ae177a578a0c1831d27c7b406b0d4996cdf1ca5716edae9341fb0d072989fc8f06654078a7b3b4d171999a9175b39e1b958a300c562c88ced48863
6
+ metadata.gz: d83e34a329de9dc3828d727559af5f33916ab377b7a4727d16e307c803cf094a2e5febd5905bf7ed9e092df32c0bba715c57181f80e5edde1f9fc0c37abe3145
7
+ data.tar.gz: 1fac675949a0d8470c1d3c567d3d8cc19b77c47391df7376019248e449d18abba5dd1790cc3a95f1458fd70397cd719941d12efd332d5906daa3a3617f3a2fd6
data/README.md CHANGED
@@ -75,7 +75,20 @@ controller:
75
75
  user_role3: raise->{message}
76
76
  ```
77
77
 
78
- The `user_role` if the role attribute of your user model configed in `config/application.rb` or `config/environments/*.rb`
78
+ The `user_role` is the role attribute of your user model configed in `config/application.rb` or `config/environments/*.rb`
79
+ And also you need define a enum about this role like:
80
+
81
+ ```ruby
82
+ class User < ApplicationRecord
83
+ has_secure_password
84
+
85
+ enum :role => {
86
+ :user_role1 => 0,
87
+ :user_role2 => 1,
88
+ :user_role3 => 2
89
+ }
90
+ end
91
+ ```
79
92
 
80
93
  The `action` has 3 types
81
94
 
data/lib/easy_login.rb CHANGED
@@ -10,7 +10,7 @@ require "easy_login/permission"
10
10
 
11
11
  module EasyLogin
12
12
  def self.helper_method
13
- [:signed_in?, :current_user, :current_user?]
13
+ [:signed_in?, :current_user, :current_user?, :easy_login_session]
14
14
  end
15
15
 
16
16
  class Railtie < Rails::Railtie
@@ -26,21 +26,17 @@ module EasyLogin
26
26
  end
27
27
 
28
28
  def self.included(base)
29
- base.send :include, Session
30
29
  if base == ApplicationController
30
+ base.send :include, Session
31
31
  base.helper_method EasyLogin.helper_method
32
32
  base.send :before_action do |controller|
33
33
  Permission.action controller
34
34
  end
35
- elsif base == ApplicationCable::Connection
36
- base.send :identified_by, :client
35
+ elsif base == ApplicationCable::Channel
36
+ base.send :include, Cable
37
37
  elsif base == Grape::API || base.superclass == Grape::API
38
38
  base.helpers GrapeHelper
39
39
  end
40
40
  end
41
41
 
42
- def self.cable_authorize(connection, current_user)
43
- connection.client = current_user
44
- end
45
-
46
42
  end
@@ -0,0 +1,39 @@
1
+ module EasyLogin
2
+
3
+ module Cable
4
+ def signed_in?
5
+ return !current_user.nil?
6
+ end
7
+
8
+ def current_user?(user)
9
+ if(user == nil || current_user == nil)
10
+ return false;
11
+ end
12
+ return user.id == current_user.id
13
+ end
14
+
15
+ def current_user
16
+ user_id = session_info[0]
17
+ return nil if user_id == nil
18
+ user = EasyLogin.config.user_model.capitalize.constantize.find_by_id(user_id)
19
+ return user
20
+ end
21
+
22
+ private
23
+ def session_info
24
+ session = params[:f]
25
+ # cookie signed failed
26
+ return [nil, nil] unless session
27
+ session = Base64.decode64 session.split('--').first
28
+ begin
29
+ session = JSON.parse session
30
+ rescue
31
+ return [nil, nil]
32
+ end
33
+ digest = Digest::MD5.hexdigest "#{session[0]},#{EasyLogin.config.salt},#{Time.parse(session[1]).to_i}"
34
+ # digest check failed
35
+ return [nil, nil] unless session[2] == digest
36
+ [session[0], session[1]]
37
+ end
38
+ end
39
+ end
@@ -27,10 +27,10 @@ module EasyLogin
27
27
 
28
28
  private
29
29
  def session_info
30
- session = cookies[:f]
30
+ session = params[:f]
31
31
  # cookie signed failed
32
32
  return [nil, nil] unless session
33
- session = Base64.decode64 cookies[:f].split('--').first
33
+ session = Base64.decode64 session.split('--').first
34
34
  begin
35
35
  session = JSON.parse session
36
36
  rescue
@@ -28,6 +28,11 @@ module EasyLogin
28
28
  return user
29
29
  end
30
30
 
31
+ def easy_login_session
32
+ session = cookies.signed[:f]
33
+ "<div id='easy_login_session' uid=#{session[0]} ts='#{session[1]}' d='#{session[2]}'></div>".html_safe
34
+ end
35
+
31
36
  private
32
37
  def session_info
33
38
  session = cookies.signed[:f]
@@ -1,3 +1,3 @@
1
1
  module EasyLogin
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_login
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - goshan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-31 00:00:00.000000000 Z
11
+ date: 2017-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,6 +74,7 @@ files:
74
74
  - Rakefile
75
75
  - easy_login.gemspec
76
76
  - lib/easy_login.rb
77
+ - lib/easy_login/cable.rb
77
78
  - lib/easy_login/config.rb
78
79
  - lib/easy_login/grape_helper.rb
79
80
  - lib/easy_login/permission.rb