Exemple #1
0
        public LoginModule()
        {
            var config = TinyfxCore.Configuration;

            _tinyfxPageRender = new TinyfxPageRender(config);

            Get("/login", _ =>
            {
                bool islogin = false;
                if (Context.CurrentUser != null && Context.CurrentUser.Identity != null && Context.CurrentUser.Identity.Name != null && Context.CurrentUser.Identity.Name.Length > 0)
                {
                    islogin = true;
                }
                return(Response.AsText(_tinyfxPageRender.RenderLogin("GET", islogin, false), "text/html"));
            });

            Post("/login", _ =>
            {
                DateTime _lastLoginFail = DateTime.MinValue;
                DateTime.TryParse(TStorage.GetInstance()["_last_login_fail"] + "", out _lastLoginFail);

                double tspan = (DateTime.Now - _lastLoginFail).TotalSeconds;

                if (tspan < TinyfxCore.Configuration.LoginRetryTimeSpanSeconds)
                {
                    return(Response.AsText(ResourceHelper.LoadStringResource("login.html").AsHtmlFromTemplate(new
                    {
                        Error = "拒绝登录,请" + (TinyfxCore.Configuration.LoginRetryTimeSpanSeconds - (int)tspan) + "秒后重试!"
                    }), "text/html"));
                }
                else
                {
                    string username = Request.Form.username;
                    string password = Request.Form.password;

                    LogHelper.WriteLog(LogHelper.LogType.INFO, "HTTP POST /login username="******",password="******"_POSTS"] = null;
                        return(this.LoginAndRedirect(uobj.Value, DateTime.Now.AddSeconds(config.AuthExpireSeconds)));
                    }
                    else
                    {
                        TStorage.GetInstance()["_last_login_fail"] = DateTime.Now;
                        return(Response.AsText(_tinyfxPageRender.RenderLogin("POST", false, false), "text/html"));
                    }
                }
            });

            Get("/logout", _ =>
            {
                TStorage.GetInstance()["_POSTS"] = null;
                return(this.LogoutAndRedirect("/login"));
            });
        }
Exemple #2
0
 public void EmptyPostsCache()
 {
     try
     {
         TStorage.GetInstance()["_POSTS"] = null;
     }
     catch (Exception ex)
     {
         LogHelper.WriteLog(LogHelper.LogType.ERROR, ex.Message, ex);
     }
 }