From 200f7370835f96663dfa42088cfe905a686642b3 Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Tue, 14 Feb 2017 02:47:23 +0100 Subject: [PATCH] Implement login --- source/app.d | 109 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 104 insertions(+), 5 deletions(-) diff --git a/source/app.d b/source/app.d index 1c182db..4f62de5 100644 --- a/source/app.d +++ b/source/app.d @@ -1,6 +1,8 @@ import std.stdio; import std.conv; +import core.sys.linux.unistd; + import vibe.d; import vibe.data.json; import vibe.textfilter.urlencode; @@ -61,6 +63,31 @@ class StartFlow : ApiRequest } } +class WidgetEvents : ApiRequest +{ + string applicationId; + Json[string][] widgetEventInformations; + + this(string applicationId, string[string] widgetEventInformations, string[string] attributes) + { + this.applicationId = applicationId; + + Json[string] eventInformations; + foreach(key, value; widgetEventInformations) + { + eventInformations[key] = value.serializeToJson; + } + this.widgetEventInformations = [eventInformations]; + + Json[string] jsonAttributes; + foreach(key, value; attributes) + { + jsonAttributes[key] = value.serializeToJson; + } + this.widgetEventInformations[0]["attributes"] = jsonAttributes; + } +} + class ApiMessage { string executionMode; @@ -99,7 +126,7 @@ class SessionApiMessage : ApiMessage class ApiClient { - enum string Endpoint = "https://m.belfius.be/F2CRenderingDexiaToClient/GEPARendering/machineIdentifier=s0/"; + enum string Endpoint = "https://m.belfius.be/F2CRenderingDexiaToClient/GEPARendering/machineIdentifier=s4/"; private string _locale; @@ -120,13 +147,78 @@ class ApiClient _sessionId = response.responseSets[0].responses[0]["SessionOpened"][0]["sessionId"].get!string; _requestCounter = 1; - auto startFlowRequest = new StartFlow("yui3a", "Container", "gef0.gef1.gemd.Flow_MobileApplication.diamlflow", ["deviceType": "simple", "language": "2", "smsType": "otpUrl"], null); + auto startFlowRequest = new StartFlow("yui3a", "Container", "gef0.gef1.gemd.Flow_MobileApplication.diamlflow", + ["deviceType": "simple", "language": "2", "smsType": "otpUrl"], null); response = sendRequest("sequential", startFlowRequest); } - ApiResponse sendRequest(T : ApiRequest)(string executionMode, T request) + void login1(string cardNumber, string phoneZone, string phoneSubscriber) { + auto widgetEventsRequest = createClickImageEvent("Container@reuse_Screen@img_Operations"); + sendRequest("sequential", widgetEventsRequest); + widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_PanNumbersimple", cardNumber[0 .. 4]); + sendRequest("sequential", widgetEventsRequest); + + widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_PanNumbersimple", cardNumber); + sendRequest("sequential", widgetEventsRequest); + + widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_PhoneZone", phoneZone); + sendRequest("sequential", widgetEventsRequest); + + widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_PhoneSubscriber", phoneSubscriber); + sendRequest("sequential", widgetEventsRequest); + + widgetEventsRequest = createClickButtonEvent("Container@reuse_flowAuthentication@btn_Identification"); + sendRequest("sequential", widgetEventsRequest); + } + + void login2(string otp, string password) + { + auto widgetEventsRequest = createClickImageEvent("Container@reuse_Screen@img_Operations"); + sendRequest("sequential", widgetEventsRequest); + + widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_otp", otp); + sendRequest("sequential", widgetEventsRequest); + + widgetEventsRequest = createChangeValueEvent("Container@reuse_flowAuthentication@inp_pw", password); + sendRequest("sequential", widgetEventsRequest); + + widgetEventsRequest = createClickButtonEvent("Container@reuse_flowAuthentication@btn_Identification"); + sendRequest("sequential", widgetEventsRequest); + } + + WidgetEvents createClickImageEvent(string widgetId) + { + return new WidgetEvents("Container", [ + "widgetId": widgetId, + "eventType": "clicked", + "widgetType": "Image", + ], null); + } + + WidgetEvents createClickButtonEvent(string widgetId) + { + return new WidgetEvents("Container", [ + "widgetId": widgetId, + "eventType": "clicked", + "widgetType": "ActionButton", + ], null); + } + + WidgetEvents createChangeValueEvent(string widgetId, string value) + { + return new WidgetEvents("Container", [ + "widgetId": widgetId, + "eventType": "valueChanged", + "widgetType": "Input", + ], [ + "text": value + ]); + } + + private ApiResponse sendRequest(T : ApiRequest)(string executionMode, T request) + { string requestString; if(_sessionId !is null) { @@ -141,6 +233,8 @@ class ApiClient requestString = message.serializeToJsonString; } + writeln("C> " ~ requestString); + auto response = requestHTTP(Endpoint, (scope request) { request.method = HTTPMethod.POST; @@ -151,9 +245,9 @@ class ApiClient } ).bodyReader.readAllUTF8; - auto json = response.parseJsonString; + writeln("S> " ~ response); - return json.deserializeJson!ApiResponse; + return response.parseJsonString.deserializeJson!ApiResponse; } } @@ -171,4 +265,9 @@ shared static this() auto apiClient = new ApiClient("nl_BE"); apiClient.connect(); + apiClient.login1("67030514325746009", "0470", "854404"); + write("OTP: "); + auto otp = readln()[0 .. $-1]; + auto password = fromStringz(getpass("Password: ")).idup; + apiClient.login2(otp, password); }