Merge pull request 'Remove ln_login from users' (#86) from chore/remove_ln_login into master
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: #86
This commit is contained in:
Râu Cao 2023-02-23 12:16:06 +00:00
commit b530ad2f0f
8 changed files with 12 additions and 9 deletions

View File

@ -2,7 +2,6 @@ EJABBERD_API_URL='http://xmpp.example.com/api'
BTCPAY_API_URL='http://btcpay.example.com/api/v1' BTCPAY_API_URL='http://btcpay.example.com/api/v1'
LNDHUB_LEGACY_API_URL='http://localhost:3023'
LNDHUB_API_URL='http://localhost:3026' LNDHUB_API_URL='http://localhost:3026'
LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org' LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org'

View File

@ -7,7 +7,7 @@ class WalletController < ApplicationController
before_action :fetch_balance before_action :fetch_balance
def index def index
@wallet_url = "lndhub://#{current_user.ln_login}:#{current_user.ln_password}@#{ENV['LNDHUB_PUBLIC_URL']}" @wallet_url = "lndhub://#{current_user.ln_account}:#{current_user.ln_password}@#{ENV['LNDHUB_PUBLIC_URL']}"
qrcode = RQRCode::QRCode.new(@wallet_url) qrcode = RQRCode::QRCode.new(@wallet_url)
@svg = qrcode.as_svg( @svg = qrcode.as_svg(

View File

@ -2,13 +2,12 @@ class CreateLndhubAccountJob < ApplicationJob
queue_as :default queue_as :default
def perform(user) def perform(user)
return if user.ln_login.present? && user.ln_password.present? return if user.ln_account.present? && user.ln_password.present?
lndhub = LndhubV2.new lndhub = LndhubV2.new
credentials = lndhub.create_account credentials = lndhub.create_account
user.update! ln_account: credentials["login"], user.update! ln_account: credentials["login"],
ln_login: credentials["login"], # TODO remove when production is migrated
ln_password: credentials["password"] ln_password: credentials["password"]
end end
end end

View File

@ -2,7 +2,7 @@ class Lndhub
attr_accessor :auth_token attr_accessor :auth_token
def initialize def initialize
@base_url = ENV["LNDHUB_LEGACY_API_URL"] @base_url = ENV["LNDHUB_API_URL"]
end end
def post(endpoint, payload) def post(endpoint, payload)
@ -42,7 +42,7 @@ class Lndhub
end end
def authenticate(user) def authenticate(user)
credentials = post "auth?type=auth", { login: user.ln_login, password: user.ln_password } credentials = post "auth?type=auth", { login: user.ln_account, password: user.ln_password }
self.auth_token = credentials["access_token"] self.auth_token = credentials["access_token"]
self.auth_token self.auth_token
end end

View File

@ -39,7 +39,7 @@ class LndhubV2
end end
def authenticate(user) def authenticate(user)
credentials = post "auth?type=auth", { login: user.ln_login, password: user.ln_password } credentials = post "auth?type=auth", { login: user.ln_account, password: user.ln_password }
self.auth_token = credentials["access_token"] self.auth_token = credentials["access_token"]
self.auth_token self.auth_token
end end

View File

@ -0,0 +1,5 @@
class RemoveLnLoginFromUsers < ActiveRecord::Migration[7.0]
def change
remove_column :users, :ln_login_cyphertext
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_02_17_084310) do ActiveRecord::Schema[7.0].define(version: 2023_02_23_115536) do
create_table "donations", force: :cascade do |t| create_table "donations", force: :cascade do |t|
t.integer "user_id" t.integer "user_id"
t.integer "amount_sats" t.integer "amount_sats"

View File

@ -19,7 +19,7 @@ RSpec.describe CreateLndhubAccountJob, type: :job do
.with { |req| req.body == '{}' } .with { |req| req.body == '{}' }
user.reload user.reload
expect(user.ln_login).to eq("abc123") expect(user.ln_account).to eq("abc123")
expect(user.ln_password).to eq("def456") expect(user.ln_password).to eq("def456")
end end