public ActionResult LoginAsEmployer(LoginModel model, string returnUrl) { if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { return RedirectToLocal(returnUrl); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "Името или паролата са невалидни."); return View(model); }
public ActionResult LoginAsStudent(LoginModel model, string returnUrl) { if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { return RedirectToLocal(returnUrl); } else if (ModelState.IsValid && !WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { try { // get SUSI info SusiParser.SusiParser parser = new SusiParser.SusiParser(); parser.Login(model.UserName, model.Password); StudentInfo info = parser.GetStudentInfo(); IEnumerable<CourseInfo> courses = parser.GetCourses(); // Create user in local database WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); // Fill info int userId = int.Parse(Membership.GetUser(model.UserName).ProviderUserKey.ToString()); studentManager.AddStudent(userId, info, courses, model.UserName); var roles = (SimpleRoleProvider)Roles.Provider; roles.AddUsersToRoles(new[] { model.UserName }, new[] { "student" }); if (returnUrl != null) { return Redirect(returnUrl); } return RedirectToAction("Profile", "Student", new { profileId = userId }); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); Debug.WriteLine(e.Message); } catch (System.Net.WebException e) { ModelState.AddModelError("", e.Message); Debug.WriteLine(e.Message); } } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); return View("LoginAsStudent", model); }
public void UpdateSusi(LoginModel model) { if (ModelState.IsValid) { if (WebSecurity.Login(model.UserName, model.Password)) { try { // get SUSI info SusiParser.SusiParser parser = new SusiParser.SusiParser(); parser.Login(model.UserName, model.Password); StudentInfo info = parser.GetStudentInfo(); IEnumerable<CourseInfo> courses = parser.GetCourses(); // Fill info int userId = int.Parse(Membership.GetUser(model.UserName).ProviderUserKey.ToString()); studentManager.FillInSusiInfo(studentManager.GetStudentByUserId(userId), info, courses); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", e.Message); Debug.WriteLine(e.Message); } catch (System.Net.WebException e) { ModelState.AddModelError("", e.Message); Debug.WriteLine(e.Message); } } else { Response.StatusCode = 400; } } }