// GET api/AuthTest public IEnumerable <AuthTest> Get(string token) { APIAuth.authorizeToken(token); string userName = APIAuth.getUserNameFromToken(token); return(db.AuthTests.Where(a => a.UserName.Equals(userName))); }
public ActionResult CustomerDepotEmail(string companyid, string customerid, string databasename) { APIAuth auth = new APIAuth(Request, Response); AuthInfo authInfo = auth.CheckLogin(); if (authInfo.IsAuthenticated) { var userCustomerDepotEmail = db.GetOnRentEmailAddress(companyid, customerid, databasename); return(Content(new JavaScriptSerializer().Serialize(userCustomerDepotEmail.ToList()), "application/json")); } else { return(auth.Forbidden()); } }
public ActionResult Customers() { APIAuth auth = new APIAuth(Request, Response); AuthInfo authInfo = auth.CheckLogin(); if (authInfo.IsAuthenticated) { var userCustomers = db.GetUserCustomersSync(authInfo.User.Id); return(Content(new JavaScriptSerializer().Serialize(userCustomers.ToList()), "application/json")); } else { return(auth.Forbidden()); } }
public IActionResult GetToken([FromForm] APIClient clientSrc) { IActionResult response = Unauthorized(); var client = this.CheckAuthentication(clientSrc); if (client != null) { var auth = new APIAuth(); auth.UserId = client.UserId; auth.Token = this.GenerateJsonWebToken(); response = this.Ok(auth); } return(response); }
// POST api/AuthTest?token=<token> //public HttpResponseMessage Post(Token<AuthTest> packet) public HttpResponseMessage Post(string token, AuthTest test) { //string token = packet.token; //AuthTest test = packet.obj; APIAuth.authorizeToken(token); test.UserName = APIAuth.getUserNameFromToken(token); db.AuthTests.Add(test); db.SaveChanges(); var response = Request.CreateResponse <AuthTest>(HttpStatusCode.Created, test); //var response = Request.CreateResponse(HttpStatusCode.Created); return(response); }
public ActionResult AccountManagerPicture(string databaseName, string customerId, string companyId) { APIAuth auth = new APIAuth(Request, Response); AuthInfo authInfo = auth.CheckLogin(); if (authInfo.IsAuthenticated) { Customer localCust = new Customer(); localCust.DatabaseName = databaseName; localCust.CustomerId = customerId; localCust.CompanyId = companyId; //Check if this user has access to this customer var userCustomers = db.GetUserCustomersSync(authInfo.User.Id); if (userCustomers.Count(x => x.CustomerKey == localCust.CustomerKey) > 0) { // Get the customer's account manager's details AccountManager accountManager = new OverviewDAL().GetAccountManagerDetailsSync(localCust).FirstOrDefault(); // Get the URL for the account manager's image string accountManagerImageURL = DownloadsHelper.GetAccountManagerImageURL(accountManager.Email); // Download the account manager image WebClient webClient = new WebClient(); byte[] accountManagerImageBytes = webClient.DownloadData(accountManagerImageURL); // Return the account manager image as bytes return(File(accountManagerImageBytes, System.Net.Mime.MediaTypeNames.Image.Jpeg)); } else { return(auth.Forbidden()); } } else { return(auth.Forbidden()); } }
public ActionResult AccountManagerDetails(string databaseName, string customerId, string companyId) { APIAuth auth = new APIAuth(Request, Response); AuthInfo authInfo = auth.CheckLogin(); if (authInfo.IsAuthenticated) { Customer localCust = new Customer(); localCust.DatabaseName = databaseName; localCust.CustomerId = customerId; localCust.CompanyId = companyId; //Check if this user has access to this customer var userCustomers = db.GetUserCustomersSync(authInfo.User.Id); if (userCustomers.Count(x => x.CustomerKey == localCust.CustomerKey) > 0) { //AccountManager accountManager = db.GetAccountManagerDetails(localCust).GetAwaiter().GetResult(); var accountManagers = db.GetAccountManagerDetailsSync(localCust); AccountManager accountManager = accountManagers.FirstOrDefault(); RentalsDAL dbRental = new RentalsDAL(); string depotEmail = dbRental.GetOnRentEmailAddressSync(localCust).FirstOrDefault();; accountManager.OnRentEmailAddress = depotEmail; return(Json(accountManager, JsonRequestBehavior.AllowGet)); } else { return(auth.Forbidden()); } } else { return(auth.Forbidden()); } }
public ActionResult Orders(DateTime startDate, DateTime endDate, string databaseName, string customerId, string companyId) { APIAuth auth = new APIAuth(Request, Response); AuthInfo authInfo = auth.CheckLogin(); if (authInfo.IsAuthenticated) { Customer localCust = new Customer(); localCust.DatabaseName = databaseName; localCust.CustomerId = customerId; localCust.CompanyId = companyId; //Check if this user has access to this customer var userCustomers = db.GetUserCustomersSync(authInfo.User.Id); //Customer selectedCompany = userCustomers.Where(x => x.CustomerKey == localCust.CustomerKey).First(); //return Json(new { foo = "ok", baz = "alee" }); //if (selectedCompany != null) if (userCustomers.Count(x => x.CustomerKey == localCust.CustomerKey) > 0) { IEnumerable <RentalOrder> orders; Customer activeCust = db.GetCustomer(localCust.DatabaseName, localCust.CompanyId, localCust.CustomerId); if (activeCust.showChildBROrders) { var validCustomers = new OverviewDAL().GetCustomersRegisteredSync().Where(x => x.DatabaseName == activeCust.DatabaseName && x.CompanyId == activeCust.CompanyId); orders = db.GetRentalOrdersChildBRSync(activeCust, startDate, endDate); orders = orders.Join(validCustomers, x => x.CustAccount, y => y.CustomerId, (ord, cust) => ord); } else { orders = db.GetRentalOrdersSync(localCust, startDate, endDate); } //need to manually add trackunit data RentalsDAL dbRental = new RentalsDAL(); IEnumerable <TrackUnitData> units = dbRental.GetTrackUnitDataSync(); using (var orderEnum = orders.GetEnumerator()) { while (orderEnum.MoveNext()) { RentalOrder order = orderEnum.Current; var unit = units.Where(x => x.ReferenceNumber == order.ObjectId).FirstOrDefault(); if (unit != null) { order.IsMachineLocalized = true; order.Latitude = unit.Latitude; order.Longitude = unit.Longitude; TimeSpan diffTime = DateTime.Now.Subtract(unit.GpsFixTime); if (diffTime.TotalMinutes > 240) { order.markerColor = "yellow"; } else if (unit.Speed > 15) { order.markerColor = "green"; } else if (unit.Input1.Value == true) { order.markerColor = "blue"; } else { order.markerColor = "red"; } } else { order.IsMachineLocalized = false; order.Latitude = 0.0; order.Longitude = 0.0; order.markerColor = ""; } } } //END trackunit //new CustomJsonResult( //return Content(new JavaScriptSerializer().Serialize(orders.ToList()), "application/json"); return(new CustomJsonResult { Data = orders.ToList() }); } else { return(Json(new { error = "No access" }, JsonRequestBehavior.AllowGet)); } } else { return(auth.Forbidden()); } }