Rrefresh code post review di yeld...

This commit is contained in:
Samuele E. Locatelli
2019-03-01 18:01:56 +01:00
parent b43ce351d9
commit 54cb54d7ee
4 changed files with 347 additions and 13 deletions
+99 -3
View File
@@ -254,6 +254,51 @@ namespace MConnectSDK
ML.setRSV(ML.redHash("UserListCache"), serVal);
}
}
/// <summary>
/// Utente corrente (SE login OK)
/// </summary>
protected userData currUser
{
get
{
userData answ = new userData();
try
{
answ = JsonConvert.DeserializeObject<userData>(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);
}
}
/// <summary>
/// Elenco utenti (in cache locale)
/// </summary>
protected List<userPwdData> userPwdLocalCache
{
get
{
List<userPwdData> answ = new List<userPwdData>();
try
{
answ = JsonConvert.DeserializeObject<List<userPwdData>>(ML.getRSV(ML.redHash("UserPwdLocalCache")));
}
catch
{ }
return answ;
}
set
{
string serVal = JsonConvert.SerializeObject(value);
ML.setRSV(ML.redHash("UserPwdLocalCache"), serVal);
}
}
/// <summary>
/// Inizializzazione classe specificando tutti i parametri
@@ -559,10 +604,14 @@ namespace MConnectSDK
return answ;
}
}
/// <summary>
/// Recupera elenco user x organizzazione corrente
/// </summary>
/// <returns></returns>
public List<userData> getUserList()
{
List<userData> answ = new List<userData>();
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;
}
/// <summary>
/// Effettua login e restituisce dati utente
/// </summary>
/// <param name="username"></param>
/// <param name="password"></param>
/// <returns></returns>
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
}
}
+15 -1
View File
@@ -172,7 +172,7 @@
/// <summary>
/// Codice dell'ORGANIZATION (es asfd)
/// </summary>
public string organizationCode;
public string organizationCode = "";
/// <summary>
/// Codice utente (es asfd.0002)
/// </summary>
@@ -206,4 +206,18 @@
/// </summary>
public string ImgUrl = "";
}
/// <summary>
/// Classe info UTENTE + pwd (cifrata...) x cache localedi login
/// </summary>
public class userPwdData
{
/// <summary>
/// Codice utente (es asfd.0002)
/// </summary>
public string user_id = "";
/// <summary>
/// Password (in formato cifrato)
/// </summary>
public string passwordCyph = "";
}
}
+19 -9
View File
@@ -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();
}), "");
});
}
+214
View File
@@ -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