prove_keybase 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98de567e2e93c7858d52f3ddc970d034353a0222666537e2148403d9929a2d23
4
- data.tar.gz: b19bb531849068ecc423ea074c5b6c35957551133dafa147a5a034779830a978
3
+ metadata.gz: 478d6b2e7486a318cd58545885ffcbf95630d7e7354584b9a61b17da13ffce75
4
+ data.tar.gz: ef316bec11d97651ff7d13aa55ecd688fdc4757b41935ed04465623c16e3d8a9
5
5
  SHA512:
6
- metadata.gz: 7504350b2e10e01a0136c765a34e32b01e51d3aeef0b51a5fd42bccdab0dbc519aa596a3f832a01df5207732904e1a728c1398a0a5cc7be9336a73f4cfba37cf
7
- data.tar.gz: 00db06417b4fb949fce1d6a0324c0882190f132aa2697b8c41d9b2524c3ffd195bfc52d149a2fe8f34045cf5c7329fdf5e844314149941f10cb1f6807a6e1645
6
+ metadata.gz: 7d428ac813a60791e12b1ac02c1ce65945516851418b9761bc3aff171d2ce5e2f5bd02c866475b8d322790a4e81aa2c969d4819d17840802eee08165dcdaf25c
7
+ data.tar.gz: 0e6714bcf31889b507bea552debb89c37ce4fe7247a5e96ce6f147158f1553000f91464a1eee6f77e640b257d41f269a2fbecbb27557855d2e7be2e2e17336f9
data/README.md CHANGED
@@ -38,10 +38,10 @@ curl https://keybase.io/_/api/1.0/validate_proof_config.json\?config_url\=https:
38
38
  ## Overrides
39
39
 
40
40
  ### Definitely do this
41
- First and foremost, the view template to create a new proof is ugly as sin. This is intentional. Please make it look and feel like it's part of your site, which it is. For an example of how to do this, [here](app/views/prove_keybase/proofs/new.html.erb) is the view you need to override, and [here](spec/dummy/app/views/prove_keybase/proofs/new.html.erb) it is being overridden in the dummy app.
41
+ First and foremost, the view template to create a new proof is ugly as sin. This is intentional. Please make it look and feel like it's part of your site, which it is. For an example of how to do this, [here](app/views/prove_keybase/proofs/new.html.erb) is the view you need to override, and [here](spec/dummy/app/views/prove_keybase/proofs/new.html.erb) it is being overridden in the dummy app. The generator should have put a file in the right place.
42
42
 
43
43
  ### Consider doing this
44
- A lot of the controller behavior, especially around handling authentication, is constructed in this gem with subclassing / method-overriding in mind. Take a look at the [KeybaseBaseController](app/controllers/prove_keybase/keybase_base_controller.rb). All of these methods _can_ (and some _should_) be overridden. The dummy app has an example of this [here](spec/dummy/app/controllers/keybase_base_controller.rb).
44
+ A lot of the controller behavior, especially around handling authentication, is constructed in this gem with subclassing / method-overriding in mind and some assumptions about, for example, identifying the logged-in user. Take a look at the [KeybaseBaseController](app/controllers/prove_keybase/keybase_base_controller.rb). All of these methods _can_ (and some _should_) be overridden. The generator should have put a file in the right place with some notes to get you started. The dummy app has an [example](spec/dummy/app/controllers/keybase_base_controller.rb).
45
45
 
46
46
  ## Keeping data up-to-date
47
47
  It's always possible for a user to revoke their proof in Keybase. To ensure that your site is not linking to a broken proof, we have a couple of suggestions. The behavior that checks Keybase for a proof and updates your `keybase_proofs` table is accessible through an async job called `UpdateFromKeybaseJob`. Keybase would prefer if you did not call this every time every user sees another user's proofs. A nice compromise is to fire this off whenever a user looks at their own proofs. We do this in the dummy app [here](spec/dummy/app/controllers/users_controller.rb).
@@ -18,17 +18,19 @@ class ProveKeybase::KeybaseBaseController < ::ApplicationController
18
18
  redirect_to new_proof_url(params: proof_params)
19
19
  end
20
20
 
21
- def handle_wrong_logged_in_user(logged_in_as, proving)
22
- flash[:alert] = "you're logged in as #{logged_in_as} but trying to prove #{proving}"
23
- handle_login_redirect
24
- end
25
-
26
21
  def avatar_url_from_username(username)
27
22
  # if you override this method, please keep the behavior
28
23
  # of raising an exception when a user does not exist.
29
24
  User.find_by!(username: username).avatar_url || 'https://example.com/default_avatar.jpg'
30
25
  end
31
26
 
