Example #1
0
 public ResponseDataEntity Set()
 {
     //日志等级由系统维护,通过配置参数获取
     //系统临时设置日志级别,log4可直接设置为ALL级别,如果需要测试接口等其他级别可通过这个配置调整
     CacheUtil.Add("LogLevel", "ERROR", new TimeSpan(0, 5, 0));
     return(ResponseUtil.Success());
 }
Example #2
0
 public ResponseDataEntity Log()
 {
     LogUtil.Debug("Debug");
     LogUtil.Info("Info");
     LogUtil.Warn("Warn");
     LogUtil.Error("Error");
     LogUtil.Fatal("Fatal");
     return(ResponseUtil.Success());
 }
Example #3
0
        public ResponseDataEntity Get()
        {
            var rng  = new Random();
            var data = Enumerable.Range(1, 2).Select(index => new WeatherForecast
            {
                Date         = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary      = Summaries[rng.Next(Summaries.Length)],
                Timestamp    = (int)DateUtil.ConvertToUnixTimestamp(DateTime.Now.AddDays(index))
            })
                       .ToList();

            return(ResponseUtil.Success("", data));
        }
Example #4
0
 public async Task <ResponseDataEntity> Login(LoginFormEntity formEntity)
 {
     if (string.IsNullOrEmpty(formEntity.LoginName) || string.IsNullOrEmpty(formEntity.Password))
     {
         return(ResponseUtil.Fail("请输入账号密码"));
     }
     if (formEntity.LoginName == "admin")
     {
         //这里实际应该通过db获取管理员
         string password = EncryptUtil.MD5Encrypt(formEntity.Password, AprilConfig.SecurityKey);
         if (password == "B092956160CB0018")
         {
             //获取管理员相关权限,同样是db获取,这里只做展示
             AdminEntity admin = new AdminEntity
             {
                 UserName       = "******",
                 Avator         = "",
                 IsSuperManager = true,
                 TokenType      = (int)AprilEnums.TokenType.Web
             };
             string token      = TokenUtil.GetToken(admin, out string expiretimestamp);
             int    expiretime = 0;
             int.TryParse(expiretimestamp, out expiretime);
             //可以考虑记录登录日志等其他信息
             return(ResponseUtil.Success("", new { username = admin.UserName, avator = admin.Avator, token = token, expire = expiretime }));
         }
     }
     else if (formEntity.LoginName == "test")
     {
         //这里做权限演示
         AdminEntity admin = new AdminEntity
         {
             UserName  = "******",
             Avator    = "",
             TokenType = (int)AprilEnums.TokenType.Web
         };
         admin.Controllers.Add("weatherforecast");
         admin.Permissions.Add("weatherforecast_log");//控制器_事件(Add,Update...)
         string token      = TokenUtil.GetToken(admin, out string expiretimestamp);
         int    expiretime = 0;
         int.TryParse(expiretimestamp, out expiretime);
         //可以考虑记录登录日志等其他信息
         return(ResponseUtil.Success("", new { username = admin.UserName, avator = admin.Avator, token = token, expire = expiretime }));
     }
     //这里其实已经可以考虑验证码相关了,但是这是示例工程,后续可持续关注我,会有基础工程(带权限)的实例公开
     return(ResponseUtil.Fail("账号密码错误"));
 }