Example #1
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);
        }
Example #2
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);
        }