Toggle navigation
Wialon Playground
Add library
jQuery latest
Bootstrap 3.3.1
Wialon Javascript SDK
Run
Get code
Fork
Save
Examples
Login
Get units
Change unit icon
Get messages
Get sensors
Edit sensors
Commands
Monitoring notification
Track layer
Get resources
Resources and accounts
Account parameters
Do payment
Management Driver
Get POIs
Create POI
Create notification
Get geofences
Geofence parameters
Create geofence
Gurtam map
Units on map
Unit trace
Create report template
Execute report
Execute custom report
Remaining SMS
Create driver
Bind driver to unit
Unit edit fields
Import fillings
Fuel by mail
Token login for site
Advanced authorization form
Token usage in app
Account hierarchy
Nearest units
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Wialon Playground - Login</title> <script type="text/javascript" src="//code.jquery.com/jquery-latest.min.js"></script> <script type="text/javascript" src="//hst-api.wialon.com/wsdk/script/wialon.js"></script> </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>
HTML
#log { border: 1px solid #c6c6c6; }
CSS
// 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 ); });
JS
Result
Source code of example
Close ✕
×
Source code