-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.rb
More file actions
49 lines (39 loc) · 1.4 KB
/
plugin.rb
File metadata and controls
49 lines (39 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# name: discourse-ethereum
# version: 0.0.1
# authors: Codeiaks
# url: https://github.com/codeiaks/discourse-ethereum
# required_version: 2.7.0
enabled_site_setting :discourse_ethereum_enabled
register_asset "stylesheets/common.scss"
register_asset "stylesheets/mobile.scss", :mobile
after_initialize do
# Register custom fields
register_editable_user_custom_field("ethereum_address")
# User serializer extension
add_to_serializer(:user, :ethereum_address) do
if SiteSetting.discourse_ethereum_enabled
object.custom_fields["ethereum_address"].to_s.downcase
end
end
# Add ethereum address to post serializer
add_to_serializer(:post, :ethereum_address) do
return nil if !SiteSetting.discourse_ethereum_enabled
user = object.user
user&.custom_fields&.dig("ethereum_address")&.to_s&.downcase
end
# Controller for handling message signatures
class ::EthereumController < ::ApplicationController
requires_plugin("discourse-ethereum")
before_action :ensure_logged_in
def verify_signature
params.require([:message, :signature, :address])
# For a real implementation, you would verify the signature here
# This would validate that the user controls the wallet
render json: success_json
end
end
# Add routes
Discourse::Application.routes.append do
post "ethereum/verify" => "ethereum#verify_signature"
end
end