How to use lockutil method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

user.js

Source:user.js Github

copy

Full Screen

1const mongoose = require('mongoose')2const bcrypt = require('bcrypt')3const Schema = mongoose.Schema4const SALT_WORK_FACTOR = 105const MAX_LOGIN_ATTEMPT = 56const LOCK_TIME = 2*60*60*10007const userSchema = new Schema({8doubanID: String,9username:{10 unique:true,11 type:String,12 required:true,13},14email:{15 unique:true,16 type:String,17 required:true,18},19password:{20 unique:true,21 type:String,22 23},24lockUtil:Number,25loginAtempts:{26 type:Number,27 required:true,28 default:029},30meta: {31 createdAt: {32 type: Date,33 Default: Date.now()34},35 updatedAt:{36 type: Date,37 Default: Date.now()38}39}40})41userSchema.virtual('islocked').get(function() {42 return !!(this.lockUtil && this.lockUtil > Date.now())43})44userSchema.pre('save', function(next) {45 if (this.isNew){46 this.meta.createdAt = this. meta.updatedAt = Date.now()47 48 }else{49 this. meta.updatedAt = Date.now()50 }51 next()52})53userSchema.pre('save',function(next) {54 if(!user.isModified('password')) return next()55 bcrypt.genSalt(SALT_WORK_FACTOR,(err,salt) => {56 if (err) return next(err)57 bcrypt.hash(this.password,salt,(error,hash) => {58 this.password = hash59 next()60 })61 })62 next()63})64userSchema.methods = {65 comparePassword:(_password,password) =>{66 return new Promise((resolve,reject) => {67 bcrypt.compare(_password,password),(err, isMatch) => {68 if(!err) resolve(isMatch)69 else reject(err)70 }71 })72 },73 incLoginAttempts:(user) => {74 return new Promise((resolve,reject) => {75 if (this.lockUtil && this.lockUtil < Date.now()) {76 this.update({77 $set:{78 loginAtempts:179 },80 $unset:{81 lockUtil:182 }83 },(err) => {84 if (!err) resolve(true)85 else reject(err)86 })87 }else {88 let updates = {89 $inc:{90 loginAtempts:191 }92 }93 if (this.loginAtempts+1 >= MAX_LOGIN_ATTEMPT && !this.isLocked){94 updates.$set = {95 lockUtil:Date.now() + LOCK_TIME96 }97 }98 this.update(updates,err => {99 if(!err) resolve(true)100 else reject(err)101 })102 }103 })104 105 }106}...

Full Screen

Full Screen

lockutil.js

Source:lockutil.js Github

copy

Full Screen

