Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

服务端验证 #4

Closed
ucoker opened this issue Aug 29, 2016 · 4 comments
Closed

服务端验证 #4

ucoker opened this issue Aug 29, 2016 · 4 comments

Comments

@ucoker
Copy link

ucoker commented Aug 29, 2016

根据教程的服务端验证部分,

  1. app/Http/Requests建立ValidationRequest.php

    <?php namespace App\Http\Requests;
    use App\Http\Requests\Request;
    
    class ValidationRequest extends Request
    {
        /**
         * Determine if the user is authorized to make this request.
         *
         * @return bool
         */
        public function authorize()
        {
            return true;
        }
    
        /**
         * Get the validation rules that apply to the request.
         *
         * @return array
         */
        public function rules()
        {
            return [
                'geetest_challenge' => 'geetest'
            ];
        }
    
        /**
         * Get validation messages.
         *
         * @return array
         */
        public function messages()
        {
            return [
                'geetest' => 'Validation Failed'
            ];
        }
    }
  2. app/Http/Controllers/Auth/AuthController.php 添加:postValidate

    class AuthController extends Controller
    {
        use AuthenticatesAndRegistersUsers, ThrottlesLogins;
        use CaptchaGeetest;
    
    ....
    
    public function postValidate(ValidationRequest $request)
        {
            // is Validate
            $result = $this->validate($request, [
                'geetest_challenge' => 'geetest',
            ], [
                'geetest' => Config::get('geetest.server_fail_alert')
            ]);
            if ($result) {
                return 'success';
            }
        }
    
    ....
    
    }

请问,步骤2对吗?
或者有服务器验证这部分的Demo?
我只需要实现登陆页面进行验证码校验就可以了。

@Germey
Copy link
Owner

Germey commented Aug 29, 2016

不用加两个validate啊,步骤2实际上是Request做了验证,你下面又用了validate做了验证,没必要。其中一种就行了。

@ucoker
Copy link
Author

ucoker commented Aug 29, 2016

那就将步骤2保留

public function postValidate(ValidationRequest $request) {

}

我只需要在登陆的时候用到这个验证,所以将postValidate(ValidationRequest $request)放置在app/Http/Controllers/Auth/AuthController.php没错吧?

服务端验证不知道怎么判断是否起作用,所以才发issue。

谢谢

@Germey
Copy link
Owner

Germey commented Sep 1, 2016

嗯嗯这样就可以了,只需要参数设置成ValidationRequest就能自动调用里面的规则进行验证的。

@ucoker
Copy link
Author

ucoker commented Sep 1, 2016

谢谢

@ucoker ucoker closed this as completed Sep 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants