Implement login

This commit is contained in:
Les De Ridder 2017-02-14 02:47:23 +01:00
parent f05de6a52e
commit 200f737083
No known key found for this signature in database
GPG Key ID: 5EC132DFA85DB372
1 changed files with 104 additions and 5 deletions

View File

@ -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);
}