1/**2* Copyright © 2019 code initially contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.03**/4const apiutil = require('./apiutil')5const dbapi = require('../db/api')6const lockutil = Object.create(null)7lockutil.unlockDevice = function(lock) {8 if (lock.device) {9 dbapi.unlockDevice(lock.device.serial)10 }11}12lockutil.lockUser = function(email, res, lock) {13 return dbapi.lockUser(email)14 .then(function(stats) {15 return apiutil.computeStats(res, stats, 'user', lock)16 })17}18lockutil.unlockUser = function(lock) {19 if (lock.user) {20 dbapi.unlockUser(lock.user.email)21 }22}23lockutil.lockGroupAndUser = function(req, res, lock) {24 return lockutil.lockGroup(req, res, lock).then(function(lockingSuccessed) {25 return lockingSuccessed ?26 lockutil.lockUser(req.user.email, res, lock) :27 false28 })29}30lockutil.unlockGroupAndUser = function(lock) {31 lockutil.unlockGroup(lock)32 lockutil.unlockUser(lock)33}34lockutil.lockGroup = function(req, res, lock) {35 const id = req.swagger.params.id.value36 const email = req.user.email37 return dbapi.lockGroupByOwner(email, id).then(function(stats) {38 return apiutil.computeStats(res, stats, 'group', lock)39 })40}41lockutil.unlockGroup = function(lock) {42 if (lock.group) {43 dbapi.unlockGroup(lock.group.id)44 }45}46lockutil.unlockGroupAndDevice = function(lock) {47 lockutil.unlockGroup(lock)48 lockutil.unlockDevice(lock)49}50lockutil.lockGenericDevice = function(req, res, lock, lockDevice) {51 return lockDevice(req.user.groups.subscribed, req.swagger.params.serial.value)52 .then(function(stats) {53 return apiutil.computeStats(res, stats, 'device', lock)54 })55}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var lockutil = require('devicefarmer-stf').lockutil;2lockutil.lockScreen(function(err){3 console.log(err);4});5lockutil.unlockScreen(function(err){6 console.log(err);7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var lockutil=require('devicefarmer-stf').lockutil;2var device=lockutil.getDevice();3console.log(device);4console.log(device.locked);5lockutil.unlock();6console.log(device.locked);7lockutil.lock();8console.log(device.locked);9{10 "scripts": {11 },12 "dependencies": {13 }14}

Full Screen

Using AI Code Generation

copy

Full Screen

1var lockutil = require('devicefarmer-stf/lib/util/lockutil');2var adbkit = require('adbkit');3var client = adbkit.createClient();4lockutil.lock(client, '014d0e3c9f7b9c0a', function(err) {5 if (err) {6 console.log('lock failed');7 } else {8 console.log('lock success');9 }10});11lockutil.unlock(client, '014d0e3c9f7b9c0a', function(err) {12 if (err) {13 console.log('unlock failed');14 } else {15 console.log('unlock success');16 }17});18lockutil.reboot(client, '014d0e3c9f7b9c0a', function(err) {19 if (err) {20 console.log('reboot failed');21 } else {22 console.log('reboot success');23 }24});25lockutil.restartAdb(client, '014d0e3c9f7b9c0a', function(err) {26 if (err) {27 console.log('restart adb failed');28 } else {29 console.log('restart adb success');30 }31});32lockutil.restartStfService(client, '014d0e3c9f7b9c0a', function(err) {33 if (err) {34 console.log('restart stf service failed');35 } else {36 console.log('restart stf service success');37 }38});39lockutil.restartStfApp(client, '014d0e3c9f7b9c0a', function(err) {40 if (err) {41 console.log('restart stf app failed');42 } else {43 console.log('restart stf app success');44 }45});46lockutil.restartStf(client, '014d0e3c9f7b9c0a', function(err) {47 if (err) {48 console.log('restart stf failed');49 } else {50 console.log('restart stf success');51 }52});53lockutil.restart(client, '014d0e3c9f7b9c0a', function(err) {54 if (err) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var lockUtil = require('lockutil');2lockUtil.lock(function(err){3 if (err) {4 console.log('Error locking device');5 return;6 }7 console.log('Device locked');8});9{10 "dependencies": {

Full Screen

Using AI Code Generation

copy

Full Screen

1var lockutil = require('devicefarmer-stf').lockutil;2var device = lockutil.lockDevice('deviceName');3device.unlock();4device.tap(100, 100);5device.swipe(100, 100, 200, 200, 100);6device.pressHome();7device.pressBack();8device.pressMenu();9device.pressPower();10device.type("Hello World");11device.type("Hello World", "en");12device.type("Hello World", "en", "US");13device.type("Hello World", "en", "US", true);14var lockutil = require('devicefarmer-stf').lockutil;15var device = lockutil.lockDevice('deviceName');16device.unlock();17device.tap(100, 100);18device.swipe(100, 100, 200, 200, 100);19device.pressHome();20device.pressBack();21device.pressMenu();22device.pressPower();23device.type("Hello World");24device.type("Hello World", "en");25device.type("Hello World", "en", "US");26device.type("Hello World", "en", "US", true);27var lockutil = require('devicefarmer-stf').lockutil;28var device = lockutil.lockDevice('deviceName');29device.unlock();30device.tap(100, 100);31device.swipe(100, 100, 200, 200, 100);32device.pressHome();33device.pressBack();34device.pressMenu();35device.pressPower();36device.type("Hello World");37device.type("Hello World", "en");38device.type("Hello World", "en", "US");39device.type("Hello World", "en", "US", true);40var lockutil = require('devicefarmer-stf').lockutil;41var device = lockutil.lockDevice('deviceName');42device.unlock();43device.tap(100, 100);44device.swipe(100, 100, 200, 200, 100);45device.pressHome();46device.pressBack();47device.pressMenu();48device.pressPower();49device.type("Hello World");50device.type("Hello World", "en");51device.type("Hello World", "en", "US");52device.type("Hello

Full Screen

Using AI Code Generation

copy

Full Screen

1var lockUtil = require('lockutil');2var lock = new lockUtil();3var device = {4};5lock.lock(device, function (err) {6 if (err) {7 console.log(err);8 }9 else {10 console.log("locked");11 }12});13lock.unlock(device, function (err) {14 if (err) {15 console.log(err);16 }17 else {18 console.log("unlocked");19 }20});21{22 "dependencies": {23 }24}

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