Example #1
0
        /// <summary>
        /// 删除用户信息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public JsonResult DeleteUserById(int userId)
        {
            var reJson = new JsonReMsg();

            //判断是否具有权限
            if (GuserInfo.UserType != 1)
            {
                reJson.Status = "ERR";
                reJson.Msg    = "没有权限删除";
            }
            else
            {
                var delResult = _userService.DeleteUserById(userId);
                if (delResult.Status)
                {
                    reJson.Status = "OK";
                    reJson.Data   = Mapper.Map <List <UserViewModel> >(_userService.GetAllClassUser(GuserInfo.CurrentClass.Id));
                }
                else
                {
                    //删除失败
                    reJson.Status = "ERR";
                    reJson.Msg    = delResult.Msg;
                    reJson.Data   = delResult.Data;
                }
            }
            return(Json(reJson, JsonRequestBehavior.AllowGet));
        }
        public JsonResult AddClassNotice(NoticeViewModel newNotice)
        {
            var reJson = new JsonReMsg();

            //判断是否具有权限
            if (GuserInfo.UserType != 1)
            {
                reJson.Status = "ERR";
                reJson.Msg    = "没有发布公告权限";
            }
            else
            {
                var addresult = _classInfoService.AddClassNotice(GuserInfo.CurrentClass.Id, Mapper.Map <NoticeInput>(newNotice));
                if (addresult.Status)
                {
                    reJson.Status = "OK";
                    reJson.Data   = Mapper.Map <List <NoticeViewModel> >(_classInfoService.GetAllNotices(GuserInfo.CurrentClass.Id));
                }
                else
                {
                    //删除失败
                    reJson.Status = "ERR";
                    reJson.Msg    = addresult.Msg;
                    reJson.Data   = addresult.Data;
                }
            }
            return(Json(reJson, JsonRequestBehavior.AllowGet));
        }
        //END 班级管理员部分



        /// <summary>
        /// 获取当前班级公告
        /// </summary>
        /// <returns></returns>
        public JsonResult GetCurrentClassNotice()
        {
            var reJson = new JsonReMsg()
            {
                Status = "OK"
            };

            reJson.Data = Mapper.Map <List <NoticeViewModel> >(_classInfoService.GetAllNotices(
                                                                   GuserInfo.CurrentClass.Id
                                                                   ).OrderBy(con => con.CreateDate));
            return(Json(reJson, JsonRequestBehavior.AllowGet));
        }
Example #4
0
        /// <summary>
        /// 注册新用户接收方法
        /// </summary>
        /// <returns></returns>
        public JsonResult Regist(string logonUser, string password)
        {
            JsonReMsg reData = new JsonReMsg();
            //用户名验证
            //1.命名规则验证【略】
            //2.重复验证
            //var user = dbcontext.RegisteredUser
            //    .Where(con => con.LogonUser == logonUser)
            //    .ToList();
            //if(user.Count>0)
            //{
            //    reData.Status = "ERR";
            //    reData.Msg = "用户名已经存在!";
            //    return Json(reData, JsonRequestBehavior.AllowGet);
            //}
            //password规则验证【略】
            //password加密
            var md5      = new MD5CryptoServiceProvider();
            var passWord = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(logonUser + password)));

            passWord = passWord.Replace("-", "");
            //try
            //{
            //    dbcontext.RegisteredUser.Add(new RegisteredUser()
            //    {
            //        LogonUser = logonUser,
            //        Password = password
            //    });
            //    dbcontext.SaveChanges();
            //}
            //catch (Exception ex)
            //{
            //    //日志记录【略】
            //    //返回错误信息
            //    reData.Status = "ERR";
            //    reData.Msg = "服务内部错误,请联系管理员处理!";
            //    return Json(reData, JsonRequestBehavior.AllowGet);
            //}
            ////返回刚注册的用户信息
            //reData.Status = "OK";
            //var newUser = dbcontext.RegisteredUser.Where(con => con.LogonUser == logonUser).FirstOrDefault();
            //var userInfo = new UserInfo()
            //{
            //    Id = newUser.Id,
            //    LogonUser = newUser.LogonUser,
            //    HeadPortrait = newUser.HeadPortrait,
            //    Certification = newUser.Certification,
            //    UserType = newUser.UserType
            //};
            reData.Data = null;
            return(Json(reData, JsonRequestBehavior.AllowGet));
        }
Example #5
0
        public JsonResult LoginAuthentication(string logonUser, string password)
        {
            var md5      = new MD5CryptoServiceProvider();
            var passWord = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(logonUser + password)));

            passWord = passWord.Replace("-", "");
            var user = dbcontext.User
                       .Where(con => con.LogonUser == logonUser && con.Password == passWord)
                       .FirstOrDefault();
            var Result = new JsonReMsg()
            {
                Status = "OK"
            };

            if (user is null)
            {
                Result.Status = "ERR";
                user          = dbcontext.User
                                .Where(con => con.LogonUser == logonUser)
                                .FirstOrDefault();
                if (user is null)
                {
                    Result.Msg = "用户尚未注册,请先注册";
                }
                else
                {
                    Result.Msg = "用户密码不符,请注意大小写!";
                }
            }
            else if (user.Locked == "Y")
            {
                Result.Msg = "账号被锁,请注意大小写!";
            }
            else
            {
                var userInfo = new UserInfo()
                {
                    User  = user,
                    roles = new List <Models.Role>()
                };
                dbcontext.UserRole.Where(con => con.Id == user.Id).ToList().ForEach(item => userInfo.roles.Add(item.LogonRole));
                //认证通过KeepSession
                //var userInfo = new UserInfo()
                //{
                //    Certification = logonUser.Certification,
                //    HeadPortrait = logonUser.HeadPortrait,
                //    LogonUser = logonUser.LogonUser,
                //    UserType = logonUser.UserType,
                //    ClassId = new List<int>()
                //};
                //var classInfos = dbcontext.UserClass
                //    .Where(con => con.UserInfo.Id == logonUser.Id)
                //    .ToList();
                ////保存该用户加入的班级列表
                ////当有多个的时候在前端要用户进行选择【补充功能】
                //classInfos.ForEach(item => userInfo.ClassId.Add(item.ClassInfo.Id));
                //if (classInfos.Count == 1)
                //{
                //    //表示已经申请了一个班级
                //    userInfo.CurrentClass = classInfos[0].ClassInfo;
                //}
                ////保存Session
                //HttpContext.Session["userinfo"] = userInfo;

                Result.Data = userInfo;//将用户基本信息传回前台
            }
            return(Json(Result, JsonRequestBehavior.AllowGet));
        }