public IActionResult Administration(ViewModel.AdminControllerAdministrationViewModel am) { try { if (am.CreateAdmin.CreateEmail != null) { Services.Hashing hashing = new Services.Hashing(); string hash = hashing.CreateHashing(am.CreateAdmin.CreatePassword); store.AddNewUser(am.CreateAdmin.CreateEmail, hash, am.CreateAdmin.CreateSecurityLevel); return(Redirect("/Admin/Administration")); } else if (am.CreateClass.CreateClass != null) { string classes = am.CreateClass.CreateClass; store.SaveClass(classes, am.CreateClass.SelectedEmail); return(Redirect("/Admin/Administration")); } else if (am.CreateTeam.CreateTeam != null) { string team = am.CreateTeam.CreateTeam; store.SaveTeam(team); return(Redirect("/Admin/Administration")); } return(View(am)); } catch (Exception) { return(View()); } }
public IActionResult Index(Models.Home.Index m, string submit) { try { if (submit == "teacher") { Services.Hashing hashing = new Services.Hashing(); string hashedPass = hashing.CreateHashing(m.Password); int userType = 2; string errorMessage = ""; db.ValidateUser(m.Email, hashedPass, ref errorMessage, ref userType); m.ErrorMessage = errorMessage; string cookieValue = m.Email + "-" + hashedPass + "-" + userType; var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions() { HttpOnly = true, Expires = DateTime.Now.AddDays(7) }; if (Response != null) { Response.Cookies.Append("User", cookieValue, cookieOptions); } if (userType == 0) { return(Redirect("/Teacher/Opret/")); } else if (userType == 1) { return(Redirect("/Admin/Administration/")); } else { ViewBag.ErrorMessage = errorMessage; } } else { bool check = db.CheckSurveyCode(m.SurveyCode); string cookieValue = m.SurveyCode; var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions() { HttpOnly = true, Expires = DateTime.Now.AddDays(7) }; if (Response != null) { Response.Cookies.Append("SurveyCode", cookieValue, cookieOptions); } if (check == true) { return(Redirect("/Student/OpretSvar/")); } } } catch { m.ErrorMessage = "Felterne skal udfyldes"; ViewBag.ErrorMessage = m.ErrorMessage; } return(View(m)); }