mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2026-11-04 09:04:04 +00:00
Initial work towards authentication
This commit is contained in:
@@ -10,13 +10,64 @@ module W3DHubLauncher
|
||||
end
|
||||
|
||||
stack(style_class: [:dialog_container]) do
|
||||
button "Sign In", tip: "https://sso.w3d.cyberarm.dev" do
|
||||
# use SSO service
|
||||
pop_state
|
||||
end
|
||||
caption "Sign in with your W3D Hub forum account", margin_bottom: PADDING
|
||||
|
||||
tagline "Username"
|
||||
@username = edit_line "", width: 1.0
|
||||
|
||||
tagline "Password"
|
||||
@password = edit_line "", type: :password, width: 1.0
|
||||
end
|
||||
|
||||
flow(width: 1.0, padding: PADDING, background_nine_slice: NINE_SLICE_ROUNDED_BOTTOM, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0) do
|
||||
button "Cancel" do
|
||||
pop_state
|
||||
end
|
||||
|
||||
flow(fill: true)
|
||||
|
||||
button "Register", tip: "https://w3dhub.com/forum/register/" do
|
||||
SDL.OpenURL("https://w3dhub.com/forum/register/")
|
||||
end
|
||||
|
||||
flow(fill: true)
|
||||
|
||||
button "Sign In", **CTA_BUTTON_THEME do |btn|
|
||||
# use SSO service, eventually. , tip: "https://sso.w3d.cyberarm.dev"
|
||||
|
||||
btn.enabled = false
|
||||
|
||||
Worker::Api.user_login(@username.value, @password.value) do |result|
|
||||
if result.okay?
|
||||
hash = JSON.parse(result.data)
|
||||
|
||||
MemCache[:settings].account = W3DHubLauncher::Worker::Api::Settings::Account.create(
|
||||
user_id: hash["userid"],
|
||||
username: hash["username"],
|
||||
displayname: hash["displayname"],
|
||||
avatar_uri: "",
|
||||
access_token: hash["accessToken"],
|
||||
refresh_token: hash["refreshToken"],
|
||||
access_token_expiration_time: hash["accessTokenExpiry"]
|
||||
)
|
||||
|
||||
Worker::Api.update_settings(MemCache[:settings]) do |settings_result|
|
||||
if settings_result.okay?
|
||||
on_main_thread(-> {
|
||||
pop_state
|
||||
window.current_state&.populate_account_information
|
||||
})
|
||||
end
|
||||
|
||||
# FIXME: Retry? Show error? ???
|
||||
pp settings_result
|
||||
end
|
||||
end
|
||||
|
||||
# FIXME: Show error message!
|
||||
pp result
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user