public function refreshCaptcha($refresh = null, $audio = null, $image = null) { if (!$refresh) { if ($audio) { $this->_captcha = MollomCaptcha::refresh('audio'); } else if ($image) { $this->_captcha = MollomCaptcha::refresh('image'); } } else { $this->_captcha = MollomCaptcha::refresh(); } }
public function testCheckCaptcha() { $captcha = MollomCaptcha::create(); $this->assertEquals('image', $captcha->type); $this->assertEquals('mollom.com/new-captcha', $captcha->url); $this->assertEquals('new-sessionid', Session::get('mollom/sessionid')); Mollom::clear(); // Clear serverlist etc // Probably a post follows, client request new captcha $captcha = MollomCaptcha::check('invalid'); $this->assertNotNull($captcha); $this->assertEquals('image', $captcha->type); $this->assertEquals('mollom.com/invalid-captcha', $captcha->url); // Third try, client requests refresh Mollom::clear(); // Clear serverlist etc $captcha = MollomCaptcha::refresh(); $this->assertNotNull($captcha); $this->assertEquals('image', $captcha->type); $this->assertEquals('mollom.com/refresh-captcha', $captcha->url); // Fourh try, client requests audio file Mollom::clear(); // Clear serverlist etc $captcha = MollomCaptcha::refresh('audio'); $this->assertNotNull($captcha); $this->assertEquals('audio', $captcha->type); $this->assertEquals('mollom.com/refresh-audio-captcha', $captcha->url); // Fifth try, client refreshes Mollom::clear(); // Clear serverlist etc $captcha = MollomCaptcha::refresh(); $this->assertNotNull($captcha); $this->assertEquals('audio', $captcha->type); $this->assertEquals('mollom.com/refresh-audio-captcha', $captcha->url); // Last and valid try Mollom::clear(); // Clear serverlist etc $captcha = MollomCaptcha::check('valid'); $this->assertNull($captcha); $this->assertFalse(Session::has('mollom/sessionid')); }
/** * @post */ public function confirmreset($username, $email, $response, $image = null, $audio = null, $refresh = null) { $newCaptcha = false; if (!($image || $audio || $refresh)) { $error = ''; if ($username != null) { $user = User::getUserByName($username); if (! $user) $error = t('Username not found'); } else if ($email != null) { $user = User::getUserByEmail($email); if (! $user) $error = t('Email not found'); } else { $error = t('You have to give your username or email'); } if (! $error) { $captcha = MollomCaptcha::check($response); if ($captcha) { $error = t('Resetting your password failed'); } } else { $captcha = MollomCaptcha::refresh(); } } else { $error = false; if ($image) { $captcha = MollomCaptcha::refresh('image'); } else if ($audio) { $captcha = MollomCaptcha::refresh('audio'); } else { $captcha = MollomCaptcha::refresh(); } $newCaptcha = true; } // Still all ok if (!$newCaptcha && ! $error) { // prepare reset; $mail = $this->mail(); $mail->username = $user->username; $site = CoOrg::config()->get('site/title'); $key = $user->resetPassword(); $user->save(); $mail->site = $site; $mail->renewURL = CoOrg::createFullURL(array('user/password/renew', $user->username, $key)); $mail->to($user->email) ->subject(t('%site: Your account information', array('site' => $site))) ->send('mails/passwordreset'); $this->notice(t('A mail has been sent to you. Please follow the directions to set a new password for your account.')); $this->redirect('/'); } else { $reset = new ResetPassword; $reset->username = $username; $reset->email = $email; $this->resetPassword = $reset; $this->resetCaptcha = $captcha; if ($error) { $this->error($error); } $this->render('resetpassword'); } }