public IHttpActionResult Check(string name, [FromBody] CaptchaInfo captchaInfo)
        {
            try
            {
                var code = CookieUtils.GetCookie("SS-" + name);

                if (string.IsNullOrEmpty(code) || CacheUtils.Exists($"SiteServer.API.Controllers.V1.CaptchaController.{code}"))
                {
                    return(BadRequest("验证码已超时,请点击刷新验证码!"));
                }

                CookieUtils.Erase("SS-" + name);
                CacheUtils.InsertMinutes($"SiteServer.API.Controllers.V1.CaptchaController.{code}", true, 10);

                if (!StringUtils.EqualsIgnoreCase(code, captchaInfo.Captcha))
                {
                    return(BadRequest("验证码不正确,请重新输入!"));
                }

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Exemple #2
0
        public ActionResult SumbitLogon(VOUser user)
        {
            if (string.IsNullOrEmpty(user.UserName) || string.IsNullOrEmpty(user.Password))
            {
                return(RedirectToAction("Logon", "LogonForm", new { message = "登录名,密码不能为空!" }));
            }

            JsonUser jsonUser = UserService.CheckUserPassword(user.UserName, user.Password);

            CookieUtils.AddCookie("LogonID", user.UserName, System.Web.HttpContext.Current);

            if (user.RememberMe)
            {
                HttpCookie cookie = CookieUtils.GetCookie(System.Web.HttpContext.Current, "LogonID");
                cookie.Expires = DateTime.Now.AddDays(7);
            }
            GlobalVariables.CurrentUser = jsonUser;

            if (jsonUser == null)
            {
                return(RedirectToAction("Logon", "LogonForm", new { message = "用户名,密码验证失败!" }));
            }

            return(RedirectToAction("Index", "ParticipateConsultation"));
        }
        public IHttpActionResult Check([FromBody] CheckRequest request)
        {
            try
            {
                var code = CookieUtils.GetCookie(CookieName);

                if (string.IsNullOrEmpty(code) || CacheUtils.Exists($"{CookieName}.{code}"))
                {
                    return(BadRequest("验证码已超时,请点击刷新验证码!"));
                }

                CookieUtils.Erase(CookieName);
                CacheUtils.InsertMinutes($"{CookieName}.{code}", true, 10);

                if (!StringUtils.EqualsIgnoreCase(code, request.Captcha))
                {
                    return(BadRequest("验证码不正确,请重新输入!"));
                }

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        protected void AuthAdministrator()
        {
            if (!string.IsNullOrEmpty(CookieUtils.GetCookie(AdministratorAuthCookie)))
            {
                var administratorTokenStr = CookieUtils.GetCookie(AdministratorAuthCookie);
                AdminName = string.IsNullOrEmpty(administratorTokenStr) ? AdminManager.AnonymousUserName : GetAdministratorToken(administratorTokenStr).AdministratorName;
            }

            AdminPermissions = PermissionManager.GetInstance(AdminName);
        }
        public IActionResult Index()
        {
            /*
             * net core不自带httpcontext 需要在 Startup 注入
             * 1、在ConfigureServices 中 services.AddStaticHttpContext();
             * 2、在Configure 中 app.UseStaticHttpContext();
             */

            var builder = new StringBuilder("测试如下:\r\n");

            //Post
            builder.Append($"Post值:{WebUtils.GetFormVal<string>("a")}\r\n");

            //IP
            builder.Append($"IP:{IPUtils.GetIP()}\r\n");

            //WebUtils
            builder.Append($"pid:{WebUtils.GetQueryVal<int>("pid")}\r\n");                                  //?pid=1
            builder.Append($"date:{WebUtils.GetQueryVal<DateTime>("date", new DateTime(1900, 1, 1))}\r\n"); //?date=2020-12-31
            //全url
            builder.Append($"全URL:{WebUtils.GetAbsoluteUri()}\r\n");

            //CacheUtils 缓存
            DateTime dateTime = DateTime.Now;
            var      cache    = new CacheUtils();

            var cacheDT = DateTime.Now;

            if (cache.ContainKey("time"))
            {
                cacheDT = cache.Get <DateTime>("time");
            }
            else
            {
                cache.Insert <DateTime>("time", dateTime, 3600);
            }

            builder.Append($"当前时间:{dateTime.ToFormatString()} \r\n");
            builder.Append($"缓存时间:{cacheDT.ToFormatString()} \r\n");

            //当前网站目录
            builder.Append($"当前网站目录:{SystemUtils.GetMapPath()} \r\n");
            builder.Append($"upload目录:{SystemUtils.GetMapPath("/upload")} \r\n");

            //cookie
            CookieUtils.SetCookie("username", "jsonlee");
            builder.Append($"username cookie: {CookieUtils.GetCookie("username")} \r\n");

            //session
            SessionUtils.SetSession("username", System.Web.HttpUtility.UrlEncode("刘备"));
            builder.Append($"username session: {System.Web.HttpUtility.UrlDecode(SessionUtils.GetSession("username"))} \r\n");

            return(Content(builder.ToString()));
        }
Exemple #6
0
 public static string GetCookieWXOpenID(string wxOpenID)
 {
     if (CookieUtils.IsExists(COOKIE_WXOPENID_NAME))
     {
         return(CookieUtils.GetCookie(COOKIE_WXOPENID_NAME));
     }
     else
     {
         CookieUtils.SetCookie(COOKIE_WXOPENID_NAME, wxOpenID, DateTime.MaxValue);
         return(wxOpenID);
     }
 }
Exemple #7
0
        public bool IsCodeValid(string validateCode)
        {
            var code    = CookieUtils.GetCookie(_cookieName);
            var isValid = StringUtils.EqualsIgnoreCase(code, validateCode);

            if (isValid)
            {
                CacheUtils.Remove(_cookieName);
            }

            return(isValid);
        }
Exemple #8
0
 public static string GetCookieSN()
 {
     if (CookieUtils.IsExists(COOKIE_SN_NAME))
     {
         return(CookieUtils.GetCookie(COOKIE_SN_NAME));
     }
     else
     {
         var value = StringUtils.GetShortGuid();
         CookieUtils.SetCookie(COOKIE_SN_NAME, value, DateTime.MaxValue);
         return(value);
     }
 }
        public ActionResult Index()
        {
            var builder = new StringBuilder("测试如下:<br/>\r\n");

            //IP
            builder.Append($"IP:{IPUtils.GetIP()}<br/>\r\n");

            //WebUtils
            builder.Append($"pid:{WebUtils.GetQueryInt("pid")}<br/>\r\n"); //?pid=1
            //全url
            builder.Append($"全URL:{WebUtils.GetAbsoluteUri()}<br/>\r\n");

            //CacheUtils 缓存
            DateTime dateTime = DateTime.Now;
            var      cache    = new CacheUtils();

            var cacheDT = DateTime.Now;

            if (cache.ContainKey("time"))
            {
                cacheDT = cache.Get <DateTime>("time");
            }
            else
            {
                cache.Insert <DateTime>("time", dateTime, 3600);
            }

            builder.Append($"当前时间:{dateTime.ToFormatString()} <br/>\r\n");
            builder.Append($"缓存时间:{cacheDT.ToFormatString()} <br/>\r\n");

            //当前网站目录
            builder.Append($"当前网站目录:{SystemUtils.GetMapPath()} <br/>");
            builder.Append($"upload目录:{SystemUtils.GetMapPath("/upload")} <br/>");

            //cookie
            CookieUtils.SetCookie("username", "jsonlee");
            builder.Append($"username cookie: {CookieUtils.GetCookie("username")} <br/>\r\n");

            //session
            SessionUtils.SetSession("username", "刘备");
            builder.Append($"username session: {SessionUtils.GetSession<string>("username")}  <br/>\r\n");

            builder.Append($"mobile client : {SystemUtils.IsMobileClient.Value} <br/>\r\n");
            builder.Append($"weixin client : {SystemUtils.IsWeixinClient.Value} <br/>\r\n");

            builder.Append($"is iphone : {SystemUtils.IsIphone.Value} <br/>\r\n");
            builder.Append($"is android : {SystemUtils.IsAndroid.Value} <br/>\r\n");

            return(Content(builder.ToString()));
        }
Exemple #10
0
 protected void Page_Load(object sender, System.EventArgs e)
 {
     if (base.IsPost)
     {
         UserInfo userInfo    = new UserInfo();
         string   formString  = WebUtils.GetFormString("_loginname");
         string   formString2 = WebUtils.GetFormString("_loginpwd");
         bool     flag        = WebUtils.GetFormInt("_loginremeber").Equals(1);
         if (PageBase.config.VerifycodeForLogin && string.Compare(base.ValidateCode, WebUtils.GetFormString("_loginyzm"), true) != 0)
         {
             base.WriteJsonTip(base.GetCaption("ValidateCodeIncorrect"));
         }
         else
         {
             LoginStatus loginStatus = SinGooCMS.BLL.User.UserLogin(formString, formString2, ref userInfo);
             if (loginStatus == LoginStatus.Success)
             {
                 if (flag)
                 {
                     CookieUtils.SetCookie("_remeberusername", userInfo.UserName, 31536000);
                 }
                 string text = base.Server.UrlDecode(WebUtils.GetFormString("_loginreturnurl"));
                 if (!string.IsNullOrEmpty(text))
                 {
                     base.WriteJsonTip(true, "Đăng nhập thành công", text);
                 }
                 else
                 {
                     base.WriteJsonTip(true, "Đăng nhập thành công", UrlRewrite.Get("infocenter_url"));
                 }
             }
             else if (loginStatus == LoginStatus.MutilLoginFail)
             {
                 base.WriteJsonTip(base.GetCaption("Login_LoginFailTooMany").Replace("${num}", PageBase.config.TryLoginTimes.ToString()));
             }
             else
             {
                 base.WriteJsonTip(base.GetCaption("Login_FailWithMsg").Replace("${msg}", base.GetCaption("LoginStatus_" + loginStatus.ToString())));
             }
         }
     }
     else
     {
         base.Put("remeberusername", CookieUtils.GetCookie("_remeberusername"));
         base.Put("returnurl", (base.Request.Url.ToString().IndexOf("?returnurl=") == -1) ? "" : base.Request.Url.ToString().Substring(base.Request.Url.ToString().IndexOf("?returnurl=") + "?returnurl=".Length));
         base.Put("thirdlogin", OAuthConfig.Load());
         base.UsingClient("user/login.html");
     }
 }
Exemple #11
0
        //
        // GET: /Login/

        public ActionResult Index(string message)
        {
            VOUser user = new VOUser();

            ViewBag.Message = message;

            HttpCookie cookie = CookieUtils.GetCookie(System.Web.HttpContext.Current, "LogonID");

            if (cookie != null)
            {
                user.UserName   = cookie.Value;
                user.RememberMe = true;
            }
            return(View(user));
        }
Exemple #12
0
 private void AuthApi()
 {
     if (!string.IsNullOrEmpty(HttpRequest.Headers.Get(AuthKeyApiHeader)))
     {
         ApiToken = HttpRequest.Headers.Get(AuthKeyApiHeader);
     }
     else if (!string.IsNullOrEmpty(HttpRequest.QueryString[AuthKeyApiQuery]))
     {
         ApiToken = HttpRequest.QueryString[AuthKeyApiQuery];
     }
     else if (!string.IsNullOrEmpty(CookieUtils.GetCookie(AuthKeyApiCookie)))
     {
         ApiToken = CookieUtils.GetCookie(AuthKeyApiCookie);
     }
 }
Exemple #13
0
        public ActionResult Login()
        {
            if (User.Identity.IsAuthenticated)
            {
                return(Redirect(Url.AdminHome()));
            }
            var model = new LoginModel();

            model.UserName = CookieUtils.GetCookie(FormsAuthSvc.GetUserNameCookieKey(), "");
            if (!string.IsNullOrEmpty(model.UserName))
            {
                model.IsRemember = true;
            }
            return(View(model));
        }
        protected void AuthUser()
        {
            var userTokenStr = string.Empty;

            if (!string.IsNullOrEmpty(CookieUtils.GetCookie(UserAuthCookie)))
            {
                userTokenStr = CookieUtils.GetCookie(UserAuthCookie);
            }

            if (string.IsNullOrEmpty(userTokenStr))
            {
                return;
            }

            UserName = GetUserToken(userTokenStr).UserName;
        }
Exemple #15
0
        private void AuthAdministrator()
        {
            var accessTokenStr = string.Empty;

            if (!string.IsNullOrEmpty(CookieUtils.GetCookie(AuthKeyAdminCookie)))
            {
                accessTokenStr = CookieUtils.GetCookie(AuthKeyAdminCookie);
            }
            else if (!string.IsNullOrEmpty(HttpRequest.Headers.Get(AuthKeyAdminHeader)))
            {
                accessTokenStr = HttpRequest.Headers.Get(AuthKeyAdminHeader);
            }
            else if (!string.IsNullOrEmpty(HttpRequest.QueryString[AuthKeyAdminQuery]))
            {
                accessTokenStr = HttpRequest.QueryString[AuthKeyAdminQuery];
            }

            SetAdmin(string.IsNullOrEmpty(accessTokenStr) ? AdminManager.AnonymousUserName : GetAdministratorToken(accessTokenStr).AdministratorName);
        }
Exemple #16
0
        public IHttpActionResult Check(string name, [FromBody] CaptchaInfo captchaInfo)
        {
            try
            {
                var code    = CookieUtils.GetCookie("SS-" + name);
                var isValid = StringUtils.EqualsIgnoreCase(code, captchaInfo.Captcha);

                if (!isValid)
                {
                    return(BadRequest("验证码不正确"));
                }

                return(Ok(new OResponse(true)));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Exemple #17
0
        protected void AdministratorAuthentication()
        {
            var administratorTokenStr = string.Empty;

            if (!string.IsNullOrEmpty(CookieUtils.GetCookie(AdministratorAccessToken)))
            {
                administratorTokenStr = CookieUtils.GetCookie(AdministratorAccessToken);
            }
            else if (!string.IsNullOrEmpty(HttpRequest.Headers.Get(AdministratorAccessToken)))
            {
                administratorTokenStr = HttpRequest.Headers.Get(AdministratorAccessToken);
            }
            else if (!string.IsNullOrEmpty(HttpRequest.QueryString[AdministratorAccessToken]))
            {
                administratorTokenStr = HttpRequest.QueryString[AdministratorAccessToken];
            }

            AdminName        = string.IsNullOrEmpty(administratorTokenStr) ? AdminManager.AnonymousUserName : GetAdministratorToken(administratorTokenStr).AdministratorName;
            AdminPermissions = PermissionManager.GetInstance(AdminName);
        }
Exemple #18
0
        private void AuthApi()
        {
            if (!string.IsNullOrEmpty(HttpRequest.Headers.Get(AuthKeyApiHeader)))
            {
                ApiToken = HttpRequest.Headers.Get(AuthKeyApiHeader);
            }
            else if (!string.IsNullOrEmpty(HttpRequest.QueryString[AuthKeyApiQuery]))
            {
                ApiToken = HttpRequest.QueryString[AuthKeyApiQuery];
            }
            else if (!string.IsNullOrEmpty(CookieUtils.GetCookie(AuthKeyApiCookie)))
            {
                ApiToken = CookieUtils.GetCookie(AuthKeyApiCookie);
            }

            if (!string.IsNullOrEmpty(ApiToken))
            {
                var tokenInfo = AccessTokenManager.GetAccessTokenInfo(ApiToken);
                SetAdmin(tokenInfo?.AdminName);
                IsApiAuthenticated = tokenInfo != null;
            }
        }
        private void FillFileSystems(bool isReload)
        {
            const string cookieName  = "SiteServer.BackgroundPages.Cms.Modal.SelectAttachment";
            var          isSetCookie = AuthRequest.IsQueryExists("ListType");

            if (!isSetCookie)
            {
                var cookieExists = false;
                if (CookieUtils.IsExists(cookieName))
                {
                    var cookieValue = CookieUtils.GetCookie(cookieName);
                    foreach (ListItem item in DdlListType.Items)
                    {
                        if (string.Equals(item.Value, cookieValue))
                        {
                            cookieExists  = true;
                            item.Selected = true;
                        }
                    }
                }
                if (!cookieExists)
                {
                    CookieUtils.SetCookie(cookieName, DdlListType.SelectedValue, DateTime.MaxValue);
                }
            }
            else
            {
                CookieUtils.SetCookie(cookieName, AuthRequest.GetQueryString("ListType"), DateTime.MaxValue);
            }
            if (DdlListType.SelectedValue == "List")
            {
                FillFileSystemsToList(isReload);
            }
            else if (DdlListType.SelectedValue == "Image")
            {
                FillFileSystemsToImage(isReload);
            }
        }
Exemple #20
0
        public IHttpActionResult Check(string name, [FromBody] CaptchaInfo captchaInfo)
        {
            try
            {
                var code = CookieUtils.GetCookie("SS-" + name);
                if (string.IsNullOrEmpty(code))
                {
                    return BadRequest("验证码已超时,请点击刷新验证码图片!");
                }

                if (!StringUtils.EqualsIgnoreCase(code, captchaInfo.Captcha))
                {
                    return BadRequest("验证码不正确,请重新输入!");
                }

                return Ok(new OResponse(true));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return InternalServerError(ex);
            }
        }
Exemple #21
0
        protected void UserAuthentication()
        {
            var userTokenStr = string.Empty;

            if (!string.IsNullOrEmpty(CookieUtils.GetCookie(UserAccessToken)))
            {
                userTokenStr = CookieUtils.GetCookie(UserAccessToken);
            }
            else if (!string.IsNullOrEmpty(HttpRequest.Headers.Get(UserAccessToken)))
            {
                userTokenStr = HttpRequest.Headers.Get(UserAccessToken);
            }
            else if (!string.IsNullOrEmpty(HttpRequest.QueryString[UserAccessToken]))
            {
                userTokenStr = HttpRequest.QueryString[UserAccessToken];
            }

            if (string.IsNullOrEmpty(userTokenStr))
            {
                return;
            }

            UserName = GetUserToken(userTokenStr).UserName;
        }
Exemple #22
0
        private void AuthUser()
        {
            var accessTokenStr = string.Empty;

            if (!string.IsNullOrEmpty(CookieUtils.GetCookie(AuthKeyUserCookie)))
            {
                accessTokenStr = CookieUtils.GetCookie(AuthKeyUserCookie);
            }
            else if (!string.IsNullOrEmpty(HttpRequest.Headers.Get(AuthKeyUserHeader)))
            {
                accessTokenStr = HttpRequest.Headers.Get(AuthKeyUserHeader);
            }
            else if (!string.IsNullOrEmpty(HttpRequest.QueryString[AuthKeyUserQuery]))
            {
                accessTokenStr = HttpRequest.QueryString[AuthKeyUserQuery];
            }

            if (string.IsNullOrEmpty(accessTokenStr))
            {
                return;
            }

            UserName = GetUserToken(accessTokenStr).UserName;
        }
Exemple #23
0
        protected void AdministratorAuthentication(HttpRequest request)
        {
            var administratorTokenStr = string.Empty;

            if (!string.IsNullOrEmpty(CookieUtils.GetCookie(AdministratorAccessToken)))
            {
                administratorTokenStr = CookieUtils.GetCookie(AdministratorAccessToken);
            }
            else if (!string.IsNullOrEmpty(request.Headers.Get(AdministratorAccessToken)))
            {
                administratorTokenStr = request.Headers.Get(AdministratorAccessToken);
            }
            else if (!string.IsNullOrEmpty(request.QueryString[AdministratorAccessToken]))
            {
                administratorTokenStr = request.QueryString[AdministratorAccessToken];
            }

            if (string.IsNullOrEmpty(administratorTokenStr))
            {
                return;
            }

            AdministratorName = GetAdministratorToken(administratorTokenStr).AdministratorName;
        }
Exemple #24
0
 public string GetCookie(string name)
 {
     return(CookieUtils.GetCookie(name));
 }
        public IHttpActionResult Insert()
        {
            try
            {
                var request = Context.AuthenticatedRequest;
                var siteId  = request.GetPostInt("siteId");
                if (!request.IsAdminLoggin)
                {
                    return(Unauthorized());
                }

                var authCode = request.GetPostString("authCode");
                var code     = CookieUtils.GetCookie(CaptchaController.CookieName);
                if (string.IsNullOrEmpty(code) || CacheUtils.Exists($"{CaptchaController.CookieName}.{code}"))
                {
                    return(BadRequest("验证码已超时,请点击刷新验证码!"));
                }
                CookieUtils.Erase(CaptchaController.CookieName);
                CacheUtils.InsertMinutes($"{CaptchaController.CookieName}.{code}", true, 10);
                if (!StringUtils.EqualsIgnoreCase(code, authCode))
                {
                    return(BadRequest("验证码不正确,请重新输入!"));
                }

                var categoryId     = request.GetPostInt("categoryId");
                var departmentId   = request.GetPostInt("departmentId");
                var categoryInfo   = CategoryManager.GetCategoryInfo(siteId, categoryId);
                var departmentInfo = DepartmentManager.GetDepartmentInfo(siteId, departmentId);

                var dataInfo = new DataInfo
                {
                    Id             = 0,
                    SiteId         = siteId,
                    AddDate        = DateTime.Now,
                    QueryCode      = StringUtils.GetShortGuid(true),
                    CategoryId     = categoryInfo?.Id ?? 0,
                    DepartmentId   = departmentInfo?.Id ?? 0,
                    IsCompleted    = false,
                    State          = DataState.New.Value,
                    DenyReason     = string.Empty,
                    RedoComment    = string.Empty,
                    ReplyContent   = string.Empty,
                    IsReplyFiles   = false,
                    ReplyDate      = DateTime.Now,
                    Name           = request.GetPostString("name"),
                    Gender         = request.GetPostString("gender"),
                    Phone          = request.GetPostString("phone"),
                    Email          = request.GetPostString("email"),
                    Address        = request.GetPostString("address"),
                    Zip            = request.GetPostString("zip"),
                    Title          = request.GetPostString("title"),
                    Content        = request.GetPostString("content"),
                    CategoryName   = categoryInfo == null ? string.Empty : categoryInfo.CategoryName,
                    DepartmentName = departmentInfo == null ? string.Empty : departmentInfo.DepartmentName
                };

                Main.DataRepository.Insert(dataInfo);

                return(Ok(new
                {
                    Value = dataInfo
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }