使用strophe.register.js在新注册期间未定义conn.authenticate

时间:2014-07-31 10:33:07

标签: openfire ejabberd strophe

大家好我想在我的本地openfire服务器上注册新帐户,使用strophe.js和strophe.register.js插件,按照许多网站上提供的注册步骤提供。但是我在strophe.register.js中收到错误文件行 var auth_old = conn.authenticate.bind(conn); 表示conn.authenticate未定义 下面是我的代码
  我的js文件的代码

$(document).ready(function () {              
var conn = new Strophe.Connection(
    "http://jabber.local/http-bind");
console.log(conn);
var callback = function (status) {

    if ( status === Strophe.Status.REGISTERING ) {
        console.log('REGISTERING')
    conn.authenticate();
    }

    else if ( status === Strophe.Status.REGIFAIL ) {
        console.log('REGIFAIL')
    }

    else if ( status === Strophe.Status.REGISTER ) {
        console.log('REGISTER')
        conn.register.fields.username = "joe"
                conn.register.fields.password = "doe"
                conn.register.submit();
    }

    else if ( status === Strophe.Status.SUBMITTING ) {
        console.log('SUBMITTING')
    }

    else if ( status === Strophe.Status.SBMTFAIL ) {
        console.log('SBMTFAIL')
        console.log('Something went wrong...');
    }

    else if ( status === Strophe.Status.REGISTERED ) {
        console.log('REGISTERED')

        console.log('Your account has been created successfully and is ready to use!');

    }

}   

conn.register.connect("example.com", callback);

});

并且html文件代码是

<html>
<head>

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js'></script>
<script src='../scripts/strophe.js'></script>
<script type="text/javascript" src="../scripts/strophe.register.js"></script>
<script src='../scripts/flXHR.js'></script>
<script src='../scripts/strophe.flxhr.js'></script>

<link rel='stylesheet' href='hello.css'>
<script src='hello.js'></script>
</head>
<body>
<h1>Hello</h1>

<div id='log'>
</div>

<!-- login dialog -->
<div id='login_dialog' class='hidden'>
  <label>JID:</label><input type='text' id='jid'>
  <label>Password:</label><input type='password' id='password'>
</div>
</body>
</html>

可以告诉我为什么会发生这种情况以及如何解决这个问题。还有一件事我还会评论大多数网站所说的话。

/* if (register.length === 0) {
        conn._changeConnectStatus(Strophe.Status.REGIFAIL, null);
        return true;
    }*/
this.enabled = true;

1 个答案:

答案 0 :(得分:0)

注意到您使用的是旧版本的插件。请从https://github.com/metajack/strophejs-plugins/blob/master/register/strophe.register.js

更新strophe.register.js

我已经检查了它下面没有的最新版本

var auth_old = conn.authenticate.bind(conn);