dereuromark / cakephp-captcha

Dead simple, unobtrusive and extendable captcha solution for CakePHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Captcha @ Login

docelmo opened this issue · comments

I am using the table version of the example with my login form. It doesnt appear to be working. What am I missing?

How are u using it, and what do you mean with "not working"?

Here is my login routine in my Users controller. When I login it doesnt appear to be working with the captcha is wrong. How can I check to see if the captcha is correct before I try to identify them?

public function login(){
    $this->viewBuilder()->setLayout('login');
    $this->Users->addBehavior('Captcha.Captcha');

    if ($this->request->is('post')) {

        try {
            $userad = $this->Auth->identify();
        } catch (Exception $e) {
            $this->Flash->error("Error authenticating you.  I cannot connect to the domain controller.");
            $this->redirect("/Users/login");
        }
        if (!$userdb = $this->Users->find()->where(['Users.email' => $userad['userprincipalname']])->toArray()){
            $this->Flash->error(__('You have no valid profile.  Please contact the GCS Helpdesk +1-866-767-7822 M-F 7am-7pm Eastern'));
            return $this->redirect($this->Auth->redirectUrl());
        }

        $user = $userdb[0];
        $user['userad'] = $userad;

        if ($userdb) {
            $this->Auth->setUser($user);
            if ($user['usertype_id'] == 2) {
                 return $this->redirect('/carts/masterindex');
             } else {
                 return $this->redirect('/users/dashboard');
             }
        } else {
            $this->Flash->error(__('Username or password is incorrect'));
        }
    }        
}

As documented this works mainly for patching/validation

$this->Ads->newEntity($postData);

In your case there is no patching, directly Auth lookup only.
Here you would need to manually add the validation into a form or alike ( https://github.com/dereuromark/cakephp-captcha/tree/master/docs#working-with-model-less-forms ).

Where are you instancing this from? $contactForm = new ContactForm(); What is ContactForm() in this instance?

Sorry I dont know all the lingo. I have done that but I know I cant extend the login form to it. So I will be extending your code to include checking @ login. I will send you a diff.

ping @matcsa