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() {
|
||||
|
Reference in New Issue
Block a user