~singpolyma/sgx-jmp

ref: a0bb2b95a26784aa54bf9cfbbf5a80f2fcc3ff12 sgx-jmp/lib/backend_sgx.rb -rw-r--r-- 731 bytes
a0bb2b95Stephen Paul Weber Set execting status properly 1 year, 2 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
36
37
38
39
40
# frozen_string_literal: true

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

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

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

protected

	def from_jid
		"customer_#{@customer_id}@#{CONFIG[:component][:jid]}"
	end

	def mkibr(type)
		ibr = IBR.new(type, @jid)
		ibr.from = from_jid
		ibr
	end
end