27
+ private
28
+
29
+ def handle_wrong_logged_in_user(logged_in_as, proving)
30
+ flash[:alert] = "you're logged in as #{logged_in_as} but trying to prove #{proving}"
31
+ handle_login_redirect
32
+ end
33
+
32
34
  def handle_login_redirect
33
35
  redirect_to Rails.application.routes.url_helpers.send(ProveKeybase.configuration.login_redirection)
34
36
  end
@@ -5,6 +5,8 @@ class ProveKeybaseGenerator < Rails::Generators::NamedBase
5
5
  def install
6
6
  copy_file "initializer.rb", "config/initializers/prove_keybase.rb"
7
7
  migration_template "migration.rb", "db/migrate/create_keybase_proofs.rb"
8
+ copy_file "base_controller.rb", "app/controllers/keybase_base_controller.rb"
9
+ copy_file "new_proof.html.erb", "app/views/prove_keybase/proofs/new.html.erb"
8
10
  end
9
11
 
10
12
  def self.next_migration_number(dir)
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ProveKeybase::Engine.root.join('app', 'controllers', 'prove_keybase', 'keybase_base_controller')
4
+
5
+ class ProveKeybase::KeybaseBaseController
6
+
7
+ # current_user is expected to be the logged in user. In your app, this is
8
+ # very likely already the case. If it is, you can just delete this and
9
+ # stop reading.
10
+ # If you don't use current_user from elsewhere, then please uncomment this.
11
+ # It should be the logged-in user. This is also used in the view file that
12
+ # you'll be overriding / rewriting, which is why `helper_method` is here.
13
+ # helper_method :current_user
14
+ # def current_user
15
+ # User.find_by(username: params[:username]) || User.new
16
+ # end
17
+
18
+ # def user_is_logged_in!
19
+ # handle_login_redirect unless current_user
20
+ # end
21
+
22
+ # def user_proving_own_account!
23
+ # unless current_user.username.casecmp(@proving_username).zero?
24
+ # handle_wrong_logged_in_user(current_user.username, @proving_username)
25
+ # end
26
+ # end
27
+
28
+ # def handle_proof_failed
29
+ # flash[:alert] = 'proof failed. please start again from keybase.'
30
+ # redirect_to new_proof_url(params: proof_params)
31
+ # end
32
+
33
+ # def avatar_url_from_username(username)
34
+ # # if you override this method, please keep the behavior
35
+ # # of raising an exception when a user does not exist.
36
+ # User.find_by!(username: username).avatar_url || 'https://example.com/default_avatar.jpg'
37
+ # end
38
+
39
+ # private
40
+
41
+ # def handle_wrong_logged_in_user(logged_in_as, proving)
42
+ # flash[:alert] = "you're logged in as #{logged_in_as} but trying to prove #{proving}"
43
+ # handle_login_redirect
44
+ # end
45
+
46
+ # def handle_login_redirect
47
+ # redirect_to Rails.application.routes.url_helpers.send(ProveKeybase.configuration.login_redirection)
48
+ # end
49
+
50
+ end
@@ -0,0 +1,18 @@
1
+ <p id='alert'><%= alert %></p>
2
+
3
+ <h2>Rewrite Me Please</h2>
4
+
5
+ <p>this is you here:</p>
6
+ <p><%= image_tag current_user.avatar_url, width: 200 %></p>
7
+
8
+ <p>is this you on keybase?</p>
9
+ <p><%= image_tag @proof.keybase_avatar_url, width: 200 %></p>
10
+
11
+
12
+ <%= form_with scope: :proof, url: proofs_path, local: true do |f| %>
13
+ <%= f.hidden_field :token, value: @proof.token %>
14
+ <%= f.hidden_field :username, value: @proof.username %>
15
+ <%= f.hidden_field :kb_username, value: @proof.kb_username %>
16
+ <%= f.hidden_field :kb_ua, value: params[:kb_ua] %>
17
+ <%= submit_tag 'yes' %>
18
+ <% end %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProveKeybase
4
- VERSION = '0.1.0'.freeze
4
+ VERSION = '0.1.1'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prove_keybase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Gessner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-10 00:00:00.000000000 Z
11
+ date: 2019-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -147,8 +147,10 @@ files:
147
147
  - config/routes.rb
148
148
  - lib/generators/prove_keybase/USAGE
149
149
  - lib/generators/prove_keybase/prove_keybase_generator.rb
150
+ - lib/generators/prove_keybase/templates/base_controller.rb
150
151
  - lib/generators/prove_keybase/templates/initializer.rb
151
152
  - lib/generators/prove_keybase/templates/migration.rb
153
+ - lib/generators/prove_keybase/templates/new_proof.html.erb
152
154
  - lib/prove_keybase.rb
153
155
  - lib/prove_keybase/configuration.rb
154
156
  - lib/prove_keybase/engine.rb