XOOPS新規登録に画像認証を設置する

このトピックの投稿一覧へ

なし XOOPS新規登録に画像認証を設置する

msg# 1
depth:
0
前の投稿 - 次の投稿 | 親投稿 - 子投稿.1 | 投稿日時 2014/5/11 6:59 | 最終変更
タツ  管理人   投稿数: 2389 オンライン
この何カ月か、外国からの悪戯登録が多かったので困っていました。とりあえず、この登録のユーザー名が常に9文字だったので、ユーザーモジュールの一般設定管理画面からユーザー名を8文字に限定したところ無くなっていました。しかし、リアルで登録する場合(う?ん。。。しかし、残念ながら、実際、登録は悪戯登録に比べると実に無いに等しい。。。)、やはり不都合なので、どうしても現バージョン(legacy 2.2)にユーザー登録の際に画像認証を入れようと思い、どうにか試行錯誤の末、入れることができました。バージョンアップの際、不具合が発生した時に追えるよう、覚書として記録しておこうと思います。

手順

1.captchaモジュールを入れる。(現バージョン2.0)

2.説明にもあるようにcaptcha.phpをhtml/に設置し、管理画面でcaptchaモジュールが利用できることを確認する。

3.html/modules/captcha/preloadフォルダを作成し、

■その1 その中に以下の内容をpreload.class.phpファイルとして挿入する
<?php

if (!defined('XOOPS_ROOT_PATH')) exit();

class captcha_preload extends XCube_ActionFilter
{
function postFilter() {
$this->mRoot->mDelegateManager->add('Legacy.Event.RegistUser.Validate', array($this, 'registUserValidate'));
$this->mRoot->mDelegateManager->add('Legacy.Event.RegistUser.SetValidators', array($this, 'registUserSetValidator'));
}

function registUserValidate($actionForm) {
$handler =& xoops_gethandler('config');
$mConfigs = $handler->getConfigsByDirname('captcha');
if ($mConfigs['registUser']) {
include_once XOOPS_ROOT_PATH.'/modules/captcha/include/api.php';
$captcha_api = captcha_api::getInstance();
if ( !$captcha_api->validate_post() ) {
$actionForm->addErrorMessage(_CAPTCHA_ERROR);
}
}
}

function registUserSetValidator(&$validators) {
$handler =& xoops_gethandler('config');
$mConfigs = $handler->getConfigsByDirname('captcha');
if ($mConfigs['registUser']) {
include_once XOOPS_ROOT_PATH.'/modules/captcha/include/api.php';
$captcha_api = captcha_api::getInstance();
$validators = array(
'caption' => $captcha_api->make_caption(),
'element' => $captcha_api->make_img_input()
);
}
}
}

?>



