/// <summary> /// 更新用户信息 /// </summary> /// <param name="model">用户资料</param> /// <returns></returns> public QssResult QssUpdateUserInfo(QssSicauLoginHelper login, UserType type, out User user) { // 判断学生还是教师 if (type == UserType.S) { string[] _stuInfo = login.GetStuInfo(); if (_stuInfo.Length == 0) { QssLogHelper.Log("获取学生信息失败", "学生登录时,通过模拟登录教务网获取学生信息,但是并没有获取成功!", QssLogType.Info); user = null; return(QssResult.Fail); } var stuInfo = new UserInfoHandle(_stuInfo); return(QssUpdateUserInfo(stuInfo, out user)); } else { string[] _thInfo = login.GetThInfo(); if (_thInfo.Length == 0) { QssLogHelper.Log("获取教师信息失败", "教师登录时,通过模拟登录教务网获取教师信息,但是并没有获取成功!", QssLogType.Info); user = null; return(QssResult.Fail); } var thInfo = new UserInfoHandle(_thInfo); return(QssUpdateUserInfo(thInfo, out user)); } }
public ActionResult Login(LoginModel model, string returnUrl) { ViewBag.ReturnUrl = returnUrl; if (ModelState.IsValid) { // 若是超级管理员 // 因为超级管理员的账号不是教务网账号,是单独设置的,所以需要单独处理 if (model.Account == QssEnvironment.AdministratorAccount) { QssResult result = AdministratorLogin(model.Password, out string _result); if (result != QssResult.Success) { ModelState.AddModelError("", _result); return(View()); } return(Redirect(_result)); } // 模拟登陆确认用户合法 var login = new QssSicauLoginHelper(); var userType = model.Account.Length >= 8 ? UserType.S : UserType.T; try { if (login.Login(model.Account, model.Password, userType)) { // 账号密码正确 // 开始更新用户信息 var result = UserService.QssUpdateUserInfo(login, userType, out User user); if (result != QssResult.Success) { QssLogHelper.Log("更新用户信息失败", "用户登录时,更新用户信息失败!用户:" + model.Account, QssLogType.Error, $"{model.Account}({user.Name})"); ModelState.AddModelError("", "更新用户信息失败!请重试."); return(View(model)); } // 更新用户信息成功 // 开始处理登录请求 LoginHandle(user.Account, user.Role.Name + "|" + user.Name + "|" + user.Id); QssLogHelper.Log("登录成功", "登录成功!", QssLogType.Info, $"{model.Account}({user.Name})"); // 跳转到AutoDealOrg进行自动加入或退出组织处理 return(RedirectToAction("AutoDealOrg", "Account", new { returnUrl = returnUrl })); } } catch (Exception exception) { ModelState.AddModelError("", "登录教务网失败!" + exception.Message); QssLogHelper.Log("更新用户信息失败", "用户登录教务网失败!用户:" + model.Account, QssLogType.Error, exception); return(View(model)); } // 账号密码错误 ModelState.AddModelError("", "登录失败,账号密码错误!或是教务网未评教,请评教后请重试."); return(View(model)); } return(View(model)); }