Example #1
0
 public IActionResult Post(SingleMode.Request request)
 {
     try
     {
         UserService.SingleService service = new UserService.SingleService();
         // Request验证
         if (request == null)
         {
             throw new Exception("Request无效!");
         }
         // 指向具体执行的方法
         switch (request.Function.Name.ToLower())
         {
         default:
             if (string.IsNullOrEmpty(request.Function.Name) || request.Function.Name.ToLower().Equals("byid"))
             {
                 return(base.ResponseOk(
                            request.ToResponse(
                                service.ById(int.Parse(request.Function.Args[0] ?? ""), ToParams(request.Function.Args, 1))
                                )
                            ));
             }
             else
             {
                 throw new Exception("未发现对应函数方法!");
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #2
0
        public IActionResult GetToken([FromForm] HttpEntity authEntity)
        {
            var user = new UserService.SingleService().Verify(authEntity.AccountName, authEntity.AccountPwd);

            if (user != null)
            {
                return(new JsonResult(new {
                    result = true,
                    message = "认证成功",
                    token = GenerateToken(user),
                    user = new { userId = user.Id, userName = user.Name, realName = user.RealName, weChatOpenId = user.WeChatOpenId }
                }));
            }
            else
            {
                return(new JsonResult(new
                {
                    result = false,
                    message = "认证失败",
                    token = new { },
                    user = new { }
                }));
            }
        }