2023-03-14 13:18:55 +00:00
|
|
|
{{!
|
|
|
|
Copyright (c) HashiCorp, Inc.
|
|
|
|
SPDX-License-Identifier: MPL-2.0
|
|
|
|
}}
|
|
|
|
|
2021-11-24 14:53:12 +00:00
|
|
|
<StateChart
|
|
|
|
@src={{chart}}
|
|
|
|
as |State Guard Action dispatch state|>
|
|
|
|
|
|
|
|
<Guard
|
|
|
|
@name="hasToken"
|
|
|
|
@cond={{action 'hasToken'}}
|
|
|
|
/>
|
|
|
|
<Action
|
|
|
|
@name="login"
|
|
|
|
@exec={{action 'login'}}
|
|
|
|
/>
|
|
|
|
<Action
|
|
|
|
@name="logout"
|
|
|
|
@exec={{action 'logout'}}
|
|
|
|
/>
|
2020-05-11 15:37:11 +00:00
|
|
|
|
|
|
|
{{! This DataSource just permanently listens to any changes to the users }}
|
|
|
|
{{! token, whether thats a new token, a changed token or a deleted token }}
|
|
|
|
<DataSource
|
2022-01-07 19:08:25 +00:00
|
|
|
@src={{@src}}
|
2020-05-11 15:37:11 +00:00
|
|
|
@onchange={{queue (action (mut token) value="data") (action dispatch "CHANGE") (action (mut previousToken) value="data")}}
|
|
|
|
/>
|
|
|
|
{{! This DataSink is just used for logging in from the form, }}
|
|
|
|
{{! or logging out via the exposed logout function }}
|
|
|
|
<DataSink
|
2022-01-07 19:08:25 +00:00
|
|
|
@sink={{@sink}}
|
2020-05-11 15:37:11 +00:00
|
|
|
as |sink|
|
|
|
|
>
|
|
|
|
{{#let (hash
|
|
|
|
login=(action sink.open)
|
|
|
|
logout=(action sink.open null)
|
|
|
|
token=token
|
2022-01-07 19:08:25 +00:00
|
|
|
) as |api|}}
|
|
|
|
|
2020-05-11 15:37:11 +00:00
|
|
|
<State @matches="authorized">
|
2022-01-07 19:08:25 +00:00
|
|
|
{{yield api to="authorized"}}
|
2020-05-11 15:37:11 +00:00
|
|
|
</State>
|
|
|
|
|
|
|
|
<State @matches="unauthorized">
|
2022-01-07 19:08:25 +00:00
|
|
|
{{yield api to="unauthorized"}}
|
2020-05-11 15:37:11 +00:00
|
|
|
</State>
|
2022-01-07 19:08:25 +00:00
|
|
|
|
2020-05-11 15:37:11 +00:00
|
|
|
{{/let}}
|
|
|
|
</DataSink>
|
|
|
|
</StateChart>
|