public IActionResult Login() { // If you can access this, you're essentially the authorized user. so give success response var userName = HttpContext.User.Identity.Name; var user = APISecurity.Login(userName); return(Ok(user)); }
public async Task <JsonResult> GetAllByCompany() { try { if (APISecurity.IsAllowAPIAccessByKey(roleName, "Admin")) { var list = _addOnService.GetAll().Result.ToList(); list = AddOnUtility.FilterByCompanyID(CurrentUser.CompanyID, list); return(Json(new { success = true, data = AddOnUtility.MsToVMs(list) }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = MessageUtility.NoAccessPriviledges() })); } } catch { return(Json(new { success = false }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Private method to talk to the Azure APIs. /// </summary> /// <param name="url">Url to hit.</param> /// <returns>JSON string.</returns> private string GetResponse(string url) { WebRequest request = WebRequest.Create(url); APISecurity.AddHeaders(request, APISecurity.APIKey); WebResponse response = null; try { response = (WebResponse)request.GetResponse(); } catch { throw; ////response = (WebResponse)ex.Response; } // you can use etag to decide the version of the report file. ////string etag = response.Headers["ETag"]; // you can use LastModified to decide if the report file is newer than the existing report in your system. this is as backup method. ETag is the primary one. ////string lastModified = response.Headers["LastModified"]; // the response from the service is byte[]. we decode it as string. if you like, you can use binary reader to keep it as byte[] StreamReader reader = null; string s = string.Empty; //// (int)response.StatusCode + "\t" + response.StatusDescription + "\r\n" + reader.ReadToEnd(); //append status code and message for displaying purpose try { reader = new StreamReader(response.GetResponseStream()); s = reader.ReadToEnd(); } catch (Exception e) { s = e.ToString(); } reader.Close(); response.Close(); return(s); }
public async Task <JsonResult> Insert(AddOnViewModel vm) { try { if (APISecurity.IsAllowAPIAccessByKey(roleName, "Admin")) { vm.ID = Guid.NewGuid().ToString(); vm.Company = new CompanyViewModel() { ID = CurrentUser.CompanyID }; var model = AddOnUtility.VMToM(vm); _addOnService.Insert(model); return(Json(new { success = true })); } else { return(Json(new { success = false, message = MessageUtility.NoAccessPriviledges() })); } } catch { return(Json(new { success = false, message = MessageUtility.ServerError() })); } }