~singpolyma/sgx-jmp

ref: 678283bd90f58860548fef1a9b45af6edf962a46 sgx-jmp/lib/backend_sgx.rb -rw-r--r-- 722 bytes
678283bdStephen Paul Weber Object representing the backend SGX to use 1 year, 8 months ago
                                                                                
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
# frozen_string_literal: true

class BackendSgx
	def initialize(jid=CONFIG[:sgx], creds=CONFIG[:creds])
		@jid = jid
		@creds = creds
	end

	def register!(customer_id, tel)
		ibr = mkibr(:set, customer_id)
		ibr.nick = @creds[:account]
		ibr.username = @creds[:username]
		ibr.password = @creds[:password]
		ibr.phone = tel
		IQ_MANAGER.write(ibr)
	end

	def registered?(customer_id)
		IQ_MANAGER.write(mkibr(:get, customer_id)).catch { nil }.then do |result|
			if result&.respond_to?(:registered?) && result&.registered?
				result
			else
				false
			end
		end
	end

protected

	def mkibr(type, customer_id)
		ibr = IBR.new(type, @jid)
		ibr.from = "customer_#{customer_id}@#{CONFIG[:component][:jid]}"
		ibr
	end
end