public async Task <ActionResult> StudentLogin(StudentLoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: return(RedirectToAction("Redirect", "StudentHome", new { area = "StudentArea" })); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } }
// GET: Student public ActionResult Index(StudentLoginViewModel model) { if (Validate(model)) { return(RedirectToAction("ViewRoomOrWaitingScreen", "Student", model)); } TempData["alertMessage"] = Resources.Resources.LoginInvalid; return(RedirectToAction("StudentLogin", "Account")); }
private bool Validate(StudentLoginViewModel model) { StudentData sData = rsContext.getStudent(model.PhoneNumber, model.Room); if (rsContext.getRoom(model.Room) != null && sData != null && sData.RoomId == model.Room) { return(true); } return(false); }
public async Task <IActionResult> Login([FromForm] StudentLoginViewModel studentLogin) { var student = await _db.GetAsync <Student>("SELECT id, username from students where studentId = @StudentId and password = @Password", studentLogin); if (student == null) { return(View("Index", new StudentLoginViewModel( studentLogin.StudentId, null, error: "Cannot find specified StudentId/Password combination"))); } return(RedirectToAction("Main", new { id = student.Id })); }
// GET: Student/ViewRoomOrWaitingScreen public ActionResult ViewRoomOrWaitingScreen(StudentLoginViewModel model) { RoomData roomData = rsContext.getRoom(model.Room); ActivityData activityData = rsContext.getActivity(roomData.CurrentActivityId); if (activityData == null) { //Waiting Screen return(RedirectToAction("Wait", model)); } else { if (activityData is TrueFalseQuestionData) { //True/False Question TrueFalseQuestion tfq = (TrueFalseQuestion)Adapting.getTrueFalseQuestionFromData((TrueFalseQuestionData)activityData); return(RedirectToAction("TrueFalseQuestion", new { expId = -1, currActivityIndex = -1, activityId = tfq.id, numOfActivities = 0, studentPhone = model.PhoneNumber, studentRoom = model.Room })); } else if (activityData is ShortAnswerQuestionData) { //Short Answer Question ShortAnswerQuestion saq = (ShortAnswerQuestion)Adapting.getShortAnswerQuestionFromData((ShortAnswerQuestionData)activityData); return(RedirectToAction("ShortAnswerQuestion", new { expId = -1, currActivityIndex = -1, activityId = saq.id, numOfActivities = 0, studentPhone = model.PhoneNumber, studentRoom = model.Room })); } else if (activityData is AmericanQuestionData) { //American Answer Question AmericanQuestion aq = (AmericanQuestion)Adapting.getAmericanQuestionFromData((AmericanQuestionData)activityData); return(RedirectToAction("AmericanQuestion", new { expId = -1, currActivityIndex = -1, activityId = aq.id, numOfActivities = 0, studentPhone = model.PhoneNumber, studentRoom = model.Room })); } else if (activityData is ExperimentData) { // Experiment Experiment exp = (Experiment)Adapting.getExperimentFromData((ExperimentData)activityData); if (exp.ActiveExpID == 0) { //Waiting Screen Thread.Sleep(2000); return(RedirectToAction("Wait", model)); } return(RedirectToAction("GroupCreation", new { expId = exp.id, studentPhone = model.PhoneNumber, studentRoom = model.Room, currActivityIndex = 0 })); } } return(View()); }
public async Task <IActionResult> PresenceStudent(StudentLoginViewModel studentLogin) { Student student = _mapper.Map <Student>(studentLogin); using (HttpClient client = new HttpClient()) { StringContent content = new StringContent(JsonConvert.SerializeObject(student.Register), Encoding.UTF8, "application/json"); HttpResponseMessage responseMessage = await client.PutAsync(Startup.UrlBase + "PresenceAPI/UpdateFrequency", content); if (responseMessage.StatusCode == System.Net.HttpStatusCode.NotFound) { ViewBag.Errors = "Usuário e/ou senha inválidos."; return(View("Index")); } string jsonResponse = await responseMessage.Content.ReadAsStringAsync(); User user = JsonConvert.DeserializeObject <User>(jsonResponse); List <Claim> userClaims = new List <Claim>() { //define o cookie new Claim(ClaimTypes.Name, user.Name), new Claim(ClaimTypes.Role, user.Role), new Claim(ClaimTypes.PrimarySid, user.UserName), new Claim(ClaimTypes.UserData, user.Token) }; ClaimsIdentity minhaIdentity = new ClaimsIdentity(userClaims, "Usuario"); ClaimsPrincipal userPrincipal = new ClaimsPrincipal(new[] { minhaIdentity }); //cria o cookie await HttpContext.SignInAsync(userPrincipal); return(View(user)); } }
// GET: Student/Wait public ActionResult Wait(StudentLoginViewModel studentLogin) { return(View(studentLogin)); }
// GET: /<controller>/ public async Task <IActionResult> LoginStudent(StudentLoginViewModel studentLoginVM) { Student student = await _context.Students.SingleOrDefaultAsync(s => s.TeacherUsername == studentLoginVM.TeacherUserName && s.Username == studentLoginVM.StudentUserName && s.Password == studentLoginVM.StudentPassword); return(RedirectToAction("ViewLists", new { StudentId = student.StudentId })); }