Ejemplo n.º 1
0
 public IActionResult Item([Required] Int32 logId)
 {
     if (ModelState.IsValid)
     {
         LogStudentOperation log = _context.LogStudentOperations.Find(logId);
         if (log == null)
         {
             return(Json(new
             {
                 isOk = false,
                 title = "错误提示",
                 message = "日志记录不存在,或者已经被删除!"
             }));
         }
         else
         {
             return(Json(new
             {
                 isOk = true,
                 title = "错误提示",
                 message = "加载成功",
                 id = log.LogStudentOperationId,
                 uId = log.StudentId,
                 addTime = _logger.FormatDateLocal(log.AddTime),
                 ip = log.OperationIp,
                 code = log.StuOperationCode.ToString(),
                 target = log.StuOperationName,
                 status = log.StuOperationStatus == StuOperationStatus.Success ? "操作成功" : "操作失败",
                 content = log.StuOperationContent
             }));
         }
     }
     else
     {
         return(Json(new
         {
             isOk = false,
             error = _analysis.ModelStateDictionaryError(ModelState),
             title = "错误提示",
             message = "参数错误,传递了不符合规定的参数"
         }));
     }
 }
Ejemplo n.º 2
0
 public int Logger(LogStudentOperation operation)
 {
     _context.LogStudentOperations.Add(operation);
     return(_context.SaveChanges());
 }
Ejemplo n.º 3
0
 public async Task <int> LoggerAsync(LogStudentOperation operation)
 {
     _context.LogStudentOperations.Add(operation);
     return(await _context.SaveChangesAsync());
 }
Ejemplo n.º 4
0
        public IActionResult Alter([FromForm, Required] String StudentId, [FromForm, Required] String Password, [FromForm, Required] String IDNumber)
        {
            if (ModelState.IsValid)
            {
                UserType type = _analysis.GetUserType(StudentId);
                if (type == UserType.Anonymous)
                {
                    return(RedirectToAction("AlterResult", "Account", new
                    {
                        header = "你的账号不存在,无法修改密码!如果未录入系统,请和管理员联系! ",
                        rightUrl = "/Account/Alter",
                        rightTitle = "再次修改"
                    }));
                }
                if (type == UserType.Principal)
                {
                    return(RedirectToAction("AlterResult", "Account", new
                    {
                        header = "管理员无法在此修改密码,如果忘记密码,请联系系统维护人员! ",
                        rightUrl = "/Account/Alter",
                        rightTitle = "返回修改页面"
                    }));
                }
                //如果是学生的话
                Student student =
                    _context.Student.FirstOrDefault(s => s.IDNumber == IDNumber && s.StudentId == StudentId);

                #region 记录学生操作日志

                LogStudentOperation operation = new LogStudentOperation
                {
                    StudentId           = StudentId,
                    AddTime             = DateTime.Now,
                    OperationIp         = _accessor.HttpContext.Connection.RemoteIpAddress.ToString(),
                    StuOperationCode    = StuOperationCode.ChangePassword,
                    StuOperationContent = "修改账号密码",
                    StuOperationName    = "修改密码",
                    StuOperationStatus  = StuOperationStatus.Success,
                    Title            = "修改密码",
                    StuOperationType = StuOperationType.Normal
                };

                #endregion

                if (student != null)
                {
                    student.Password             = _ncryption.EncodeByMd5(_ncryption.EncodeByMd5(Password));
                    operation.StuOperationStatus = StuOperationStatus.Success;
                    _context.LogStudentOperations.Add(operation);
                    _context.SaveChanges();

                    HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

                    return(RedirectToAction("AlterResult", "Account", new
                    {
                        header = "恭喜你,已经修改密码! 需要重新登录账号..... ",
                        rightUrl = "/Account/Login",
                        rightTitle = "立马前去登录"
                    }));
                }
                else
                {
                    operation.StuOperationStatus = StuOperationStatus.Fail;
                    _context.LogStudentOperations.Add(operation);
                    _context.SaveChanges();
                    //学生的身份证号码错误
                    return(RedirectToAction("AlterResult", "Account", new
                    {
                        header = "修改失败了! 你的身份证号码输入错误! ",
                        rightUrl = "/Account/Alter",
                        rightTitle = "返回修改页面"
                    }));
                }
            }
            else
            {
                return(RedirectToAction("ParameterError", "Error"));
            }
        }