PCRB webassembly
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
@ -15,8 +14,8 @@ using Fab2ApprovalSystem.DMO;
|
||||
using Microsoft.AspNet.Identity.Owin;
|
||||
using System.Net.Http;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
|
||||
namespace Fab2ApprovalSystem.Controllers {
|
||||
[Authorize]
|
||||
@ -129,6 +128,86 @@ namespace Fab2ApprovalSystem.Controllers {
|
||||
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<HttpResponseMessage> ExternalAuthSetup(AuthAttempt authAttempt) {
|
||||
try {
|
||||
bool isLoginValid;
|
||||
|
||||
HttpClient httpClient = HttpClientFactory.Create();
|
||||
httpClient.BaseAddress = new Uri(_apiBaseUrl);
|
||||
|
||||
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "auth/refresh");
|
||||
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(authAttempt),
|
||||
Encoding.UTF8,
|
||||
"application/json");
|
||||
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(request);
|
||||
|
||||
if (!httpResponseMessage.IsSuccessStatusCode)
|
||||
throw new Exception($"The authentication API failed, because {httpResponseMessage.ReasonPhrase}");
|
||||
|
||||
string responseContent = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
|
||||
LoginResult loginResult = JsonConvert.DeserializeObject<LoginResult>(responseContent);
|
||||
|
||||
#if(DEBUG)
|
||||
isLoginValid = true;
|
||||
|
||||
#endif
|
||||
#if (!DEBUG)
|
||||
|
||||
bool isIFX = false;
|
||||
//domainProvider = Membership.Providers["NA_ADMembershipProvider"];
|
||||
//isLoginValid = domainProvider.ValidateUser(model.LoginID, model.Password);
|
||||
|
||||
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
|
||||
isLoginValid = true;
|
||||
} else {
|
||||
isLoginValid = loginResult.IsAuthenticated;
|
||||
if (isLoginValid) isIFX = true;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (isLoginValid) {
|
||||
UserAccountDMO userDMO = new UserAccountDMO();
|
||||
LoginModel user = userDMO.GetUser(authAttempt.LoginID);
|
||||
if (user != null) {
|
||||
Session["JWT"] = loginResult.AuthTokens.JwtToken;
|
||||
Session["RefreshToken"] = loginResult.AuthTokens.RefreshToken;
|
||||
|
||||
Session[GlobalVars.SESSION_USERID] = user.UserID;
|
||||
Session[GlobalVars.SESSION_USERNAME] = user.FullName;
|
||||
Session[GlobalVars.IS_ADMIN] = user.IsAdmin;
|
||||
Session[GlobalVars.IS_MANAGER] = user.IsManager;
|
||||
Session[GlobalVars.OOO] = user.OOO;
|
||||
Session[GlobalVars.CAN_CREATE_PARTS_REQUEST] = user.IsAdmin || PartsRequestController.CanCreatePartsRequest(user.UserID);
|
||||
|
||||
FormsAuthentication.SetAuthCookie(user.LoginID, true);
|
||||
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
} else {
|
||||
ModelState.AddModelError("", "The user name does not exist in the DB. Please contact the System Admin");
|
||||
|
||||
return new HttpResponseMessage(HttpStatusCode.NotFound);
|
||||
}
|
||||
} else {
|
||||
ModelState.AddModelError("", "The user name or password provided is incorrect.");
|
||||
|
||||
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Functions.WriteEvent(@User.Identity.Name + " " + ex.InnerException, System.Diagnostics.EventLogEntryType.Error);
|
||||
EventLogDMO.Add(new WinEventLog() { IssueID = 99999, UserID = @User.Identity.Name, DocumentType = "Login", OperationType = "Error", Comments = "Reject - " + ex.Message });
|
||||
ModelState.AddModelError("", ex.Message);
|
||||
|
||||
return new HttpResponseMessage(HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
// GET: /Account/Register
|
||||
[AllowAnonymous]
|
||||
public ActionResult Register() {
|
||||
|
@ -102,53 +102,15 @@ namespace Fab2ApprovalSystem.Controllers
|
||||
// GET: /MRB/Edit/5
|
||||
public ActionResult Edit(int issueID)
|
||||
{
|
||||
MRB mrb = new MRB();
|
||||
int isITARCompliant = 1;
|
||||
ViewBag.Status = "Pending";
|
||||
ViewBag.IsApprover = "false";
|
||||
ViewBag.IsCloser = "false";
|
||||
string jwt = Session["JWT"].ToString();
|
||||
string encodedJwt = System.Net.WebUtility.UrlEncode(jwt);
|
||||
string refreshToken = Session["RefreshToken"].ToString();
|
||||
string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken);
|
||||
string wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ??
|
||||
"https://localhost:7255";
|
||||
string mrbUrl = $"{wasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/mrb/{issueID}";
|
||||
|
||||
//ViewBag.IsApproved = "false";
|
||||
//ViewBag.IsClosed = "false";
|
||||
PopulateCloseToQDB();
|
||||
mrb = mrbDMO.GetMRBItem(issueID, out isITARCompliant, (int)Session[GlobalVars.SESSION_USERID]);
|
||||
ViewBag.UserList = mrbDMO.GetUserList();
|
||||
|
||||
if (isITARCompliant == 0) // not ITAR Compliant
|
||||
{
|
||||
return View("UnAuthorizedAccess");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mrb.ApprovalStatus == (int)GlobalVars.ApprovalOption.Approved)
|
||||
{
|
||||
//ViewBag.IsApproved = "true";
|
||||
ViewBag.Status = "Approved";
|
||||
}
|
||||
else if (mrb.ApprovalStatus == (int)GlobalVars.ApprovalOption.Closed)
|
||||
{
|
||||
ViewBag.Status = "Closed";
|
||||
//ViewBag.IsClosed = "true";
|
||||
}
|
||||
List<ApproversListViewModel> userList = MiscDMO.GetApproversListByDocument(issueID, mrb.CurrentStep, (int)GlobalVars.DocumentType.MRB);
|
||||
ApproversListViewModel appUser = userList.Find(delegate (ApproversListViewModel al) { return al.UserID == (int)Session[GlobalVars.SESSION_USERID]; });
|
||||
if (appUser != null)
|
||||
{
|
||||
ViewBag.IsApprover = "true";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// can edit
|
||||
ViewBag.Owners = MiscDMO.GetUserList();
|
||||
ViewBag.Modules = mrbDMO.GetModules();
|
||||
//ViewBag.Dispositions = mrbDMO.GetDispositions();
|
||||
ViewBag.RiskAssessments = mrbDMO.GetRiskAssessments();
|
||||
ViewBag.PartGroups = mrbDMO.GetPartGroups();
|
||||
ViewBag.DispoTypes = mrbDMO.GetDispositions(issueID).Select(d => new { d.DispositionType });
|
||||
|
||||
return View(mrb);
|
||||
return Redirect(mrbUrl);
|
||||
}
|
||||
|
||||
//
|
||||
@ -178,39 +140,15 @@ namespace Fab2ApprovalSystem.Controllers
|
||||
/// <returns></returns>
|
||||
public ActionResult ReadOnly(int issueID)
|
||||
{
|
||||
MRB mrb = new MRB();
|
||||
int isITARCompliant = 1;
|
||||
string jwt = Session["JWT"].ToString();
|
||||
string encodedJwt = System.Net.WebUtility.UrlEncode(jwt);
|
||||
string refreshToken = Session["RefreshToken"].ToString();
|
||||
string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken);
|
||||
string wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ??
|
||||
"https://localhost:7255";
|
||||
string mrbUrl = $"{wasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/mrb/{issueID}";
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (isITARCompliant == 0) // not ITAR Compliant
|
||||
{
|
||||
return View("UnAuthorizedAccess");
|
||||
}
|
||||
else
|
||||
{
|
||||
mrb = mrbDMO.GetMRBItem(issueID, out isITARCompliant, (int)Session[GlobalVars.SESSION_USERID]);
|
||||
|
||||
ViewBag.Owners = MiscDMO.GetUserList();
|
||||
ViewBag.Modules = mrbDMO.GetModules();
|
||||
//ViewBag.Dispositions = mrbDMO.GetDispositions();
|
||||
ViewBag.RiskAssessments = mrbDMO.GetRiskAssessments();
|
||||
ViewBag.PartGroups = mrbDMO.GetPartGroups();
|
||||
ViewBag.DispoTypes = mrbDMO.GetDispositions(issueID).Select(d => new { d.DispositionType });
|
||||
}
|
||||
|
||||
return View(mrb);
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "IssueID=" + issueID.ToString() + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
|
||||
Functions.WriteEvent(@User.Identity.Name + "\r\n ReadOnly Disposition\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error);
|
||||
EventLogDMO.Add(new WinEventLog() { IssueID = issueID, UserID = @User.Identity.Name, DocumentType = "Lot Disposition", OperationType = "Error", Comments = exceptionString });
|
||||
throw new Exception(e.Message);
|
||||
|
||||
}
|
||||
return Redirect(mrbUrl);
|
||||
}
|
||||
|
||||
//
|
||||
|
Reference in New Issue
Block a user