1

Проблема: Не могу войти в систему

Тема: Проблема: Не могу войти в систему

Здравствуйте!

Авторизовалась с помощью http://hosting.wialon.com/login.html.
Получила токен и теперь пробовала выполнить пример из Javascript API - 
http://sdk.wialon.com/playground/demo/login
Самый первый пример "Login". На вашем сервере все работает.
А вот есть скопировать код и выполнитьь на своем компьютере, то ничего не работает.
Пишет "Error performing request".

2

Проблема: Не могу войти в систему

Re: Проблема: Не могу войти в систему

Перепроверено - всё работает, если создать на основании песочницы такой файл:

+ открыть спойлер
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Wialon Playground - Login</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript" src="https://hst-api.wialon.com/wsdk/script/wialon.js"></script>
    <script type="text/javascript">
// Print message to log
function msg(text) { $("#log").prepend(text + "<br/>"); }

// Login to server using entered username and password
function login() {
    var sess = wialon.core.Session.getInstance(); // get instance of current Session
    var user = sess.getCurrUser(); // get current User
    if( user ) { // if user exists - you are already logged, print username to log
        msg("You are logged as '" + user.getName()+"', click logout button first");
        return; 
    }
  
    // if not logged
    var token = $("#token").val(); // get token from input
    if (!token) { // if token is empty - print message to log
        msg("Enter token");
        return;
    } 

    msg("Trying to login with token '"+ token +"'");
    sess.initSession("https://hst-api.wialon.com"); // initialize Wialon session
    sess.loginToken(token, "", // trying login 
        function (code) { // login callback
            if (code) msg(wialon.core.Errors.getErrorText(code)); // login failed, print error
            else msg("Logged successfully"); // login succeed
        }
    );
}

// Logout
function logout() {
    var user = wialon.core.Session.getInstance().getCurrUser(); // get current user
    if (!user){ msg("You are not logged, click 'login' button"); return; } 
    wialon.core.Session.getInstance().logout( // if user exist - logout
        function (code) { // logout callback
            if (code) msg(wialon.core.Errors.getErrorText(code)); // logout failed, print error
            else msg("Logout successfully"); // logout suceed
        }
    );
}

// Get current user and prints its name to log
function getUser() {
    var user = wialon.core.Session.getInstance().getCurrUser(); // get current user
    // print message 
    if (!user) msg("You are not logged, click 'login' button"); // user not exists
    else msg("You are logged as '" + user.getName() + "'"); // print current user name
}

// execute when DOM ready
$(document).ready(function(){
    // For more info about how to generate token check
    // http://sdk.wialon.com/playground/demo/app_auth_token
    $("#token").val("5dce19710a5e26ab8b7b8986cb3c49e58C291791B7F0A7AEB8AFBFCEED7DC03BC48FF5F8");
    // bind actions to buttons click
    $("#login_btn").click( login );
    $("#logout_btn").click( logout );
    $("#user_btn").click( getUser );
});
    </script>
    <style>
#log {
  border: 1px solid #c6c6c6;
}
    </style>
</head>
<body>

Token: <input type="text" id="token"/>
<input type="button" value="login" id="login_btn" />
<input type="button" value="logout" id="logout_btn" />
<input type="button" value="get user" id="user_btn" />
<div id="log"></div>

</body>
</html>

Вы создавали токен для хостинга и обращаетесь к hst-api.wialon.com? Какой у вас получился файл?

Head of Wialon Local Department
Gurtam
3

Проблема: Не могу войти в систему

(22/04/2016 11:29:30 отредактировано varaksina.a)

Re: Проблема: Не могу войти в систему

Я авторизовалась  здесь http://hosting.wialon.com/login.html
И мне get-параметром вернулся токен. Его я и ввела в данный пример.

+ открыть спойлер
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Wialon Playground - Login</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript" src="https://hst-api.wialon.com/wsdk/script/wialon.js"></script>
</head>
<body>
<style>
#log {
  border: 1px solid #c6c6c6;
}
</style>


Token: <input type="text" id="token"/>
<input type="button" value="login" id="login_btn" />
<input type="button" value="logout" id="logout_btn" />
<input type="button" value="get user" id="user_btn" />
<div id="log"></div>


<script type="text/javascript">
// Print message to log
function msg(text) { $("#log").prepend(text + "<br/>"); }

// Login to server using entered username and password
function login() {
    var sess = wialon.core.Session.getInstance(); // get instance of current Session
    var user = sess.getCurrUser(); // get current User
    if( user ) { // if user exists - you are already logged, print username to log
        msg("You are logged as '" + user.getName()+"', click logout button first");
        return; 
    }
  
    // if not logged
    var token = $("#token").val(); // get token from input
    if (!token) { // if token is empty - print message to log
        msg("Enter token");
        return;
    } 

    msg("Trying to login with token '"+ token +"'");
    sess.initSession("https://hst-api.wialon.com"); // initialize Wialon session
    sess.loginToken(token, "", // trying login 
        function (code) { // login callback
            if (code) msg(wialon.core.Errors.getErrorText(code)); // login failed, print error
            else msg("Logged successfully"); // login succeed
        }
    );
}

// Logout
function logout() {
    var user = wialon.core.Session.getInstance().getCurrUser(); // get current user
    if (!user){ msg("You are not logged, click 'login' button"); return; } 
    wialon.core.Session.getInstance().logout( // if user exist - logout
        function (code) { // logout callback
            if (code) msg(wialon.core.Errors.getErrorText(code)); // logout failed, print error
            else msg("Logout successfully"); // logout suceed
        }
    );
}

// Get current user and prints its name to log
function getUser() {
    var user = wialon.core.Session.getInstance().getCurrUser(); // get current user
    // print message 
    if (!user) msg("You are not logged, click 'login' button"); // user not exists
    else msg("You are logged as '" + user.getName() + "'"); // print current user name
}

// execute when DOM ready
$(document).ready(function(){
    // For more info about how to generate token check
    // [url]http://sdk.wialon.com/playground/demo/app_auth_token[/url]
    $("#token").val("416e4013c18567f4661a9a20b2647d4a48CD9F9580C4AA4441D9CC6F06E5A5139E357AD7");
    // bind actions to buttons click
    $("#login_btn").click( login );
    $("#logout_btn").click( logout );
    $("#user_btn").click( getUser );
});

</script>
</body>
</html>
4

Проблема: Не могу войти в систему

Re: Проблема: Не могу войти в систему

Проверил ваш пример с токеном - всё корректно отработало.
В каком браузере проверяете? Какой ответ на запрос https://hst-api.wialon.com/wialon/ajax. … oken/login приходит?

Head of Wialon Local Department
Gurtam
5

Проблема: Не могу войти в систему

Re: Проблема: Не могу войти в систему

Браузер: Google Chrome
Приходит ответ {"error":4}

6

Проблема: Не могу войти в систему

Re: Проблема: Не могу войти в систему

Надеюсь Вы открываете страничку не напрямую (file:///)?
Должен быть локальный веб-сервер и обращаться к ней нужно по http.

Head of Wialon Local Department
Gurtam
7

Проблема: Не могу войти в систему

Re: Проблема: Не могу войти в систему

Эврика! Теперь все работает. Спасибо!