GatewayLoginResult

This commit is contained in:
Kevin Darby committed 2018-11-06 18:12:31 -05:00
1 parent a5b7332fa4
commit e75be340e2
11 files changed
+32 -11

No files matched your search

+1
View File
@@ -10,6 +10,7 @@ message GatewayLoginResult {
bool is_valid = 1;
string reason = 2;
string token = 3;
bool can_create = 4;
}
message GatewayCallHeader {
int32 request_id = 1;
+1
View File
@@ -47,6 +47,7 @@ message AuthenticateLoginResponse {
string reason = 2;
AuthToken token = 3;
uint32 user_id = 4;
bool can_create = 5;
}
message AuthenticateTokenRequest {AuthToken token = 1;}
message AuthenticateTokenResponse {bool is_valid = 1; string reason = 2; User user = 3;}
+1
View File
@@ -46,6 +46,7 @@ struct ApiGatewayImpl {
if (logon_response.result()->is_valid()) {
resp.mutable_logon()->set_is_valid(true);
resp.mutable_logon()->set_token(logon_response.result()->token().token());
resp.mutable_logon()->set_can_create(logon_response.result()->can_create());
}
else {
resp.mutable_logon()->set_reason(logon_response.result()->reason());
@@ -66,6 +66,10 @@ void UserServiceServer::authenticate_login(const api::user::AuthenticateLoginReq
resp.set_is_valid(user.is_active());
resp.set_user_id(user.id());
resp.mutable_token()->CopyFrom(api::auth::generate_token(user));
api::user::TokenPayload payload;
api::auth::decode_token(resp.token().token(), &payload);
resp.set_can_create(payload.wheel() || user.can_create());
respond(resp);
return;
}
+3 -1
View File
@@ -65,6 +65,7 @@ class PrivateContext {
this.ws.onmessage = e => this.onmessage(e)
console.log("Authenticated")
this.sc.token = response.logon.token
this.sc.can_create = response.logon.can_create
resolve(this.sc)
}
else {
@@ -121,7 +122,8 @@ class PrivateContext {
export class ServiceContext {
next_id : number
send : (msg)=>void
token : string
token: string
can_create: boolean
outstanding : { [request:number]:{ resolve : (buffer)=>void, reject: (msg)=>void } }
constructor(send : (msg)=>void) {
+4 -1
View File
@@ -33,6 +33,7 @@ let init (context:ServiceContext.ServiceContext) =
SelectedClipLimits = []
SelectedPositionLimits = []
token = context.token
can_create = context.can_create
}, Access.getAdminData admin context.token UpdateAdminData NoAdminData
let existingSelection (scratch:BTSAccount) (previousScratch:BTSAccount) (data:AdminData) =
@@ -189,8 +190,10 @@ let update msg (model:Model) : Model * Cmd<Msg> =
| true -> mdl, Cmd.ofExistingPromise (deleteAccount model.admin account model ) id (box>>ErrorOccured)
| false -> mdl, Cmd.Empty
| AddAccount ->
match model.can_create with
// Create a new scratch account. Send to server after user has filled in details
{ model with previousScratch = model.scratch; scratch = { emptyAccount with name = "New Account" } }, Cmd.ofMsg <| SelectTab General
| true-> { model with previousScratch = model.scratch; scratch = { emptyAccount with name = "New Account" } }, Cmd.ofMsg <| SelectTab General
| false-> model, Cmd.Empty
| SaveScratch ->
match isNewAccount model.scratch with
| true -> model, Cmd.ofExistingPromise (createAccount model.admin model.scratch model ) id (box>>ErrorOccured)
+1
View File
@@ -104,4 +104,5 @@ type Model = {
OptionsMenuOpen:string
ConfirmModal: string * Msg
token: string
can_create: bool
}
+5 -3
View File
@@ -12,6 +12,8 @@ open System
open bts.co2
let accountIsSelected (initialState:BTSAccount) (scratch:BTSAccount) = scratch <> initialState
let selectedAccount model =
match model.adminData with
| Some data ->
@@ -72,7 +74,7 @@ let generalView model dispatch =
Fields.text "Name" account.name [] (AccountName >> Update >> dispatch)
Fields.text "Description" account.description [] (Description >> Update >> dispatch)
Fields.checkbox "Can Trade Into Account" "Unchecking this stops all users from entering orders into the account" account.isActive [] (IsActive >> Update >> dispatch)
(if State.isNewAccount account then modal else span[][])
(if (State.isNewAccount account && model.can_create) then modal else span[][])
accountControls model dispatch
]
@@ -730,8 +732,8 @@ let exchangeSettings model dispatch =
let tabContent model dispatch =
div [Key (string model.scratch.id); ClassName "is-tab-content"] [
// (match model.tab with
(match model.tab, (selectedAccount model ) with
| _ , None -> p [Style [ Color "Red" ]] [ str "Select an Account" ]
(match model.tab, (accountIsSelected model.scratch Access.Accounts.empty) with
| _ , false -> p [Style [ Color "Red" ]] [ str "Select an Account" ]
| General, _ -> generalView model dispatch
| LimitsTab, _ -> LimitsView model dispatch
| ConnectionsTab, _ -> ConnectionsView model dispatch
+8 -5
View File
@@ -115,6 +115,7 @@ let init (context:ServiceContext.ServiceContext) : Model * Cmd<Msg> =
OptionsMenuOpen = ""
ConfirmModal = "", (Msg.SwitchTab Tab.General)
token = context.token
can_create = context.can_create
}, getAdminData admin context.token
let rec removeUser (user:BTSUser) (userList:BTSUser list) =
@@ -169,7 +170,7 @@ let deleteUser (admin:IAdminService) (user:BTSUser) (model:Model) = promise {
return ErrorOccured (sprintf "Error deleting user: %s" result.errorText)
}
let createUser (admin:IAdminService) (user:BTSUser) = promise {
let createUser (admin:IAdminService) (user:BTSUser) (model:Model)= promise {
let args : UserCreateAPIArgument = {
parentGroupId = user.parentGroupId
name = user.name
@@ -178,10 +179,10 @@ let createUser (admin:IAdminService) (user:BTSUser) = promise {
company = user.company
licenseData = user.licenseData
licenseEntitlements = user.licenseEntitlements
}
}
let! result = admin.create_user args
if result.isSuccess then
return! saveUser admin { user with id = result.newId }
return! saveUser admin { user with id = result.newId } model
else
return ErrorOccured (sprintf "Error creating user: %s" result.errorText)
}
@@ -300,7 +301,9 @@ let update msg (model:Users.Types.Model) : Model * Cmd<Msg> =
| false -> mdl, Cmd.Empty
| AddUser ->
{ model with PreviousScratchUser = model.scratchUser; scratchUser = { defaultScratchUser with name = "New User" }}, Cmd.ofMsg (SwitchTab General)
match model.can_create with
| true -> { model with PreviousScratchUser = model.scratchUser; scratchUser = { defaultScratchUser with name = "New User" }}, Cmd.ofMsg (SwitchTab General)
| false -> model, Cmd.Empty
| CancelAddUser ->
{ model with scratchUser = { model.PreviousScratchUser with name = "New User" }}, Cmd.ofMsg (SwitchTab General)
| SwitchTab tb ->
@@ -311,7 +314,7 @@ let update msg (model:Users.Types.Model) : Model * Cmd<Msg> =
| SaveUser ->
// match on id = 0 to see if it's a new user
match model.scratchUser.id with
| 0u -> { model with PreviousScratchUser = model.scratchUser}, Cmd.ofExistingPromise (createUser model.admin {model.scratchUser with name = model.scratchUser.name.ToLower() }) id (box>>ErrorOccured)
| 0u -> { model with PreviousScratchUser = model.scratchUser}, Cmd.ofExistingPromise (createUser model.admin {model.scratchUser with name = model.scratchUser.name.ToLower() } model) id (box>>ErrorOccured)
| _ -> model, Cmd.ofExistingPromise (saveUser model.admin {model.scratchUser with name = model.scratchUser.name.ToLower() } model) id (box>>ErrorOccured)
| ErrorOccured msg ->
//Browser.console.log msg
+1
View File
@@ -61,6 +61,7 @@ type Model = {
OptionsMenuOpen: string
ConfirmModal: string * Msg
token: string
can_create: bool
}
+3 -1
View File
@@ -38,6 +38,8 @@ let saveButton (model:Users.Types.Model) dispatch =
let enabled = if dirty then Button.Enabled else Button.Disabled
let flavor = if dirty then "is-success" else ""
Button.button buttonText flavor "" enabled (fun _ -> dispatch SaveUser)
let generalTabView (model:Model) (dispatch:Msg->Unit) (readonly: bool)=
let modal = Modal.showCreate
@@ -61,7 +63,7 @@ let generalTabView (model:Model) (dispatch:Msg->Unit) (readonly: bool)=
Fields.text "Company" model.scratchUser.company [Disabled readonly] (Company >> UpdateField >> dispatch)
Fields.checkbox "Can Login?" "Unchecking this stops the user from logging into Spark and entering orders" model.scratchUser.isActive [Disabled readonly] (IsActive >> UpdateField >> dispatch)
Fields.checkbox "Can Create?" "Checking this allows the user to create other users and accounts" model.scratchUser.canCreate [Disabled readonly] (CanCreate >> UpdateField >> dispatch)
(if State.isNewUser model.scratchUser then modal else span[][])
(if (State.isNewUser model.scratchUser) then modal else span[][])
]
let accountNameLookup (accountsList:BTSAccount list) (id:string) =