Ejemplo n.º 1
0
        public IActionResult Login(Student student)
        {
            ResponseResult result = new ResponseResult(ResultCode.ResponseFailCode);

            if (ModelState.IsValid)
            {
                Student studentTemp = _context.Student.Find(student.Id);
                if (studentTemp != null)
                {
                    if (studentTemp.Password == student.Password)
                    {
                        result.SetResult(ResultType.SUCCESS);
                    }
                    else
                    {
                        result.SetResult(ResultType.FAIL);
                    }
                }
                else
                {
                    result.SetResult(ResultType.FAIL).Info = ErrorMessage.EmptyUser;
                }
                return(new JsonResult(result));
            }
            return(BadRequest(ModelState));
        }
Ejemplo n.º 2
0
        public JsonResult Login(string name, string pwd, string role = "")
        {
            ResponseResult result = new ResponseResult();

            if (name == null || pwd == null)
            {
                return(Json(result));
            }
            User user;

            if (!SqliteHelper.Instacne.CheckUser(name, pwd, out user))
            {
                result.code = -2;
                result.msg  = "账号或密码错误";
                return(Json(result));
            }
            //如果是基于角色的授权策略,这里要添加用户;如果是基于角色的授权策略,这里要添加角色
            var claims = new Claim[] { new Claim(ClaimTypes.Name, name), new Claim(ClaimTypes.Role, role) };
            //用户标识
            var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme);

            identity.AddClaims(claims);
            var authorization = JwtToken.BuildJwtTokenString(claims, _requirement);

            user.authorization = authorization;
            result.SetResult(user);
            return(Json(result));
        }
Ejemplo n.º 3
0
        public JsonResult Update(string id, string title, string content, string photo, string type)
        {
            ResponseResult result = new ResponseResult();

            id      = StringUtil.Check(id);
            title   = StringUtil.Check(title);
            content = StringUtil.Check(content);
            photo   = StringUtil.Check(photo);
            type    = StringUtil.Check(type);
            Article article = SqliteHelper.Instacne.GetArticle(id);

            if (article == null)
            {
                result.msg = "文章不存在";
                return(Json(result));
            }
            article.title      = title;
            article.content    = content;
            article.photo      = photo;
            article.type       = type;
            article.updateTime = DateTimeHelper.GetNow();
            bool ret = SqliteHelper.Instacne.UpdateArticle(article);

            if (!ret)
            {
                result.msg = "更新文章失败";
                return(Json(result));
            }
            result.SetResult(ret);
            return(Json(result));
        }
Ejemplo n.º 4
0
        public JsonResult Insert(string title, string content, string photo, string type)
        {
            ResponseResult result = new ResponseResult();

            title   = StringUtil.Check(title);
            content = StringUtil.Check(content);
            photo   = StringUtil.Check(photo);
            type    = StringUtil.Check(type);

            Article article = new Article();

            article.id         = Guid.NewGuid().ToString();
            article.title      = title;
            article.content    = content;
            article.photo      = photo;
            article.type       = type;
            article.createTime = DateTimeHelper.GetNow();
            article.updateTime = DateTimeHelper.GetNow();
            bool ret = SqliteHelper.Instacne.InsertArticle(article);

            if (!ret)
            {
                result.msg = "插入文章失败";
                return(Json(result));
            }
            result.SetResult(ret);
            return(Json(result));
        }
Ejemplo n.º 5
0
        public JsonResult Insert(string title, string content, string photo, string type)
        {
            ResponseResult result = new ResponseResult();

            title   = StringUtil.Check(title);
            content = StringUtil.Check(content);
            photo   = StringUtil.Check(photo);
            type    = StringUtil.Check(type);

            New @new = new New();

            @new.id         = Guid.NewGuid().ToString();
            @new.title      = title;
            @new.content    = content;
            @new.photo      = photo;
            @new.type       = type;
            @new.createTime = DateTimeHelper.GetNow();
            @new.updateTime = DateTimeHelper.GetNow();
            bool ret = SqliteHelper.Instacne.InsertNew(@new);

            if (!ret)
            {
                result.msg = "插入新闻失败";
                return(Json(result));
            }
            result.SetResult(ret);
            return(Json(result));
        }
Ejemplo n.º 6
0
        public JsonResult Update(string id, string title, string content, string photo, string type)
        {
            ResponseResult result = new ResponseResult();

            id      = StringUtil.Check(id);
            title   = StringUtil.Check(title);
            content = StringUtil.Check(content);
            photo   = StringUtil.Check(photo);
            type    = StringUtil.Check(type);
            New @new = SqliteHelper.Instacne.GetNew(id);

            if (@new == null)
            {
                result.msg = "新闻不存在";
                return(Json(result));
            }
            @new.title      = title;
            @new.content    = content;
            @new.photo      = photo;
            @new.type       = type;
            @new.updateTime = DateTimeHelper.GetNow();
            bool ret = SqliteHelper.Instacne.UpdateNew(@new);

            if (!ret)
            {
                result.msg = "更新新闻失败";
                return(Json(result));
            }
            result.SetResult(ret);
            return(Json(result));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 文章分页
        /// </summary>
        /// <param name="limit"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public JsonResult GetList(int?limit, int?offset)
        {
            ResponseResult result = new ResponseResult();

            if (limit == null || offset == null)
            {
                return(Json(result));
            }
            result.SetResult(SqliteHelper.Instacne.GetArticles(limit, offset));
            return(Json(result));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 根据id获得文章内容
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult GetOne(string id)
        {
            ResponseResult result = new ResponseResult();

            id = StringUtil.Check(id);
            Article article = SqliteHelper.Instacne.GetArticle(id);

            if (article == null)
            {
                result.msg = "无此结果";
                return(Json(result));
            }
            result.SetResult(article);
            return(Json(result));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 根据id获得新闻内容
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult GetOne(string id)
        {
            ResponseResult result = new ResponseResult();

            id = StringUtil.Check(id);
            New @new = SqliteHelper.Instacne.GetNew(id);

            if (@new == null)
            {
                result.msg = "无此结果";
                return(Json(result));
            }
            result.SetResult(@new);
            return(Json(result));
        }
Ejemplo n.º 10
0
        public JsonResult Delete(string id)
        {
            ResponseResult result = new ResponseResult();

            id = StringUtil.Check(id);
            Article article = SqliteHelper.Instacne.GetArticle(id);

            if (article == null)
            {
                result.msg = "文章不存在";
                return(Json(result));
            }
            bool ret = SqliteHelper.Instacne.DeleteArticle(id);

            if (!ret)
            {
                result.msg = "删除失败";
                return(Json(result));
            }
            result.SetResult(ret);
            return(Json(result));
        }
Ejemplo n.º 11
0
        public JsonResult Delete(string id)
        {
            ResponseResult result = new ResponseResult();

            id = StringUtil.Check(id);
            New @new = SqliteHelper.Instacne.GetNew(id);

            if (@new == null)
            {
                result.msg = "新闻不存在";
                return(Json(result));
            }
            bool ret = SqliteHelper.Instacne.DeleteNew(id);

            if (!ret)
            {
                result.msg = "删除失败";
                return(Json(result));
            }
            result.SetResult(ret);
            return(Json(result));
        }