WEB: GNS passwords
This commit is contained in:
@@ -32,20 +32,20 @@
|
||||
public static IHttpClient CreateHttpClient(string baseURI, string routePrefix)
|
||||
=> new HttpClient(baseURI, routePrefix);
|
||||
|
||||
public IHttpMessage Delete(string route)
|
||||
=> new HttpMessage(this, HttpMethod.Delete, $"{routePrefix}/{route.TrimStart('/')}");
|
||||
public IHttpMessage Delete(string route, bool full = false)
|
||||
=> new HttpMessage(this, HttpMethod.Delete, this.Route(route, full));
|
||||
|
||||
public IHttpMessage Get(string route)
|
||||
=> new HttpMessage(this, HttpMethod.Get, $"{routePrefix}/{route.TrimStart('/')}");
|
||||
public IHttpMessage Get(string route, bool full = false)
|
||||
=> new HttpMessage(this, HttpMethod.Get, this.Route(route, full));
|
||||
|
||||
public IHttpMessage Options(string route)
|
||||
=> new HttpMessage(this, HttpMethod.Options, $"{routePrefix}/{route.TrimStart('/')}");
|
||||
public IHttpMessage Options(string route, bool full = false)
|
||||
=> new HttpMessage(this, HttpMethod.Options, this.Route(route, full));
|
||||
|
||||
public IHttpMessage Post(string route)
|
||||
=> new HttpMessage(this, HttpMethod.Post, $"{routePrefix}/{route.TrimStart('/')}");
|
||||
public IHttpMessage Post(string route, bool full = false)
|
||||
=> new HttpMessage(this, HttpMethod.Post, this.Route(route, full));
|
||||
|
||||
public IHttpMessage Put(string route)
|
||||
=> new HttpMessage(this, HttpMethod.Put, $"{routePrefix}/{route.TrimStart('/')}");
|
||||
public IHttpMessage Put(string route, bool full = false)
|
||||
=> new HttpMessage(this, HttpMethod.Put, this.Route(route, full));
|
||||
|
||||
internal async Task<IHttpResponse<T>> SendAsync<T>(HttpMessage fluentHttpRequestMessage)
|
||||
{
|
||||
@@ -87,5 +87,10 @@
|
||||
|
||||
return httpResult;
|
||||
}
|
||||
|
||||
private string Route(string route, bool full)
|
||||
{
|
||||
return full ? route : $"{routePrefix}/{route.TrimStart('/')}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
{
|
||||
public interface IHttpClient
|
||||
{
|
||||
IHttpMessage Delete(string route);
|
||||
IHttpMessage Delete(string route, bool full = false);
|
||||
|
||||
IHttpMessage Get(string route);
|
||||
IHttpMessage Get(string route, bool full = false);
|
||||
|
||||
IHttpMessage Options(string route);
|
||||
IHttpMessage Options(string route, bool full = false);
|
||||
|
||||
IHttpMessage Post(string url);
|
||||
IHttpMessage Post(string route, bool full = false);
|
||||
|
||||
IHttpMessage Put(string url);
|
||||
IHttpMessage Put(string route, bool full = false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
using System.Web.Http;
|
||||
|
||||
[RoutePrefix(ROUTE_PREFIX)]
|
||||
public class SendController : ApiController
|
||||
public class SendController : ControllerBase
|
||||
{
|
||||
const string ROUTE_PREFIX = "api/Send";
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
if (!this.ModelState.IsValid)
|
||||
{
|
||||
response = this.BadRequest(this.ModelState.ErrorsJson());
|
||||
response = this.BadRequest();
|
||||
}
|
||||
else if (!this.TrySendEmail(model, out string state))
|
||||
{
|
||||
@@ -146,6 +146,7 @@
|
||||
|
||||
return recordId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class SendModel
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
namespace LaaProductionWeb.Controllers
|
||||
{
|
||||
using LaaProductionDI;
|
||||
using LaaProduction.Personalization;
|
||||
using LaaProduction.Http.Interfaces;
|
||||
using LaaProductionWeb.App_Infrastructure;
|
||||
using LaaProduction.Services.Interfaces;
|
||||
using LaaProduction.Services.Models.Search;
|
||||
using LaaProductionDI;
|
||||
using LaaProductionWeb.API;
|
||||
using LaaProductionWeb.App_Infrastructure;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -103,5 +104,157 @@
|
||||
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[AllowedRoles(EmployeesRoles.WEB_Passwords)]
|
||||
public async Task<ActionResult> Passwords()
|
||||
{
|
||||
var fieldsResult = await this.httpClient
|
||||
.Get("/Search/Wildcard")
|
||||
.AuthorizeBearer(this.User.GetNameIdentifier())
|
||||
.SendAsync<IEnumerable<string>>();
|
||||
|
||||
var model = new SearchPasswordsModel();
|
||||
|
||||
if (fieldsResult.Succeeded)
|
||||
{
|
||||
if (fieldsResult.Value != null)
|
||||
{
|
||||
model.Fields = fieldsResult.Value.ToDictionary(x => x, x => true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ModelState.AddModelErrors(fieldsResult);
|
||||
}
|
||||
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowedRoles(EmployeesRoles.WEB_Passwords)]
|
||||
public async Task<ActionResult> Passwords(SearchPasswordsModel model)
|
||||
{
|
||||
var fields = string.Empty;
|
||||
|
||||
if (model.Fields.Any(x => x.Value))
|
||||
{
|
||||
fields = WebUtility.UrlEncode(string.Join(",", model.Fields.Where(x => x.Value).Select(x => x.Key)));
|
||||
}
|
||||
|
||||
// http://10.49.40.25/MeterProcessState/api/FinalCheck/GetEncryptionKey?PcbID=45451
|
||||
|
||||
var httpResult = await this.httpClient
|
||||
.Post($"/Search/Wildcard")
|
||||
.WhitJsonBody(new { model.Token, fields })
|
||||
.AuthorizeBearer(this.User.GetNameIdentifier())
|
||||
.SendAsync<IEnumerable<IDictionary<string, object>>>();
|
||||
|
||||
if (httpResult.Succeeded)
|
||||
{
|
||||
model.Results = httpResult.Value ?? Array.Empty<IDictionary<string, object>>();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ModelState.AddModelErrors(httpResult);
|
||||
}
|
||||
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
public async Task<string> FS(string pcbid)
|
||||
{
|
||||
var userId = this.User?.Identity?.Name;
|
||||
var email = this.ordersService.GetUserEmail(userId);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(email) || email.Length < 11)
|
||||
{
|
||||
email = "Roland.Drabesch@xylem.com";
|
||||
|
||||
// return "Leider kanst Du keine Funkschlüssel anfordern!";
|
||||
}
|
||||
|
||||
var result = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
var httpResult = await this.httpClient
|
||||
.Get($"http://10.49.40.25/MeterProcessState/api/FinalCheck/GetEncryptionKey?PcbID={pcbid}", full: true)
|
||||
.SendAsync<string>();
|
||||
|
||||
if (httpResult.Succeeded)
|
||||
{
|
||||
result = httpResult.Value?.ToUpper();
|
||||
}
|
||||
|
||||
// TODO: remove in the feature
|
||||
//using (var httpClient = new HttpClient())
|
||||
//{
|
||||
// using (var httpResponse = await httpClient.GetAsync($"http://10.49.40.25/MeterProcessState/api/FinalCheck/GetEncryptionKey?PcbID={pcbid}"))
|
||||
// {
|
||||
// if (httpResponse.Content != null)
|
||||
// {
|
||||
// result = await httpResponse.Content.ReadAsStringAsync();
|
||||
// result = result?.ToUpper();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
result = e.ToString();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await this.httpClient
|
||||
.Post("api/Send/Email")
|
||||
.WhitJsonBody(new SendModel
|
||||
{
|
||||
Body = $"MitarbeiterNr: {userId} => PcbID: {pcbid}",
|
||||
CC = new string [] { "Roland.Drabesch@xylem.com", "Stoyan.Zlatev@xylem.com" },
|
||||
IPAddress = HttpContext.Request.UserHostAddress,
|
||||
IsHtml = false,
|
||||
PCName = HttpContext.Request.UserHostName,
|
||||
Recipients = new string[] { "Roland.Drabesch@xylem.com", "Stoyan.Zlatev@xylem.com" },
|
||||
Sender = email,
|
||||
StationNr = "0000",
|
||||
Subject = "Funkschlüssel wurde angefragt.",
|
||||
Trace = $"{nameof(SearchController)}.{nameof(FS)}"
|
||||
})
|
||||
.SendAsync<string>();
|
||||
|
||||
// TODO: remove in the feature
|
||||
//this.smtpClient
|
||||
// .CreateMessage()
|
||||
// .Subject("Funkschlüssel wurde angefragt.")
|
||||
// .Body($"MitarbeiterNr: {userId} => PcbID: {pcbid}")
|
||||
// .From(email)
|
||||
// .To("Roland.Drabesch@xylem.com")
|
||||
// .CC("Stoyan.Zlatev@xylem.com")
|
||||
// .Send();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await this.httpClient
|
||||
.Post("api/Send/Email")
|
||||
.WhitJsonBody(new SendModel
|
||||
{
|
||||
Body = $"{e}",
|
||||
CC = new string[] { "Roland.Drabesch@xylem.com", "Stoyan.Zlatev@xylem.com" },
|
||||
IPAddress = HttpContext.Request.UserHostAddress,
|
||||
IsHtml = false,
|
||||
PCName = HttpContext.Request.UserHostName,
|
||||
Recipients = new string[] { "Roland.Drabesch@xylem.com", "Stoyan.Zlatev@xylem.com" },
|
||||
Sender = email,
|
||||
StationNr = "0000",
|
||||
Subject = "Funkschlüssel wurde angefragt.",
|
||||
Trace = $"{nameof(SearchController)}.{nameof(FS)}"
|
||||
})
|
||||
.SendAsync<string>();
|
||||
}
|
||||
|
||||
return result.Trim('"');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user