How to use the when function in when

To help you get started, we’ve selected a few when examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ZachLiuGIS / reactjs-auth-django-rest / react_frontend_old / services / AuthService.jsx View on Github external
getUserData(token) {
        return (when(request({
            url: UserConstants.USER_DETAIL_URL,
            method: 'GET',
            type: 'json',

            // add Authorization header for api authentication
            headers: {
                'Authorization': 'Token ' + UserStore.token
            }
        })).then(function(data) {
            console.log(data);
            UserActions.loadUserDetail(data);
        }));
    }
github Cedric1996C / DCOS-Auth / src / components / Login.jsx View on Github external
em.on('login', function(username, search) {
      $('#failAlert').hide()
      $('#successAlert').show();

      const url = `${window.location.origin}/authorize${search}&username=${username}`;
      when(request({
        url: url,
        method: 'GET',
        crossOrigin: true,
        type: 'json',
      })
      .then(function(code){
        var Code = code.code
        window.location = `${Code.redirectUri}/?code=${Code.authorizationCode}`
      })
      .catch( err => {
        console.log("no res")
      }))
      // window.close()
    }.bind(this))
  }
github ZachLiuGIS / reactjs-auth-django-rest / react_frontend_old / services / AuthService.jsx View on Github external
reset_password(email) {
        return (when(request({
            url: UserConstants.PASSWORD_RESET_URL,
            method: 'POST',
            type: 'json',

            data: {
                email: email
            }
        })).then(function(data) {
            console.log(data);
            alert('password reset email sent');
            return true;
        }));
    }
github Cedric1996C / DCOS-Auth / src / service / AuthService.js View on Github external
login(username, password) {
    return when(request({
      url: LOGIN_URL,
      method: 'POST',
      crossOrigin: true,
      type: 'json',
      data: {
         username: username,
         password: password
      }
    })).then(function(response) {
        const status = response.status;
        const search = window.location.search
        if(status == 'ok'){
          em.emit('login', username, search);
          return true;
        }
      });;
github ZachLiuGIS / reactjs-auth-django-rest / react_frontend_old / services / AuthService.jsx View on Github external
signup(email, username, password1, password2) {
        console.log(password1, password2);
        return this.handleAuth(when(request({
            url: UserConstants.SIGNUP_URL,
            method: 'POST',
            type: 'json',
            data: {
                email: email,
                username: username,
                password1: password1,
                password2: password2
            }
        })));
    }
github ldvm / LDVMi / src / app / assets_webpack / assistant / javascripts / misc / rest.js View on Github external
export default async function rest(url, payload = null, method = 'POST') {
  try {
    debug('API call: ' + url);
    const response = await when(request({
      url: url.startsWith('/') ? url : apiEndpoint + '/' + url,
      method: method,
      crossOrigin: true,
      type: 'json',
      contentType: 'application/json',
      data: JSON.stringify(payload)
    }));

    return response;
  } catch (response) {
    debug('API call failed with status ' + response.status);

    if (response.status === 0) {
      throw new Error('API endpoint did not respond. Is backend running?');
    } else if (response.status === 404) {
      throw new Error('API endpoint did not recognize this call (404 Not Found)');
github thebillkidy / Brewr-Site / frontend / src / js / services / AuthService.js View on Github external
login(username, password) {

        return this.handleAuth(when(request({
            url: LOGIN_URL,
            method: 'POST',
            crossOrigin: true,
            type: 'json',
            data: {
                email: username,
                password: password
            }
        })));
    }
github auth0-blog / react-flux-jwt-authentication-sample / src / services / AuthService.js View on Github external
login(username, password) {
    return this.handleAuth(when(request({
      url: LOGIN_URL,
      method: 'POST',
      crossOrigin: true,
      type: 'json',
      data: {
        username, password
      }
    })));
  }
github particle-iot / particle-cli / src / lib / library.js View on Github external
run(state, site) {
		const libsPromise = when().then(() => site.getLibraries());
		return when.map(libsPromise, libdir => {
			site.notifyStart(libdir);
			const dir = path.resolve(libdir);
			const repo = new FileSystemLibraryRepository(dir, FileSystemNamingStrategy.DIRECT);
			return this.processLibrary(repo, '', state, site)
			.then(([res, err]) => {
				site.notifyEnd(libdir, res, err);
				return {libdir, res, err};
			});
		});
	}
github particle-iot / particle-cli / src / cmd / command.js View on Github external
run(cmd, state = {}) {
		return when()
		.then(() => this.begin(state, this))
		.then(() => cmd.run(state, this))
		.finally(() => this.end(state, this));
	}
}