Migrate from lockbox to ActiveRecord encryption (1/2)
This commit is contained in:
@@ -4,7 +4,7 @@ class Admin::LightningController < Admin::BaseController
|
||||
def index
|
||||
@current_section = :lightning
|
||||
|
||||
@users = User.pluck(:cn, :ou, :ln_account)
|
||||
@users = User.pluck(:cn, :ou, :lndhub_username)
|
||||
@accounts = LndhubAccount.with_balances.order(balance: :desc).to_a
|
||||
|
||||
@ln = {}
|
||||
|
||||
@@ -37,7 +37,7 @@ class LnurlpayController < ApplicationController
|
||||
pubkey: Setting.lndhub_public_key,
|
||||
customData: [{
|
||||
customKey: "696969",
|
||||
customValue: @user.ln_account
|
||||
customValue: @user.lndhub_username
|
||||
}]
|
||||
}
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ class Services::LightningController < ApplicationController
|
||||
before_action :lndhub_fetch_balance
|
||||
|
||||
def index
|
||||
@wallet_setup_url = "lndhub://#{current_user.ln_account}:#{current_user.ln_password}@#{ENV['LNDHUB_PUBLIC_URL']}"
|
||||
@wallet_setup_url = "lndhub://#{current_user.lndhub_username}:#{current_user.lndhub_password}@#{ENV['LNDHUB_PUBLIC_URL']}"
|
||||
end
|
||||
|
||||
def transactions
|
||||
|
||||
@@ -5,7 +5,7 @@ class WebhooksController < ApplicationController
|
||||
before_action :process_payload
|
||||
|
||||
def lndhub
|
||||
@user = User.find_by!(ln_account: @payload[:user_login])
|
||||
@user = User.find_by!(lndhub_username: @payload[:user_login])
|
||||
|
||||
if @zap = @user.zaps.find_by(payment_request: @payload[:payment_request])
|
||||
settled_at = Time.parse(@payload[:settled_at])
|
||||
|
||||
@@ -2,12 +2,12 @@ class CreateLndhubAccountJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(user)
|
||||
return if user.ln_account.present? && user.ln_password.present?
|
||||
return if user.lndhub_username.present? && user.lndhub_password.present?
|
||||
|
||||
lndhub = LndhubV2.new
|
||||
credentials = lndhub.create_account
|
||||
|
||||
user.update! ln_account: credentials["login"],
|
||||
ln_password: credentials["password"]
|
||||
user.update! lndhub_username: credentials["login"],
|
||||
lndhub_password: credentials["password"]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ class LndhubUser < LndhubBase
|
||||
foreign_key: "user_id"
|
||||
|
||||
belongs_to :user, class_name: "User",
|
||||
primary_key: "ln_account",
|
||||
primary_key: "lndhub_username",
|
||||
foreign_key: "login"
|
||||
|
||||
def balance
|
||||
|
||||
@@ -23,7 +23,7 @@ class User < ApplicationRecord
|
||||
has_many :zaps
|
||||
|
||||
has_one :lndhub_user, class_name: "LndhubUser", inverse_of: "user",
|
||||
primary_key: "ln_account", foreign_key: "login"
|
||||
primary_key: "lndhub_username", foreign_key: "login"
|
||||
|
||||
has_many :accounts, through: :lndhub_user
|
||||
|
||||
@@ -66,7 +66,8 @@ class User < ApplicationRecord
|
||||
# Encrypted database columns
|
||||
#
|
||||
|
||||
has_encrypted :ln_login, :ln_password
|
||||
has_encrypted :ln_password
|
||||
encrypts :lndhub_password
|
||||
|
||||
# Include default devise modules. Others available are:
|
||||
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
||||
|
||||
@@ -33,7 +33,10 @@ class Lndhub < ApplicationService
|
||||
end
|
||||
|
||||
def authenticate(user)
|
||||
credentials = post "auth?type=auth", { login: user.ln_account, password: user.ln_password }
|
||||
credentials = post "auth?type=auth", {
|
||||
login: user.lndhub_username,
|
||||
password: user.lndhub_password
|
||||
}
|
||||
self.auth_token = credentials["access_token"]
|
||||
self.auth_token
|
||||
end
|
||||
|
||||
@@ -276,7 +276,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><%= @user.ln_account %></td>
|
||||
<td><%= @user.lndhub_username %></td>
|
||||
<td><%= number_with_delimiter @lndhub_user.balance %> sats</td>
|
||||
<td><%= number_with_delimiter @lndhub_user.sum_incoming %> sats</td>
|
||||
<td><%= number_with_delimiter @lndhub_user.sum_outgoing %> sats</td>
|
||||
@@ -285,7 +285,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p>No LndHub user found for account <strong class="font-mono"><%= @user.ln_account %></strong>.
|
||||
<p>No LndHub user found for account <strong class="font-mono"><%= @user.lndhub_username %></strong>.
|
||||
<% end %>
|
||||
</section>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user