"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/login.js" (8 Mar 2017, 3696 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 (function() {
    2   var Command, Login, Q, _, auth, open, read, yargs,
    3     bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    4     extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    5     hasProp = {}.hasOwnProperty;
    6 
    7   _ = require('underscore-plus');
    8 
    9   yargs = require('yargs');
   10 
   11   Q = require('q');
   12 
   13   read = require('read');
   14 
   15   open = require('open');
   16 
   17   auth = require('./auth');
   18 
   19   Command = require('./command');
   20 
   21   module.exports = Login = (function(superClass) {
   22     extend(Login, superClass);
   23 
   24     function Login() {
   25       this.saveToken = bind(this.saveToken, this);
   26       this.getToken = bind(this.getToken, this);
   27       this.welcomeMessage = bind(this.welcomeMessage, this);
   28       return Login.__super__.constructor.apply(this, arguments);
   29     }
   30 
   31     Login.getTokenOrLogin = function(callback) {
   32       return auth.getToken(function(error, token) {
   33         if (error != null) {
   34           return new Login().run({
   35             callback: callback,
   36             commandArgs: []
   37           });
   38         } else {
   39           return callback(null, token);
   40         }
   41       });
   42     };
   43 
   44     Login.commandNames = ['login'];
   45 
   46     Login.prototype.parseOptions = function(argv) {
   47       var options;
   48       options = yargs(argv).wrap(100);
   49       options.usage("Usage: apm login\n\nEnter your Atom.io API token and save it to the keychain. This token will\nbe used to identify you when publishing packages to atom.io.");
   50       options.alias('h', 'help').describe('help', 'Print this usage message');
   51       return options.string('token').describe('token', 'atom.io API token');
   52     };
   53 
   54     Login.prototype.run = function(options) {
   55       var callback;
   56       callback = options.callback;
   57       options = this.parseOptions(options.commandArgs);
   58       return Q({
   59         token: options.argv.token
   60       }).then(this.welcomeMessage).then(this.openURL).then(this.getToken).then(this.saveToken).then(function(token) {
   61         return callback(null, token);
   62       })["catch"](callback);
   63     };
   64 
   65     Login.prototype.prompt = function(options) {
   66       var readPromise;
   67       readPromise = Q.denodeify(read);
   68       return readPromise(options);
   69     };
   70 
   71     Login.prototype.welcomeMessage = function(state) {
   72       var welcome;
   73       if (state.token) {
   74         return Q(state);
   75       }
   76       welcome = "Welcome to Atom!\n\nBefore you can publish packages, you'll need an API token.\n\nVisit your account page on Atom.io " + 'https://atom.io/account'.underline + ",\ncopy the token and paste it below when prompted.\n";
   77       console.log(welcome);
   78       return this.prompt({
   79         prompt: "Press [Enter] to open your account page on Atom.io."
   80       });
   81     };
   82 
   83     Login.prototype.openURL = function(state) {
   84       if (state.token) {
   85         return Q(state);
   86       }
   87       return open('https://atom.io/account');
   88     };
   89 
   90     Login.prototype.getToken = function(state) {
   91       if (state.token) {
   92         return Q(state);
   93       }
   94       return this.prompt({
   95         prompt: 'Token>',
   96         edit: true
   97       }).spread(function(token) {
   98         state.token = token;
   99         return Q(state);
  100       });
  101     };
  102 
  103     Login.prototype.saveToken = function(arg) {
  104       var token;
  105       token = arg.token;
  106       if (!token) {
  107         throw new Error("Token is required");
  108       }
  109       process.stdout.write('Saving token to Keychain ');
  110       auth.saveToken(token);
  111       this.logSuccess();
  112       return Q(token);
  113     };
  114 
  115     return Login;
  116 
  117   })(Command);
  118 
  119 }).call(this);