/// <summary>
        /// 获取验证码
        /// </summary>
        /// <param name="batch"></param>
        /// <returns></returns>
        public byte[] GetCaptchaImage(string batch)
        {
            ArgumentHelper.AssertNotNullOrEmpty(batch, "batch is null");

            string captcha;
            var    data = CaptchaImageHelper.CreatBitmap(out captcha);

            RedisHelper.SetRedis(RedisConstName.Captcha + batch, captcha, 1800);

            return(data);
        }
Exemplo n.º 2
0
        public Response <object> CaptchaImage(string key, string code)
        {
            Response <object> result = new Response <object>();

            if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(code) && CaptchaImageHelper.Check(key, code))
            {
                result.data = new { result = true };
                return(result);
            }
            result.data = new { result = false };
            return(result);
        }
Exemplo n.º 3
0
        private void LoginSuccessOprate(int userid, string username, string key, bool remember, string account)
        {
            DavidFormsAuthentication.SignIn(username, userid, remember);
            //设置用户名框里显示名字
            int days = int.Parse(ConfigurationManager.AppSettings["UserAccountDisplayTime"]);

            var useraccountCookie = new HttpCookie("DisplayUserAccount", account)
            {
                Expires = DateTime.Now.AddDays(days),
                Domain  = ".postpony.com"
            };

            HttpContext.Current.Response.Cookies.Add(useraccountCookie);
            //设置验证码隐藏
            CaptchaDisplayHelper.SetHide(CaptchaDispalyType.Login);
            //删除验证码值
            CaptchaImageHelper.RemoveCurrentCapcha(key);
            //删除错误计数
            CaptchaDisplayHelper.DeleteErrorCount();
        }
Exemplo n.º 4
0
        public Response <object> Login(LoginRequest loginRequest)
        {
            Response <object> result = new Response <object>();
            bool showCaptcha         = false;

            if (string.IsNullOrEmpty(loginRequest.account))
            {
                showCaptcha = OprateLoginCaptcha();
                result.data = new
                {
                    result      = false,
                    errorcode   = 1,
                    showcaptcha = showCaptcha
                };
                return(result);
            }

            Regex passwordRegex = new Regex("[A-Za-z].*[0-9]|[0-9].*[A-Za-z]");

            if (string.IsNullOrEmpty(loginRequest.password))
            {
                showCaptcha = OprateLoginCaptcha();
                result.data = new { result = false, errorcode = 2, showcaptcha = showCaptcha };
                return(result);
            }
            if (loginRequest.password == Encryption.SHA256Encrypt(Encryption.MD5(loginRequest.password)))
            {
                showCaptcha = OprateLoginCaptcha();
                result.data = new { result = false, errorcode = 2, showcaptcha = showCaptcha };
                return(result);
            }
            if (CaptchaDisplayHelper.IsDisplay(CaptchaDispalyType.Login) && !CaptchaImageHelper.Check(loginRequest.key, loginRequest.code))
            {
                CaptchaDisplayHelper.SetDisplay(CaptchaDispalyType.Login);
                result.data = new { result = false, errorcode = 6, showcaptcha = true };
                return(result);
            }

            //ResultOfUserLoginInfoDtoUserLoginReturnEnum loginResult = UserDataService.UserLoginValidation(loginRequest.account, Encryption.SHA256Encrypt(Encryption.MD5(loginRequest.password)));

            //if (loginResult == null)
            //{
            //    showCaptcha = OprateLoginCaptcha();

            //    result.data = new { result = false, errorcode = 7, showcaptcha = showCaptcha };
            //    return result;
            //}

            //switch (loginResult.Status)
            //{
            //    case UserLoginReturnEnum.Success:
            //        try
            //        {
            //            LogDataService.Log("Save The Login userInfo", LogType.SaveUserLoginInfo, $"userid={loginResult.Data.UserId};userIp={IPHelper.GetClicentIp()};userMacAddress={CommonTool.GetMacAddress()};");
            //        }
            //        catch (Exception ex)
            //        {
            //            LogDataService.Exception("Save The Login userInfo Exception", ex.Message, ex.Source, $"userid={loginResult.Data.UserId}");
            //        }

            //        break;
            //    case UserLoginReturnEnum.Closed://账户关闭,客户登录失败
            //        result.data = new { result = false, errorcode = 8 };
            //        return result;

            //    case UserLoginReturnEnum.NullOrEmpty:
            //        if (!loginRequest.isheadlogin)
            //        {
            //            showCaptcha = OprateLoginCaptcha();

            //        }
            //        result.data = new { result = false, errorcode = 9, showcaptcha = showCaptcha };
            //        return result;

            //    case UserLoginReturnEnum.SystemError:
            //        if (!loginRequest.isheadlogin)
            //        {
            //            showCaptcha = OprateLoginCaptcha();

            //        }
            //        result.data = new { result = false, errorcode = 10, showcaptcha = showCaptcha };
            //        return result;

            //    case UserLoginReturnEnum.UnActivate:
            //        LoginSuccessOprate(loginResult.Data.UserId, loginResult.Data.UserName, loginRequest.key, loginRequest.remember, loginRequest.account);
            //        result.data = new { result = false, errorcode = 11, userid = loginResult.Data.UserId };
            //        return result;
            //    case UserLoginReturnEnum.UnFound:
            //        showCaptcha = OprateLoginCaptcha();
            //        result.data = new { result = false, errorcode = 12, showcaptcha = showCaptcha };
            //        return result;
            //}

            //LoginSuccessOprate(loginResult.Data.UserId, loginResult.Data.UserName, loginRequest.key, loginRequest.remember, loginRequest.account);
            //播种Cookie种子
            //var seed = new CookiesPlant().GetSeed();
            //SowCookie("SEED", seed, false, DateTime.MaxValue);

            result.data = new { result = true };
            return(result);
        }