user_management_rails 0.1.1 → 0.1.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
- SHA1:
3
- metadata.gz: 5d1909d8b0e260c2b033ead5e6ca86299ba18712
4
- data.tar.gz: f00e5625bed7d4e27458438c28adf2a220d0f89d
2
+ SHA256:
3
+ metadata.gz: 9bad4e0973506e6ab846fc6265f84d4cd9e76aff3c762522d8b536cbf7cbfcbb
4
+ data.tar.gz: f56c50c9812b39249953dfe0aa06f0f84331f170cdea83d99ad44a5758029117
5
5
  SHA512:
6
- metadata.gz: d7364f85e3a62bb90d6316f47093c2b6fff0da0866a389674cf3fbaf991ae653df39cf62bf9c0b9dd078162035a3c284585a8ce9e8eda80c0fade915dd9a8bdd
7
- data.tar.gz: a7548e2026aae1f650a1c41dd676b196f644f589dab6413a70888d8934fdddd15a399335b8680bf0db4a90d14e94dc1e07d8edc1f255b34f18611d84adbf82a0
6
+ metadata.gz: 18a6994d399b64f54e727019b15297d44791c49639a098efffc6102be6c93c7072baa352cde9b30ddd6da792bb4fbe0ab4f198171cd74c922b58ef9b4b0733a7
7
+ data.tar.gz: 9735957dffd941cd5baf1e3f910de71a521b4e4691a9069d4564facb2e2771065c966e58c5a1949afd724bfc209769521cb4dc02437ea534ed3cd779a835285e
data/README.md CHANGED
@@ -34,14 +34,29 @@ And then execute:
34
34
  $ bundle
35
35
  ```
36
36
 
37
- Or install it yourself as:
37
+ Next, you need to run the generator:
38
38
  ```bash
39
- $ gem install user_management_rails
39
+ $ rails generate user_management_rails:install --ringcaptcha-key=RINGCAPTCHA_APP_KEY --um-key=UM_KEY [--mode=OTP|PASSWORD]
40
+ ```
41
+
42
+ This will add the necessary controller, view, and routes.
43
+ You can update the files according to your needs.
44
+
45
+ Default routes installed:
46
+ ```bash
47
+ $ rake routes
48
+ Prefix Verb URI Pattern Controller#Action
49
+ user_management_rails / UserManagementRails::Engine
50
+ home GET /home(.:format) user_management#loggedin
51
+ login GET /login(.:format) user_management#login
52
+ root GET / user_management#signup
53
+
54
+ Routes for UserManagementRails::Engine:
55
+ logins POST /logins(.:format) user_management_rails/logins#create
40
56
  ```
41
57
 
42
58
  ## Requirements
43
- To use gem you should provide environment variable with UM public key called 'JWT_PUBLIC_KEY'.
44
- Also, in your routes.rb file you should specify where `/login` endpoint will be mount.
59
+ In your routes.rb file you should specify where `/login` endpoint will be mount.
45
60
  Example:
46
61
  ```ruby
47
62
  mount UserManagementRails::Engine, at: '/'
@@ -53,6 +68,8 @@ If you already have a '/login' endpoint you can isolate it by
53
68
  ```
54
69
  Then gems `/login` endpoint will be mounted on `domain.com/some_path/logins`
55
70
 
71
+ * rails generator adds this route by default as stated above.
72
+
56
73
  ## Adding new version of gem to rubygems repository
57
74
  After you made changes and increment version of gem in(/lib/user_management_rails/version.rb)
58
75
  you need to build and push new gem file to rubygems.org:
@@ -0,0 +1,19 @@
1
+ ===============================================================================
2
+
3
+ Installation done!
4
+
5
+ 1. You can now visit '/login' for your signin page.
6
+
7
+ If you would like to check default routes:
8
+
9
+ rake routes
10
+
11
+ 2. If you like to change your keys, check out:
12
+
13
+ config/initializers/user_management.rb
14
+
15
+ 3. You can customize views on your app according to your needs:
16
+
17
+ app/views/user_management/*.html.erb
18
+
19
+ ===============================================================================
@@ -0,0 +1,28 @@
1
+ class UserManagementController < ApplicationController
2
+ include UserManagementRails::Concerns::UserResource
3
+
4
+ def signup
5
+ if current_user_hash
6
+ redirect_to action: 'loggedin'
7
+ else
8
+ render 'signup'
9
+ end
10
+ end
11
+
12
+ def login
13
+ if current_user_hash
14
+ redirect_to action: 'loggedin'
15
+ else
16
+ render 'login'
17
+ end
18
+ end
19
+
20
+ def loggedin
21
+ if current_user_hash
22
+ @userinfo = current_user_hash.values_at("phone","email")
23
+ else
24
+ redirect_to action: 'login'
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,5 @@
1
+ UserManagementRails.configure do |config|
2
+ config.um_key = "<%= options['um_key'] %>"
3
+ config.ringcaptcha_key = "<%= options['ringcaptcha_key'] %>"
4
+ config.jwt_public_key = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvvoSdfTthi+8Q18teTftAyyXq2WbnUjc62tIPRRJmWnd2YoP6d245EzMtXL8WnNq1khEiIFevpLLnV+fHY/QmlayP0dUqR+P0yGgMCxzpIPONZC/X5ndUpjbkjk/LF6NOrQXJcY6HfFY6TwoPr6DbCb49WUxkIHTaaaW8wJAartAI/fVmd0mnihacap85cCsfWH4lm+c9f/a/+gx5F6ndgL+zvm8uda7I5qlK9myczsj8CGT3QtH30GSGZ1kXUH3v61tYoBsCm+BM5DGZrPxsACb8vpoP3WDKq+BSNUa7QWUklA/pRF1dpDqhUChF0FocsFNfvTI+3k1s2gjsjc6rwIDAQAB\n-----END PUBLIC KEY-----"
5
+ end
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ </head>
5
+ <body>
6
+ <h3>"You Are Logged In as"</h3>
7
+ <h4><%%= @userinfo %></h4>
8
+ </body>
9
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ </head>
6
+
7
+ <body>
8
+ <div id='widget-point'>
9
+ </div>
10
+
11
+ <script type='text/javascript' src="//code.jquery.com/jquery-3.1.1.min.js"></script>
12
+
13
+ <script type='text/javascript' src="//cdn.rawgit.com/oauth-io/oauth-js/c5af4519/dist/oauth.js"></script>
14
+
15
+ <script type='text/javascript' src="https://s3.amazonaws.com/ringcaptcha-test/widget/jwt-20180328/bundle.js"></script>
16
+
17
+
18
+ <script type='text/javascript'>
19
+ $(document).ready(function() {
20
+ $('#widget-point').append(
21
+ '<div id="xyz" data-widget data-locale="en" data-mode="login" data-type="dual"></div>'
22
+ );
23
+
24
+ $('#xyz').each(function() {
25
+ // var appKey = "3i8i2ihu7e9u6orapyga";
26
+ // var userManagementId = '0bb071d01611abdf8e76c3';
27
+ var appKey = "<%%= UserManagementRails.configuration.ringcaptcha_key %>";
28
+ var userManagementId = "<%%= UserManagementRails.configuration.um_key %>";
29
+ var oauthioKey = 'HwAr2OtSxRgEEnO2-JnYjsuA3tc';
30
+ var settings = $(this).data();
31
+ // Initialize the SDK
32
+ //OAuth.initialize(oauthioKey)
33
+ settings.app = appKey;
34
+ settings.events = {
35
+ login: function(event, formValues) {
36
+ console.log("Login: event:", event);
37
+ console.log("Login: formValues:", formValues);
38
+ const dataString = localStorage.getItem('ringcaptcha.widget.' + appKey);
39
+ const data = dataString ? JSON.parse(dataString) : null;
40
+ console.log("Login: data:", data);
41
+ console.log("Login success for:", formValues.login);
42
+ $.post('/logins',{jwt:formValues['jwt']});
43
+ window.location.replace('./home');
44
+ }
45
+ };
46
+ settings.form = [
47
+ {
48
+ id: 'email',
49
+ type: 'text',
50
+ placeholder: 'Email',
51
+ },
52
+ {
53
+ id: 'pin',
54
+ type: 'pin'
55
+ }
56
+ ];
57
+ settings.userManagement = true;
58
+ settings.phoneLogin = true;
59
+ settings.userManagementAppId = userManagementId;
60
+
61
+ new RingCaptcha.Widget(this, settings.app, settings);
62
+ });
63
+ });
64
+ </script>
65
+ </body>
66
+ </html>
@@ -0,0 +1,79 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ </head>
6
+
7
+ <body>
8
+ <div id='widget-point'>
9
+ </div>
10
+
11
+ <script type='text/javascript' src="//code.jquery.com/jquery-3.1.1.min.js"></script>
12
+
13
+ <script type='text/javascript' src="//cdn.rawgit.com/oauth-io/oauth-js/c5af4519/dist/oauth.js"></script>
14
+
15
+ <script type='text/javascript' src="https://s3.amazonaws.com/ringcaptcha-test/widget/jwt-20180328/bundle.js"></script>
16
+
17
+ <script>
18
+ $(document).ready(function() {
19
+ $('#widget-point').append(
20
+ '<div id="xyz" data-widget data-locale="en" data-mode="signup" data-type="dual"></div>'
21
+ );
22
+ $('#xyz').each(function() {
23
+ // var appKey = "3i8i2ihu7e9u6orapyga";
24
+ // var userManagementId = '0bb071d01611abdf8e76c3';
25
+ var appKey = "<%%= UserManagementRails.configuration.ringcaptcha_key %>";
26
+ var userManagementId = "<%%= UserManagementRails.configuration.um_key %>";
27
+ var oauthioKey = "HwAr2OtSxRgEEnO2-JnYjsuA3tc";
28
+ var settings = $(this).data();
29
+ // Initialize the SDK
30
+ OAuth.initialize(oauthioKey)
31
+ settings.app = appKey;
32
+ settings.events = {
33
+ signup: function(event, formValues) {
34
+ console.log("Signup: event:", event);
35
+ console.log("Signup: formValues:", formValues);
36
+ const dataString = localStorage.getItem('ringcaptcha.widget.' + appKey);
37
+ const data = dataString ? JSON.parse(dataString) : null;
38
+ console.log("Signup: data:", data);
39
+ User.signup({
40
+ email: formValues.email,
41
+ password: "Freef0rall!",
42
+ firstname: "Fname",
43
+ lastname: "Lname",
44
+ phone: formValues.phone
45
+ }).done(function(user) {
46
+ console.log("User.signup success for:", formValues.email);
47
+ $.post('/logins',{jwt:formValues['jwt']});
48
+ window.location.replace('/home');
49
+ });
50
+ }
51
+ };
52
+ settings.form = [
53
+ {
54
+ id: 'email',
55
+ type: 'email',
56
+ placeholder: 'Email',
57
+ validations: {
58
+ presence: 'Email should be present',
59
+ format: { message: 'Invalid email' }
60
+ }
61
+ },
62
+ {
63
+ id: 'phone',
64
+ type: 'phone',
65
+ validations: {
66
+ length: { min: 5, max: 15, message: 'Invalid phone' }
67
+ }
68
+ }
69
+ ];
70
+ settings.userManagement = true;
71
+ settings.phoneLogin = true;
72
+ settings.userManagementAppId = userManagementId;
73
+
74
+ new RingCaptcha.Widget(this, settings.app, settings);
75
+ });
76
+ });
77
+ </script>
78
+ </body>
79
+ </html>
@@ -0,0 +1,66 @@
1
+ module UserManagementRails
2
+ class InstallGenerator < Rails::Generators::Base
3
+
4
+ desc <<-DESC.strip_heredoc
5
+ Create UserManagementRails boilerplate (controller and view) in your app folder.
6
+
7
+ Required Flags:
8
+
9
+ Use -r to specify your RingCaptcha app key.
10
+ Use -u to specify your UM key (for login mode only).
11
+
12
+ Optional Flags:
13
+
14
+ Use -m to specify login mode (options: password, otp).
15
+
16
+ If you do no specify a mode, password mode will be created by default.
17
+ For example:
18
+
19
+ rails generate user_management_rails:install users -m=password -r=XXXXXX -u=XXXXX
20
+
21
+ This will create a controller class at app/controllers/user_management_controller.rb like this:
22
+
23
+ class UserManagementController < ApplicationController
24
+ content...
25
+ end
26
+ DESC
27
+
28
+ source_root File.expand_path("../../templates", __FILE__)
29
+ class_option :ringcaptcha_key, required: true, aliases: "-r", type: :string,
30
+ desc: "Specify the RingCaptcha app key."
31
+ class_option :um_key, required: true, aliases: "-u", type: :string,
32
+ desc: "Specify the User Management key."
33
+ class_option :mode, aliases: "-m", type: :string, default: 'otp',
34
+ desc: "Specify the King Authr mode. Possible values: [otp|password]"
35
+
36
+ def add_initializer
37
+ template "user_management_initializer.rb", "config/initializers/user_management.rb"
38
+ end
39
+
40
+ def create_controller
41
+ template "controllers/user_management_controller.rb",
42
+ "app/controllers/user_management_controller.rb"
43
+ end
44
+
45
+ def create_view
46
+ template "views/signup.html.erb",
47
+ "app/views/user_management/signup.html.erb"
48
+ template "views/login.html.erb",
49
+ "app/views/user_management/login.html.erb"
50
+ template "views/loggedin.html.erb",
51
+ "app/views/user_management/loggedin.html.erb"
52
+ end
53
+
54
+ def add_routes
55
+ route "root 'user_management#signup'"
56
+ route "get '/login', to: 'user_management#login'"
57
+ route "get '/home', to: 'user_management#loggedin'"
58
+ route "mount UserManagementRails::Engine, at: '/'"
59
+ end
60
+
61
+ def show_readme
62
+ readme "README" if behavior == :invoke
63
+ end
64
+
65
+ end
66
+ end
@@ -4,12 +4,14 @@ require 'dotenv-rails'
4
4
 
5
5
  module UserManagementRails
6
6
  def self.decode_user(jwt)
7
- pub_key = OpenSSL::PKey::RSA.new(ENV['JWT_PUBLIC_KEY'])
7
+ # pub_key = OpenSSL::PKey::RSA.new(ENV['JWT_PUBLIC_KEY'])
8
+ pub_key = OpenSSL::PKey::RSA.new(self.configuration.jwt_public_key)
8
9
  JWT.decode(jwt, pub_key, true, algorithm: 'RS256')[0]
9
10
  end
10
11
 
11
12
  def self.valid_jwt?(jwt)
12
- pub_key = OpenSSL::PKey::RSA.new(ENV['JWT_PUBLIC_KEY'])
13
+ # pub_key = OpenSSL::PKey::RSA.new(ENV['JWT_PUBLIC_KEY'])
14
+ pub_key = OpenSSL::PKey::RSA.new(self.configuration.jwt_public_key)
13
15
  begin
14
16
  JWT.decode(jwt, pub_key, true, algorithm: 'RS256')[0]
15
17
  rescue JWT::DecodeError
@@ -18,4 +20,24 @@ module UserManagementRails
18
20
  true
19
21
  end
20
22
 
23
+ # initializers
24
+ class << self
25
+ attr_accessor :configuration
26
+ end
27
+
28
+ def self.configure
29
+ self.configuration ||= Configuration.new
30
+ yield(configuration)
31
+ end
32
+
33
+ class Configuration
34
+ attr_accessor :um_key, :ringcaptcha_key, :jwt_public_key
35
+
36
+ def initialize
37
+ @um_key = nil
38
+ @ringcaptcha_key = nil
39
+ @jwt_public_key = nil
40
+ end
41
+ end
42
+
21
43
  end
@@ -1,3 +1,3 @@
1
1
  module UserManagementRails
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: user_management_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - RingCaptcha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-27 00:00:00.000000000 Z
11
+ date: 2018-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -205,6 +205,13 @@ files:
205
205
  - app/views/layouts/user_management_rails/application.html.erb
206
206
  - app/views/user_managemet_rails/logins/index.html.erb
207
207
  - config/routes.rb
208
+ - lib/generators/templates/README
209
+ - lib/generators/templates/controllers/user_management_controller.rb
210
+ - lib/generators/templates/user_management_initializer.rb
211
+ - lib/generators/templates/views/loggedin.html.erb
212
+ - lib/generators/templates/views/login.html.erb
213
+ - lib/generators/templates/views/signup.html.erb
214
+ - lib/generators/user_management_rails/install_generator.rb
208
215
  - lib/tasks/user_management_rails_tasks.rake
209
216
  - lib/user_management_rails.rb
210
217
  - lib/user_management_rails/engine.rb
@@ -229,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
236
  version: '0'
230
237
  requirements: []
231
238
  rubyforge_project:
232
- rubygems_version: 2.6.11
239
+ rubygems_version: 2.7.3
233
240
  signing_key:
234
241
  specification_version: 4
235
242
  summary: RingCaptcha widget RoR helper.