public async Task <bool> Login(LoginViewModel model) { var json = string.Empty; string password = HashPasswordSha256(model.Password); string url = "https://studservice.hogent.be/auth" + "/" + model.Email + "/" + password; using (HttpClient hc = new HttpClient()) { json = await hc.GetStringAsync(url); //wc.DownloadString(url); } dynamic array = JsonConvert.DeserializeObject(json); if (array.Equals("[]")) { return(true); } var name = array.NAAM.ToString(); var vnaam = array.VOORNAAM.ToString(); Type = array.TYPE.ToString(); var faculteit = array.FACULTEIT.ToString(); Email = array.EMAIL.ToString(); Gebruiker gebruiker = repository.FindByName(model.Email); if (gebruiker == null) { if (Type.ToLower().Equals("student")) { gebruiker = new Student() { Naam = vnaam + " " + name, Email = Email, Faculteit = faculteit }; } else { gebruiker = new Lector { Naam = vnaam + " " + name, Email = Email, Faculteit = faculteit }; } gebruiker.Verlanglijst = new Verlanglijst(); gebruiker.Reservaties = new List <Reservatie>(); repository.AddGebruiker(gebruiker); repository.SaveChanges(); } return(false); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { if (controllerContext.HttpContext.User.Identity.IsAuthenticated) { IGebruikerRepository repos = (IGebruikerRepository)DependencyResolver.Current.GetService(typeof(IGebruikerRepository)); Gebruiker gebruiker = repos.FindByName(controllerContext.HttpContext.User.Identity.Name); if (gebruiker == null) { if (controllerContext.HttpContext.User.Identity.Name.Contains("@student.hogent")) { gebruiker = new Student() { Naam = "Student", Email = controllerContext.HttpContext.User.Identity.Name }; } else { gebruiker = new Lector { Naam = "Lector", Email = controllerContext.HttpContext.User.Identity.Name, }; } gebruiker.Verlanglijst = new Verlanglijst(); gebruiker.Reservaties = new List <Reservatie>(); repos.AddGebruiker(gebruiker); repos.SaveChanges(); } if (gebruiker.Verlanglijst == null) { gebruiker.Verlanglijst = new Verlanglijst(); repos.SaveChanges(); } controllerContext.HttpContext.Session[VerlanglijstSessionKey] = gebruiker; // Op basis van controllerContext.HttpContext.User.Identity.Name kunnen we niet weten of de gebruiker // al dan niet een lector is... Hier moet nog een oplossing voor gezocht worden. return(gebruiker); } return(null); }