■その2 html/modules/captcha/xoops_version.phpファイル内の最後に以下のConfig文を追加する。バージョンが低いのでif文を削除(//で対応)する。
// Config
//if (defined('LEGACY_BASE_VERSION') && version_compare(LEGACY_BASE_VERSION, '2.2.2.3', '>')) {
$modversion['config'] = array(
array(
'name' => 'registUser',
'title' => '_MI_CAPTCHA_REGISTUSER' ,
'description' => '_MI_CAPTCHA_REGISTUSER_DESC' ,
'formtype' => 'yesno' ,
'valuetype' => 'int' ,
'default' => 0 ,
'options' => array()
)
);
//}



4.html/modules/user/actions/UserRegisterAction.class.phpを編集する。(赤いコードの部分を2カ所追加)
<?php
/**
* @package user
* @version $Id: UserRegisterAction.class.php,v 1.2 2007/06/07 02:58:44 minahito Exp $
*/

if (!defined('XOOPS_ROOT_PATH')) exit();

require_once XOOPS_MODULE_PATH . "/user/forms/UserRegisterEditForm.class.php";

/***
* @internal
* @public
* This action uses the special technic to realize confirming. It set the
* register action form to Session through serialize(), then forward to the
* confirm action. Because the confirm action can't work without the register
* action form which it fetches from Session, the confim action doesn't need
* to check the permission to register.
*/
class User_UserRegisterAction extends User_Action
{
var $mActionForm = null;
var $mConfig;
var $mEnableAgreeFlag = false;

function prepare(&$controller, &$xoopsUser, $moduleConfig)
{
$this->mConfig = $moduleConfig;

if(is_object($xoopsUser)) {
//
// If user is registered, kick to his information page.
//
$controller->executeForward(XOOPS_URL . "/user.php");
}
if (empty($this->mConfig['allow_register'])) {
$controller->executeRedirect(XOOPS_URL . '/', 6, _MD_USER_LANG_NOREGISTER);
}
}

function execute(&$controller, &$xoopsUser)
{
$this->_processActionForm();
$this->mActionForm->fetch();
$this->mActionForm->validate();


XCube_DelegateUtils::call('Legacy.Event.RegistUser.Validate', new XCube_Ref($this->mActionForm));


if ($this->mActionForm->hasError()) {
return USER_FRAME_VIEW_INPUT;
} else {
$_SESSION['user_register_actionform'] = serialize($this->mActionForm);
$controller->executeForward('./register.php?action=confirm');
}
}

function getDefaultView(&$controller,&$xoopsUser)
{
$this->_processActionForm();
return USER_FRAME_VIEW_INPUT;
}

function _processActionForm()
{
if(isset($_SESSION['user_register_actionform'])){
$this->mActionForm = unserialize($_SESSION['user_register_actionform']);
unset($_SESSION['user_register_actionform']);
return;
}

if ($this->mConfig['reg_dispdsclmr'] != 0 && $this->mConfig['reg_disclaimer'] != null) {
$this->mEnableAgreeFlag = true;
$this->mActionForm =new User_RegisterAgreeEditForm($this->mConfig);
} else {
$this->mActionForm =new User_RegisterEditForm($this->mConfig);
}

$this->mActionForm->prepare();

$root =& XCube_Root::getSingleton();
$this->mActionForm->set('timezone_offset', $root->mContext->getXoopsConfig('default_TZ'));
}

function executeViewInput(&$controller,&$xoopsUser,&$renderSystem)
{
$renderSystem->setTemplateName("user_register_form.html");
//
// Get some objects for input form.
//
$tzoneHandler =& xoops_gethandler('timezone');
$timezones =& $tzoneHandler->getObjects();
$renderSystem->setAttribute('timezones', $timezones);
$renderSystem->setAttribute("actionForm", $this->mActionForm);
$renderSystem->setAttribute("enableAgree", $this->mEnableAgreeFlag);
if($this->mEnableAgreeFlag) {
$renderSystem->setAttribute("disclaimer", $this->mConfig['reg_disclaimer']);
}

$validators = array();
//
// set `$validators = array('caption' => 'Any Caption HTML', 'element' => 'Form element HTML');` in the preload function.
//
XCube_DelegateUtils::call('Legacy.Event.RegistUser.SetValidators', new XCube_Ref($validators));
$renderSystem->setAttribute('validators', $validators);
}
}

?>


5.html/modules/user/templates/user_register_form.htmlを編集する。(赤いコードの部分を1カ所追加)
<{if $actionForm->hasError()}>
<div class="errorMsg">
<ul>
<{foreach item=message from=$actionForm->getErrorMessages()}>
<li><{$message}></li>
<{/foreach}>
</ul>
</div>
<{/if}>

<form action="#" method="post">
<{xoops_token form=$actionForm}>
<table class="outer" width="100%">
<tr>
<th colspan="2" style="text-align:center;"><{$smarty.const._MD_USER_LANG_USERREG}></th>
</tr>
<tr>
<td class="head"><{$smarty.const._MD_USER_LANG_NICKNAME}></td>
<td class="<{cycle values="odd,even"}>"><{xoops_input maxlength=25 name=uname value=$actionForm->get('uname')}></td>
</tr>
<tr>
<td class="head"><{$smarty.const._MD_USER_LANG_EMAIL}></td>
<td class="<{cycle values="odd,even"}>">
<{xoops_input name=email size=30 maxlength=60 value=$actionForm->get('email')}><br />
<label><{xoops_input type=checkbox name=user_viewemail value=1 default=$actionForm->get('user_viewemail')}> <{$smarty.const._MD_USER_LANG_USER_VIEWEMAIL}></label>
</td>
</tr>
<tr>
<td class="head"><{$smarty.const._MD_USER_LANG_WEBSITE}></td>
<td class="<{cycle values="odd,even"}>"><{xoops_input name=url size=30 maxlength=100 value=$actionForm->get('url')}></td>
</tr>
<tr>
<td class="head"><{$smarty.const._MD_USER_LANG_TIMEZONE_OFFSET}></td>
<td class="<{cycle values="odd,even"}>">
<select name="timezone_offset">
<{xoops_optionsArray id=timezone_offset label=zone_name value=offset from=$timezones default=$actionForm->get('timezone_offset')}>
</select>
</td>
</tr>
<tr>
<td class="head"><{$smarty.const._MD_USER_LANG_PASSWORD}></td>
<td class="<{cycle values="odd,even"}>">
<{xoops_input type=password name=pass value=$actionForm->get('pass') size=10 maxlength=32}>
</td>
</tr>
<tr>
<td class="head"><{$smarty.const._MD_USER_LANG_VERIFYPASS}></td>
<td class="<{cycle values="odd,even"}>">
<{xoops_input type=password name=vpass value=$actionForm->get('vpass') size=10 maxlength=32}>
</td>
</tr>

<{* ---- Inserted - XCube Legacy 2.1.6RC1 - 23Sep2008 ---- *}>
<tr>
<td class="head"><{$smarty.const._MD_USER_LANG_USER_MAILOK}></td>
<td class="<{cycle values="odd,even"}>">
<label><{xoops_input type=radio name=user_mailok value=1 default=$actionForm->get('user_mailok')}><{$smarty.const._YES}></label>
<label><{xoops_input type=radio name=user_mailok value=0 default=$actionForm->get('user_mailok')}><{$smarty.const._NO}></label>
</td>
</tr>
<{* ---- /Inserted ---- *}>

<{if $enableAgree}>
<tr>
<td class="head"><{$smarty.const._MD_USER_LANG_DISCLAIMER}></td>
<td class="<{cycle values="odd,even"}>">
<{xoops_textarea name=disclaimer rows=8 cols=50 readonly=true value=$disclaimer}><br />
<label><{xoops_input type=checkbox name=agree value=1 default=$actionForm->get('agree')}> <{$smarty.const._MD_USER_MESSAGE_IAGREE}></label>
</td>
</tr>
<{/if}>


<{if $validators}>
<{foreach from=$validators item=validator}>
<tr>
<td class="head"><{$validator.caption}></td>
<td class="<{cycle values="odd,even"}>">
<{$validator.element}>
</td>
</tr>
<{/foreach}>
<{/if}>


<tr>
<td colspan="2" class="foot" style="text-align:center;">
<input type="submit" value="<{$smarty.const._MD_USER_LANG_SUBMIT}>" />
</td>
</tr>
</table>
</form>

6.管理画面よりcaptchaモジュールをアップデートすると、captchaに一般設定の項目が出現するのでクリックする。
 プリロード _MI_CAPTCHA_REGISTUSER(ユーザーモジュール新規登録に組み込むかどうか)で「はい」を選択する
投票数:25 平均点:2.80

投稿ツリー


     条件検索へ

旅と気ままなフォーラム最新投稿

欲しい商品が必ず見つかるメジャーなネットショップ

ログイン

Facebook,RSSリンク表示

検索

アクセスカウンタ

今日 : 52
昨日 : 575
総計 : 1619812