From 54cb54d7eefc81905715bcaf95a573731913d527 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Fri, 1 Mar 2019 18:01:56 +0100 Subject: [PATCH] Rrefresh code post review di yeld... --- MConnectSDK/MConnectClient.cs | 102 +++++++++++++- MConnectSDK/Utils.cs | 16 ++- TestClient/MainForm.cs | 28 ++-- docs/mconnect-api-mconnectsdk.yaml | 214 +++++++++++++++++++++++++++++ 4 files changed, 347 insertions(+), 13 deletions(-) create mode 100644 docs/mconnect-api-mconnectsdk.yaml diff --git a/MConnectSDK/MConnectClient.cs b/MConnectSDK/MConnectClient.cs index 3a4c103..4766651 100644 --- a/MConnectSDK/MConnectClient.cs +++ b/MConnectSDK/MConnectClient.cs @@ -254,6 +254,51 @@ namespace MConnectSDK ML.setRSV(ML.redHash("UserListCache"), serVal); } } + /// + /// Utente corrente (SE login OK) + /// + protected userData currUser + { + get + { + userData answ = new userData(); + try + { + answ = JsonConvert.DeserializeObject(ML.getRSV(ML.redHash("CurrUser"))); + } + catch + { } + return answ; + } + set + { + string serVal = JsonConvert.SerializeObject(value); + // salvo MAX 2h + ML.setRSV(ML.redHash("CurrUser"), serVal, 60 * 60 * 2); + } + } + /// + /// Elenco utenti (in cache locale) + /// + protected List userPwdLocalCache + { + get + { + List answ = new List(); + try + { + answ = JsonConvert.DeserializeObject>(ML.getRSV(ML.redHash("UserPwdLocalCache"))); + } + catch + { } + return answ; + } + set + { + string serVal = JsonConvert.SerializeObject(value); + ML.setRSV(ML.redHash("UserPwdLocalCache"), serVal); + } + } /// /// Inizializzazione classe specificando tutti i parametri @@ -559,10 +604,14 @@ namespace MConnectSDK return answ; } } + /// + /// Recupera elenco user x organizzazione corrente + /// + /// public List getUserList() { List answ = new List(); - userData currUser; + userData _newUser; if (_currParam.testMode) { // cerco se li ho in cache... sennĂ² genero ex-novo @@ -577,7 +626,7 @@ namespace MConnectSDK // genero tanti utenti random... for (int i = 0; i < numUser; i++) { - currUser = new userData + _newUser = new userData { organizationCode = organizationCode, user_id = string.Format("{0}.{1:000}", organizationCode, numUser + i), @@ -589,7 +638,7 @@ namespace MConnectSDK Nome = string.Format("NOME_{0:000}", numUser + i), ImgUrl = string.Format(@"http://{{BASE_URL}}/{0}/user/{1}/image.png", organizationCode, numUser + i) }; - answ.Add(currUser); + answ.Add(_newUser); } } @@ -605,6 +654,53 @@ namespace MConnectSDK return answ; } + /// + /// Effettua login e restituisce dati utente + /// + /// + /// + /// + public userData doUserLogin(string username, string password) + { + userData answ = new userData(); + if (_currParam.testMode) + { + // cerco se li ho in cache... sennĂ² genero ex-novo + if (currUser.organizationCode != "" && currUser.user_id != "" && currUser.UserName == username) + { + answ = currUser; + } + else + { + // cerco in utenti simulati che ci sia + userData userFound = userListCache.Find(x => x.UserName == username); + if (userFound != null) + { + // cerco nelle pwd salvate: se lo trovo e NON HO una pwd --> accetto questa e salvo! + var pwdDataFound = userPwdLocalCache.Find(x => x.user_id == userFound.user_id); + if (pwdDataFound != null) + { + + } + else + { + + } + } + } + + // attesa... + Thread.Sleep(500); + } + else + { + /// TBD !!!FARE!!! le vere chiamate di testing remoto... + } + // salvo in cache locale (comunque...) + currUser = answ; + return answ; + } + #endregion } } diff --git a/MConnectSDK/Utils.cs b/MConnectSDK/Utils.cs index fb998ae..5ac1134 100644 --- a/MConnectSDK/Utils.cs +++ b/MConnectSDK/Utils.cs @@ -172,7 +172,7 @@ /// /// Codice dell'ORGANIZATION (es asfd) /// - public string organizationCode; + public string organizationCode = ""; /// /// Codice utente (es asfd.0002) /// @@ -206,4 +206,18 @@ /// public string ImgUrl = ""; } + /// + /// Classe info UTENTE + pwd (cifrata...) x cache localedi login + /// + public class userPwdData + { + /// + /// Codice utente (es asfd.0002) + /// + public string user_id = ""; + /// + /// Password (in formato cifrato) + /// + public string passwordCyph = ""; + } } diff --git a/TestClient/MainForm.cs b/TestClient/MainForm.cs index 31f868c..ef88380 100644 --- a/TestClient/MainForm.cs +++ b/TestClient/MainForm.cs @@ -239,7 +239,6 @@ namespace TestClient lblConsole.Text = sb.ToString(); }), ""); - //reqStatus = MCC.init(); userAuthData authData = MCC.tryAuthorize(); // recupero nuova reqStatus... reqStatus = MCC.reqStatusUpd; @@ -350,16 +349,27 @@ namespace TestClient { await Task.Run(() => { - //MCC = new MConnectClient(txtMConnectID.Text.Trim(), txtClientID.Text.Trim(), param); - //reqStatus = MCC.init(); + var userData = MCC.doUserLogin(user, pwd); - //// sistemo retVal - //saveTokenResp(); + synchronizationContext.Post(new SendOrPostCallback(o => + { + StringBuilder sb = new StringBuilder(); + sb.AppendLine("--------------------------------------------------"); + sb.AppendLine("USERS AUTH OK"); + sb.AppendLine("--------------------------------------------------"); + sb.AppendLine(""); + sb.AppendLine(string.Format("user_id: {0}", userData.user_id)); + sb.AppendLine(string.Format("isActive: {0}", userData.isActive)); + sb.AppendLine(string.Format("isAdmin: {0}", userData.isAdmin)); + sb.AppendLine(string.Format("UserName: {0}", userData.UserName)); + sb.AppendLine(string.Format("Email: {0}", userData.Email)); + sb.AppendLine(string.Format("Cognome: {0}", userData.Cognome)); + sb.AppendLine(string.Format("Nome: {0}", userData.Nome)); + sb.AppendLine(string.Format("ImgUrl: {0}", userData.ImgUrl)); + lblConsole.Text = sb.ToString(); - //synchronizationContext.Post(new SendOrPostCallback(o => - //{ - // refreshRequestStatus(); - //}), ""); + refreshRequestStatus(); + }), ""); }); } diff --git a/docs/mconnect-api-mconnectsdk.yaml b/docs/mconnect-api-mconnectsdk.yaml new file mode 100644 index 0000000..eb1f90e --- /dev/null +++ b/docs/mconnect-api-mconnectsdk.yaml @@ -0,0 +1,214 @@ +swagger: '2.0' +info: + version: 1.0.0 + title: MConnect + description: mconnect-api for maestroconnect SDK +host: api.maestroconnect.scmgroup.com +basePath: /api +schemes: + - http +consumes: + - application/json + - application/vnd.maestroconnect.username-login+json + - application/vnd.maestroconnect.email-login+json +produces: + - application/json +tags: + - name: Auth + - name: User +securityDefinitions: + Bearer: + description: Access with JWT + type: apiKey + name: Authorization + in: header + X-Api-Key: + description: Access with Api-Key + type: apiKey + name: Authorization + in: header +paths: + '/organizations/{organizationCode}/users': + get: + description: Get all organization users + operationId: getOrganizationUsers + security: + - Bearer: [] + parameters: + - name: organizationCode + in: path + description: BusinessCode of organization + required: true + type: string + tags: + - User + responses: + '200': + description: Organization users + schema: + type: array + items: + properties: + status: + type: string + statusCode: + type: integer + format: int64 + total: + type: integer + format: int64 + count: + type: integer + format: int64 + message: + type: string + result: + type: array + items: + properties: + Id: + type: string + Username: + type: string + '400': + description: Bad request + '401': + description: Unauthorized + '403': + description: Resource Forbidden + '/{organizationCode}/auth/login': + post: + description: User authentication + operationId: loginUser + tags: + - Auth + consumes: + - application/vnd.maestroconnect.username-login+json + - application/vnd.maestroconnect.email-login+json + parameters: + - name: organizationCode + in: path + description: BusinessCode of customer organization + required: true + type: string + - in: body + name: login + description: Login object + schema: + type: object + required: + - Username + - Password + properties: + Username: + type: string + Password: + type: string + responses: + '200': + description: User authenticated + schema: + type: object + properties: + status: + type: string + statusCode: + type: integer + format: int64 + message: + type: string + result: + type: object + properties: + user: + $ref: '#/definitions/User' + token: + type: string + refreshToken: + type: string + '400': + description: Bad request + schema: + $ref: '#/definitions/ErrorResponse' + + '401': + description: Unauthorized + schema: + $ref: '#/definitions/ErrorResponse' + '403': + description: Resource Forbidden + schema: + $ref: '#/definitions/ErrorResponse' + '404': + description: Not found + schema: + $ref: '#/definitions/ErrorResponse' + '500': + description: Connection refused from 3PSP (third party service provider) + schema: + $ref: '#/definitions/ErrorResponse' +definitions: + User: + type: object + properties: + Id: + type: string + IsActive: + type: boolean + IsAdmin: + type: boolean + Username: + type: string + Email: + type: string + Firstname: + type: string + Lastname: + type: string + Password: + type: string + Image_Url: + type: string + Language: + type: string + Role_Ids: + type: array + items: + properties: + Id: + type: string + Label: + type: string + Name: + type: string + Machine_Group_Ids: + type: array + items: + properties: + Id: + type: string + Name: + type: string + OrganizationCode: + type: string + Controller_Id: + type: string + Controller_Pwd: + type: string + ErrorResponse: + type: object + properties: + status: + type: string + statusCode: + type: number + message: + type: string + result: + properties: + error: + type: string + url: + type: string + label: + type: string