login(username = null, password = null, reconnect = false) {
    return new Promise((resolve, reject) => {
      // Allows to override username+password
      if (username !== null) {
        this.opts.username = username;
      }

      if (password !== null) {
        this.opts.password = password;
      }

      // Make sure init() was called
      this._init().then(result => {
        // If init() was already called
        // resolve immediately
        if (result === 2) {
          resolve(true);
        } else {
          let endpointUrl = `${this._baseurl.href}api/login`;
          if (this._unifios) {
            endpointUrl = `${this._baseurl.href}api/auth/login`;
          }

          // Perform the login to the Unifi controller
          this._instance.post(endpointUrl, {
            username: this.opts.username,
            password: this.opts.password
          }).then(() => {
            resolve(true);
          }).catch(() => {
            if (!reconnect) {
              this._reconnect();
            }
          });
        }
      }).catch(error => {
        reject(error);
      });
    });
  }
/**
   * Login to the UniFi controller - login()
   *
   * returns true upon success
   */
Login to the UniFi controller - login()
returns true upon success
Login to the UniFi controller - login () returns true upon success
login(username = null, password = null, reconnect = false) {
    return new Promise((resolve, reject) => {
      if (username !== null) {
        this.opts.username = username;
      }
      if (password !== null) {
        this.opts.password = password;
      }
      this._init().then(result => {
        if (result === 2) {
          resolve(true);
        } else {
          let endpointUrl = `${this._baseurl.href}api/login`;
          if (this._unifios) {
            endpointUrl = `${this._baseurl.href}api/auth/login`;
          }
          this._instance.post(endpointUrl, {
            username: this.opts.username,
            password: this.opts.password
          }).then(() => {
            resolve(true);
          }).catch(() => {
            if (!reconnect) {
              this._reconnect();
            }
          });
        }
      }).catch(error => {
        reject(error);
      });
    });
  }
login ( username = null , password = null , reconnect = false ) { return new Promise ( ( resolve , reject ) => { if ( username !== null ) { this . opts . username = username ; } if ( password !== null ) { this . opts . password = password ; } this . _init ( ) . then ( result => { if ( result === 2 ) { resolve ( true ) ; } else { let endpointUrl = ` ${ this . _baseurl . href } ` ; if ( this . _unifios ) { endpointUrl = ` ${ this . _baseurl . href } ` ; } this . _instance . post ( endpointUrl , { username : this . opts . username , password : this . opts . password } ) . then ( ( ) => { resolve ( true ) ; } ) . catch ( ( ) => { if ( ! reconnect ) { this . _reconnect ( ) ; } } ) ; } } ) . catch ( error => { reject ( error ) ; } ) ; } ) ; }
Login to the UniFi controller - login()
 returns true upon success
Login to the UniFi controller - login () returns true upon success
// Allows to override username+password // Make sure init() was called // If init() was already called // resolve immediately // Perform the login to the Unifi controller