adrianmak Posted July 19, 2017 Share Posted July 19, 2017 For custom form, it is easy to add a recpatcha. But how about on default admin login form ? Link to comment Share on other sites More sharing options...
flydev Posted August 4, 2017 Share Posted August 4, 2017 Hi @adrianmak You can achieve this by using hooks and my ReCaptcha module. First install the MarkupGoogleReCaptcha module then in file ready.php, write the following code : /* * replace the LAST occurence of $search by $replace in $subject */ function str_lreplace($search, $replace, $subject) { return preg_replace('~(.*)' . preg_quote($search, '~') . '~', '$1' . $replace, $subject, 1); } /* * replace the FIRST occurence of $search by $replace in $subject */ function str_freplace($search, $replace, $subject) { $from = '/'.preg_quote($search, '/').'/'; return preg_replace($from, $replace, $subject, 1); } $captchamod = wire('modules')->get("MarkupGoogleRecaptcha"); wire()->addHookProperty('Page::captcha', function($event) use ($captchamod) { $event->return = $captchamod; }); wire()->addHookAfter('Page::render', function($event) { $template = $event->object->template; $page = $event->object; if ($template == 'admin' && !wire('user')->isLoggedin()) { $captchaScript = $page->captcha->getScript() . '</body>'; $captchaHtml = $page->captcha->render() . '</form>'; $event->return = str_freplace('</form>', $captchaHtml, $event->return); $event->return = str_lreplace('</body>', $captchaScript, $event->return); } }); wire()->addHookAfter('Session::authenticate', function($event) { $page = wire('page'); $template = $page->template; if ($template == 'admin') { if ($page->captcha->verifyResponse() == false) { wire('session')->logout(); wire('session')->redirect(wire('config')->urls->admin); } } }); 9 Link to comment Share on other sites More sharing options...
Laegnur Posted yesterday at 02:45 PM Share Posted yesterday at 02:45 PM (edited) Hi I'm trying to do the same thing, but it doesn't seem to work anymore. The ReCaptcha appears, but when I submit the login, the page reloads, but the session does not start. I'm using the invisible ReCaptcha, I don't know if that affects it Edited 23 hours ago by Laegnur Link to comment Share on other sites More sharing options...
flydev Posted 9 hours ago Share Posted 9 hours ago (edited) Hi @Laegnur I suggest you to use @nbcommunication Cloudflare turnstile module if it’s a valid option or @MoritzLost hCaptcha module as my module was not updated for a while, see: —- ps: you can get an introduction on https://weekly.pw/issue/542/ —- About the hook I writen above it may still work, but you have to debug it a bit. The issue you described seem to happen in verifyResponse() check your dev console by checking `Preserve log` on network tab to be able to check whats going on after a page reload. Edited 8 hours ago by flydev added pw weekly issue reference Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now