How to use refresh method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

token.js

Source:token.js Github

copy

Full Screen

...94 * Refresh token method. Useful in a method form as it can be override in tests.95 * @returns {Promise.<String>}96 */97 refreshToken() {98 return this._refresh()99 .then( value => {100 this._validateTokenValue( value );101 this.set( 'value', value );102 if ( this._options.autoRefresh ) {103 this._registerRefreshTokenTimeout();104 }105 } )106 .then( () => this );107 }108 /**109 * Destroys token instance. Stops refreshing.110 */111 destroy() {112 clearTimeout( this._tokenRefreshTimeout );...

Full Screen

Full Screen

server_status_processes.js

Source:server_status_processes.js Github

copy

Full Screen

...119 var label = PMA_messages.strStartRefresh;120 if (processList.autoRefresh) {121 img = 'pause.png';122 label = PMA_messages.strStopRefresh;123 processList.refresh();124 }125 $('a#toggleRefresh').html(PMA_getImage(img) + escapeHtml(label));126 },127 /**128 * Return the Url Parameters129 * for autorefresh request,130 * includes showExecuting if the filter is checked131 *132 * @return urlParams - url parameters with autoRefresh request133 */134 getUrlParams: function() {135 var urlParams = { 'ajax_request': true, 'refresh': true };136 if ($('#showExecuting').is(":checked")) {137 urlParams.showExecuting = true;138 return urlParams;139 }140 return urlParams;141 }142};143AJAX.registerOnload('server_status_processes.js', function() {144 processList.init();145 // Bind event handler for kill_process146 $('#tableprocesslist').on(147 'click',148 'a.kill_process',149 processList.killProcessHandler150 );151 // Bind event handler for toggling refresh of process list152 $('a#toggleRefresh').on('click', function(event) {153 event.preventDefault();154 processList.autoRefresh = !processList.autoRefresh;155 processList.setRefreshLabel();156 });157 // Bind event handler for change in refresh rate158 $('#id_refreshRate').on('change', function(event) {159 processList.refreshInterval = $(this).val();160 processList.refresh();161 });162 // Bind event handler for table header links163 $('#tableprocesslist').on('click', 'thead a', function() {164 processList.refreshUrl = $(this).attr('href');165 });166});167/**168 * Unbind all event handlers before tearing down a page169 */170AJAX.registerTeardown('server_status_processes.js', function() {171 $('#tableprocesslist').off('click', 'a.kill_process');172 $('a#toggleRefresh').off('click');173 $('#id_refreshRate').off('change');174 $('#tableprocesslist').off('click', 'thead a');...

Full Screen

Full Screen

processes.js

Source:processes.js Github

copy

Full Screen

...73 * @param object the event object74 *75 * @return void76 */77 refresh: function refresh() {78 // abort any previous pending requests79 // this is necessary, it may go into80 // multiple loops causing unnecessary81 // requests even after leaving the page.82 processList.abortRefresh(); // if auto refresh is enabled83 if (processList.autoRefresh) {84 var interval = parseInt(processList.refreshInterval, 10) * 1000;85 var urlParams = processList.getUrlParams();86 processList.refreshRequest = $.post(processList.refreshUrl, urlParams, function (data) {87 if (data.hasOwnProperty('success') && data.success) {88 var $newTable = $(data.message);89 $('#tableprocesslist').html($newTable.html());90 Functions.highlightSql($('#tableprocesslist'));91 }92 processList.refreshTimeout = setTimeout(processList.refresh, interval);93 });94 }95 },96 /**97 * Stop current request and clears timeout98 *99 * @return void100 */101 abortRefresh: function abortRefresh() {102 if (processList.refreshRequest !== null) {103 processList.refreshRequest.abort();104 processList.refreshRequest = null;105 }106 clearTimeout(processList.refreshTimeout);107 },108 /**109 * Set label of refresh button110 * change between play & pause111 *112 * @return void113 */114 setRefreshLabel: function setRefreshLabel() {115 var img = 'play';116 var label = Messages.strStartRefresh;117 if (processList.autoRefresh) {118 img = 'pause';119 label = Messages.strStopRefresh;120 processList.refresh();121 }122 $('a#toggleRefresh').html(Functions.getImage(img) + Functions.escapeHtml(label));123 },124 /**125 * Return the Url Parameters126 * for autorefresh request,127 * includes showExecuting if the filter is checked128 *129 * @return urlParams - url parameters with autoRefresh request130 */131 getUrlParams: function getUrlParams() {132 var urlParams = {133 'server': CommonParams.get('server'),134 'ajax_request': true,135 'refresh': true,136 'full': $('input[name="full"]').val(),137 'order_by_field': $('input[name="order_by_field"]').val(),138 'column_name': $('input[name="column_name"]').val(),139 'sort_order': $('input[name="sort_order"]').val()140 };141 if ($('#showExecuting').is(':checked')) {142 urlParams.showExecuting = true;143 return urlParams;144 }145 return urlParams;146 }147};148AJAX.registerOnload('server/status/processes.js', function () {149 processList.init(); // Bind event handler for kill_process150 $('#tableprocesslist').on('click', 'a.kill_process', processList.killProcessHandler); // Bind event handler for toggling refresh of process list151 $('a#toggleRefresh').on('click', function (event) {152 event.preventDefault();153 processList.autoRefresh = !processList.autoRefresh;154 processList.setRefreshLabel();155 }); // Bind event handler for change in refresh rate156 $('#id_refreshRate').on('change', function () {157 processList.refreshInterval = $(this).val();158 processList.refresh();159 }); // Bind event handler for table header links160 $('#tableprocesslist').on('click', 'thead a', function () {161 processList.refreshUrl = $(this).attr('href');162 });163});164/**165 * Unbind all event handlers before tearing down a page166 */167AJAX.registerTeardown('server/status/processes.js', function () {168 $('#tableprocesslist').off('click', 'a.kill_process');169 $('a#toggleRefresh').off('click');170 $('#id_refreshRate').off('change');171 $('#tableprocesslist').off('click', 'thead a'); // stop refreshing further172 processList.abortRefresh();...

Full Screen

Full Screen

jwt.js

Source:jwt.js Github

copy

Full Screen

1const jwt = require('jsonwebtoken');2const { v1: uuidv1 } = require('uuid');3const mockDB = require('./data.mock');4const jwtSecretString = 'everybody loves ice cream';5function getAccessToken(payload) {6 return jwt.sign({user: payload}, jwtSecretString, { expiresIn: '15min' });7}8function getRefreshToken(payload) {9 // get all user's refresh tokens from DB10 const userRefreshTokens = mockDB.tokens.filter(token => token.userId === payload.id);11 // check if there are 5 or more refresh tokens,12 // which have already been generated. In this case we should13 // remove all this refresh tokens and leave only new one for security reason14 if (userRefreshTokens.length >= 5) {15 mockDB.tokens = mockDB.tokens.filter(token => token.userId !== payload.id);16 }17 const refreshToken = jwt.sign({user: payload}, jwtSecretString, { expiresIn: '30d' });18 mockDB.tokens.push({19 id: uuidv1(),20 userId: payload.id,21 refreshToken22 });23 return refreshToken;24}25function verifyJWTToken(token) {26 return new Promise((resolve, reject) => {27 if (!token.startsWith('Bearer')) {28 // Reject if there is no Bearer in the token29 return reject('Token is invalid');30 }31 // Remove Bearer from string32 token = token.slice(7, token.length);33 jwt.verify(token, jwtSecretString, (err, decodedToken) => {34 if (err) {35 return reject(err.message);36 }37 // Check the decoded user38 if (!decodedToken || !decodedToken.user) {39 return reject('Token is invalid');40 }41 resolve(decodedToken.user);42 })43 });44}45function refreshToken(token) {46 // get decoded data47 const decodedToken = jwt.verify(token, jwtSecretString);48 // find the user in the user table49 const user = mockDB.users.find(user => user.id = decodedToken.user.id);50 if (!user) {51 throw new Error(`Access is forbidden`);52 }53 // get all user's refresh tokens from DB54 const allRefreshTokens = mockDB.tokens.filter(refreshToken => refreshToken.userId === user.id);55 if (!allRefreshTokens || !allRefreshTokens.length) {56 throw new Error(`There is no refresh token for the user with`);57 }58 const currentRefreshToken = allRefreshTokens.find(refreshToken => refreshToken.refreshToken === token);59 if (!currentRefreshToken) {60 throw new Error(`Refresh token is wrong`);61 }62 // user's data for new tokens63 const payload = {64 id : user.id,65 email: user.email,66 username: user.username67 };68 // get new refresh and access token69 const newRefreshToken = getUpdatedRefreshToken(token, payload);70 const newAccessToken = getAccessToken(payload);71 return {72 accessToken: newAccessToken,73 refreshToken: newRefreshToken74 };75}76function getUpdatedRefreshToken(oldRefreshToken, payload) {77 // create new refresh token78 const newRefreshToken = jwt.sign({user: payload}, jwtSecretString, { expiresIn: '30d' });79 // replace current refresh token with new one80 mockDB.tokens = mockDB.tokens.map(token => {81 if (token.refreshToken === oldRefreshToken) {82 return {83 ...token,84 refreshToken: newRefreshToken85 };86 }87 return token;88 });89 return newRefreshToken;90}91module.exports = {92 getAccessToken,93 getRefreshToken,94 verifyJWTToken,95 refreshToken...

Full Screen

Full Screen

bootstrap-table-auto-refresh.js

Source:bootstrap-table-auto-refresh.js Github

copy

Full Screen

...29 _init.apply(this, Array.prototype.slice.apply(arguments));30 if (this.options.autoRefresh && this.options.autoRefreshStatus) {31 var that = this;32 this.options.autoRefreshFunction = setInterval(function () {33 that.refresh({silent: that.options.autoRefreshSilent});34 }, this.options.autoRefreshInterval*1000);35 }36 };37 BootstrapTable.prototype.initToolbar = function() {38 _initToolbar.apply(this, Array.prototype.slice.apply(arguments));39 if (this.options.autoRefresh) {40 var $btnGroup = this.$toolbar.find('>.btn-group');41 var $btnAutoRefresh = $btnGroup.find('.auto-refresh');42 if (!$btnAutoRefresh.length) {43 $btnAutoRefresh = $([44 sprintf('<button class="btn btn-default auto-refresh %s" ', this.options.autoRefreshStatus ? 'enabled' : ''),45 'type="button" ',46 sprintf('title="%s">', this.options.formatAutoRefresh()),47 sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.autoRefresh),48 '</button>'49 ].join('')).appendTo($btnGroup);50 $btnAutoRefresh.on('click', $.proxy(this.toggleAutoRefresh, this));51 }52 }53 };54 BootstrapTable.prototype.toggleAutoRefresh = function() {55 if (this.options.autoRefresh) {56 if (this.options.autoRefreshStatus) {57 clearInterval(this.options.autoRefreshFunction);58 this.$toolbar.find('>.btn-group').find('.auto-refresh').removeClass('enabled');59 } else {60 var that = this;61 this.options.autoRefreshFunction = setInterval(function () {62 that.refresh({silent: that.options.autoRefreshSilent});63 }, this.options.autoRefreshInterval*1000);64 this.$toolbar.find('>.btn-group').find('.auto-refresh').addClass('enabled');65 }66 this.options.autoRefreshStatus = !this.options.autoRefreshStatus;67 }68 };...

Full Screen

Full Screen

widget.js

Source:widget.js Github

copy

Full Screen

...35 refreshControl.addEventListener('refreshing', onRefreshstart);36 $.addTopLevelView(refreshControl);37 }38})(arguments[0] || {});39function refresh() {40 if (!list) {41 return;42 }43 show();44 onRefreshstart();45}46function hide() {47 if (!refreshControl) {48 return;49 }50 if (OS_IOS) {51 refreshControl.endRefreshing();52 } else if (OS_ANDROID) {53 refreshControl.setRefreshing(false);...

Full Screen

Full Screen

authorization.controller.js

Source:authorization.controller.js Github

copy

Full Screen

1const jwtSecret = require('../../../common/config/env.config.js').jwt_secret;2const jwtExpiresIn = require('../../../common/config/env.config.js').jwt_expires_in;3const jwt = require('jsonwebtoken');4const crypto = require('crypto');5const RefreshTokenModel = require('../../users/models/refresh-token.model');6exports.login = async (req, res) => {7 try {8 const user = req.body;9 const ipAddress = req.ip;10 const jwtToken = generateJwtToken(user);11 const refreshToken = await generateRefreshToken(user, ipAddress);12 res.status(201).send({13 user,14 accessToken: jwtToken,15 refreshToken: refreshToken.token,16 });17 } catch (err) {18 console.log("Login error: ", err);19 res.status(500).send({ errors: err });20 }21};22exports.refreshToken = async (req, res) => {23 try {24 const token = req.body.refresh_token;25 const ipAddress = req.ip;26 const refreshToken = await RefreshTokenModel.getRefreshToken(token);27 const user = refreshToken.user.toJSON();28 const jwtToken = generateJwtToken(user);29 const newRefreshToken = await generateRefreshToken(user, ipAddress);30 refreshToken.revoked = Date.now();31 refreshToken.revokedByIp = ipAddress;32 refreshToken.replacedByToken = newRefreshToken.token;33 await refreshToken.save();34 res.status(201).send({35 user,36 accessToken: jwtToken,37 refreshToken: newRefreshToken.token38 });39 } catch (err) {40 console.log("Refresh token error: ", err);41 res.status(500).send({ errors: err });42 }43}44// Helpers45function generateJwtToken (user) {46 // create a jwt token containing the user47 return jwt.sign(user, jwtSecret, { expiresIn: jwtExpiresIn });48}49function generateRefreshToken (user, ipAddress) {50 // create a refresh token that expires in 7 days51 return RefreshTokenModel.createRefreshToken({52 user: user.id,53 token: randomTokenString(),54 expires: new Date(Date.now() + 7*24*60*60*1000),55 createdByIp: ipAddress56 });57}58function randomTokenString() {59 return crypto.randomBytes(40).toString('hex');...

Full Screen

Full Screen

OAuthRefreshTokens.js

Source:OAuthRefreshTokens.js Github

copy

Full Screen

1var mongoose = require('mongoose');2var Schema = mongoose.Schema;3const OAuthRefreshToken = new Schema({4 refreshToken: String,5 refreshTokenExpiresAt: Date,6 scope: String,7 client: String,8 user: { type: Schema.Types.ObjectId, ref: 'OAuthUser' },9});10const OAuthRefreshTokens = mongoose.model('OAuthRefreshTokens', OAuthRefreshToken);11OAuthRefreshTokens.getRefreshToken = async (refreshToken) => {12 return await OAuthRefreshTokens.findOne({ refreshToken: refreshToken });13};14OAuthRefreshTokens.revokeToken = async (token) => {15 const refreshToken = await OAuthRefreshToken.findOne({refreshToken: token.refreshToken})16 if(refreshToken){17 await refreshToken.destroy()18 return true19 } else {20 return false21 }22}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var device = new stf.Device(client, 'xxx');3device.refresh(function(err, device) {4 if (err) {5 throw err;6 }7 console.log(device);8});9var stf = require('devicefarmer-stf-client');10var device = new stf.Device(client, 'xxx');11device.refresh(function(err, device) {12 if (err) {13 throw err;14 }15 console.log(device);16});17var stf = require('devicefarmer-stf-client');18var device = new stf.Device(client, 'xxx');19device.refresh(function(err, device) {20 if (err) {21 throw err;22 }23 console.log(device);24});25var stf = require('devicefarmer-stf-client');26var device = new stf.Device(client, 'xxx');27device.refresh(function(err, device) {28 if (err) {29 throw err;30 }31 console.log(device);32});33var stf = require('devicefarmer-stf-client');34var device = new stf.Device(client, 'xxx');35device.refresh(function(err, device) {36 if (err) {37 throw err;38 }39 console.log(device);40});41var stf = require('devicefarmer-stf-client');42var device = new stf.Device(client, 'xxx');43device.refresh(function(err, device) {44 if (err) {45 throw err;46 }47 console.log(device);48});

Full Screen

Using AI Code Generation

copy

Full Screen

1var deviceFarmer = require('devicefarmer-stf');2var client = deviceFarmer.createClient({3});4var refresh = function(deviceId){5 client.refresh(deviceId, function(err, res, body){6 if(err) {7 return console.error('error:', err);8 }9 console.log('statusCode:', res && res.statusCode);10 console.log('body:', body);11 });12}13refresh('1234567890');14body: { success: true }15var deviceFarmer = require('devicefarmer-stf');16var client = deviceFarmer.createClient({17});18var refresh = function(deviceId){19 client.refresh(deviceId, function(err, res, body){20 if(err) {21 return console.error('error:', err);22 }23 console.log('statusCode:', res && res.statusCode);24 console.log('body:', body);25 });26}27refresh('1234567890');28body: { success: true }29var deviceFarmer = require('devicefarmer-stf');30var client = deviceFarmer.createClient({31});32var refresh = function(deviceId){33 client.refresh(deviceId, function(err, res, body){34 if(err) {35 return console.error('error:', err);36 }37 console.log('statusCode:', res && res.statusCode);38 console.log('body:', body);39 });40}41refresh('1234567890');42body: { success: true }43var deviceFarmer = require('devicefarmer-stf');44var client = deviceFarmer.createClient({45});46var refresh = function(deviceId){47 client.refresh(deviceId, function(err, res, body){48 if(err) {49 return console.error('error:', err);50 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf');2device.refresh(function(err, data) {3 console.log(data);4});5var devicefarmer = require('devicefarmer-stf');6device.refresh(function(err, data) {7 console.log(data);8});9var devicefarmer = require('devicefarmer-stf');10device.refresh(function(err, data) {11 console.log(data);12});13var devicefarmer = require('devicefarmer-stf');14device.refresh(function(err, data) {15 console.log(data);16});17var devicefarmer = require('devicefarmer-stf');18device.refresh(function(err, data) {19 console.log(data);20});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful