/// <summary> /// Jonathan Sanborn /// Called when a user logs out of the system /// </summary> public void Logout(MMControl mmControl) { currentSession.Duration = DateTime.Now - currentSession.Date; LoginRecords.Add(currentSession); mmControl.FileHandler.UpdateUser((IXMLnode)this); }
static string GetToken(string url, LoginRecords user) { var json = JsonConvert.SerializeObject(user); var data = new StringContent(json, Encoding.UTF8, "application/json"); using (var client = new HttpClient()) { var response = client.PostAsync(url, data).Result; string name = response.Content.ReadAsStringAsync().Result; dynamic details = JObject.Parse(name); return(details.token); } }
public IActionResult Login(LoginRecords user) { string token = GetToken("https://localhost:44353/api/Token", user); // string token = GetToken("http://52.191.222.87/api/Token", user); if (token != null) { return(RedirectToAction("Index", "Student", new { name = token })); } else { ViewBag.invalid = "UserId or Password invalid"; return(View()); } }
protected override bool CanSignIn(string username) { if (username == null) { return(false); } // check if concurrent login of user is reach limit if (ConcurrentMax > 0) { return(LoginRecords.Count(r => r.User.DisplayName.ToLower() == username.ToLower()) < ConcurrentMax); } return(base.CanSignIn(username)); }
public IActionResult Index() { LoginRecords obj = new LoginRecords { Userid = "admin", Password = "******" }; using (HttpClient client = new HttpClient()) { var token = GetToken("https://localhost:44353/api/Token", obj); client.BaseAddress = new Uri("https://localhost:44383/api/"); // MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json"); // client.DefaultRequestHeaders.Accept.Add(contentType); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = new HttpResponseMessage(); response = client.GetAsync("StudentRecords").Result; string stringData = response.Content.ReadAsStringAsync().Result; var data = JsonConvert.DeserializeObject <IEnumerable <StudentRecords> >(stringData); return(View(data)); } }