Skip to content

Commit

Permalink
Features Register and Login
Browse files Browse the repository at this point in the history
  • Loading branch information
ItaloYeltsin committed Feb 25, 2020
1 parent e69dbcd commit bd2c520
Show file tree
Hide file tree
Showing 11 changed files with 579 additions and 35 deletions.
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "totalcross",
"displayName": "TotalCross Project Extension",
"description": "This is TotalCross plugin extension for vs code. ",
"version": "0.0.2",
"version": "0.0.3",
"publisher": "Italo",
"preview": true,
"icon": "icon.png",
Expand All @@ -17,6 +17,8 @@
"Other"
],
"activationEvents": [
"onCommand:extension.login",
"onCommand:extension.register",
"onCommand:extension.createNewProject",
"onCommand:extension.package",
"onCommand:extension.deploy",
Expand All @@ -40,6 +42,14 @@
{
"command": "extension.deployAndRun",
"title": "TotalCross: Deploy&Run"
},
{
"command": "extension.login",
"title": "TotalCross: Login"
},
{
"command": "extension.register",
"title": "TotalCross: Register"
}
]
},
Expand Down Expand Up @@ -68,7 +78,7 @@
"pom-parser": "^1.1.1",
"replace-in-file": "^4.2.0",
"request": "^2.88.0",
"totalcross-core-dev": "0.0.0",
"totalcross-core-dev": "0.0.8",
"xml-js": "^1.6.11"
}
}
22 changes: 22 additions & 0 deletions src/components/components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as vscode from 'vscode';

export function showInputBox(prompt: string, placeHolder: string, validator: any) {
const options: vscode.InputBoxOptions = {
prompt: prompt,
placeHolder: placeHolder,
validateInput: validator,
ignoreFocusOut: true
};
return vscode.window.showInputBox(options);
}

export function showInputBoxPassword(prompt: string, placeHolder: string, validator: any) {
const options: vscode.InputBoxOptions = {
prompt: prompt,
ignoreFocusOut: true,
placeHolder: placeHolder,
validateInput: validator,
password: true
};
return vscode.window.showInputBox(options);
}
56 changes: 37 additions & 19 deletions src/Creator.ts → src/creator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as vscode from 'vscode';
import {showInputBox} from './components/components';
import { pathToFileURL } from 'url';
import { LoginHandler } from './login';
import { RegisterHandler } from './register';
const core = require('totalcross-core-dev');
const validators = require('./validators/creator');
const fs = require('fs-extra');
const request = require('request');
Expand All @@ -14,7 +18,30 @@ const options: vscode.OpenDialogOptions = {
};

exports.createNewProject = async function(context: vscode.ExtensionContext) {
let file = await vscode.window.showOpenDialog(options);
let auth = null;
let status = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
status.text = `$(sync~spin) TotalCross Checking login credentials...`;
status.show();
try {
auth = await core.auth();
}
catch(exp) {
auth = false;
}
status.hide();
if(!auth) {
let res = await vscode.window.showErrorMessage('You must login your account in to create a new project', 'Login', 'New Account');
if(res) {
if(res === 'Login') {
new LoginHandler().showLoginPanel();
}
else {
new RegisterHandler().doRegister();
}
}
return;
}
let file = await vscode.window.showOpenDialog(options);
if(file === undefined) {return;}

// Get Project Information
Expand All @@ -31,25 +58,24 @@ exports.createNewProject = async function(context: vscode.ExtensionContext) {
validators.artifactId
);
if(!artifactID) {return;}
let availableVersions = await getAvailableVersions(`${context.extensionPath}/resources/maven-metadata.xml`);
let availableVersions = await core.versions(`${context.extensionPath}/resources/maven-metadata.xml`);
let version = await vscode.window.showQuickPick(availableVersions, {
placeHolder: 'totalcross sdk version'
placeHolder: 'totalcross sdk version',
ignoreFocusOut: true

});
if(!version) {return;}
let platforms = await vscode.window.showQuickPick (
["-android", "-ios", "-linux", "-linux_arm", "-win32", "-wince"],
{
canPickMany: true,
placeHolder: 'example: -linux_arm'
placeHolder: 'example: -linux_arm',
ignoreFocusOut: true
}
);
if(!platforms) {return;}

let activationKey = await showInputBox(
'Enter your TotalCross Activation key (24 characters)',
'000000000000000000000000',
validators.activationKey
);

let activationKey = "5443444B5AAEEB90306B00E4";
if(!activationKey) {return;}

let props = {artifactID, groupID, platforms, version, activationKey};
Expand All @@ -69,15 +95,7 @@ exports.createNewProject = async function(context: vscode.ExtensionContext) {
vscode.commands.executeCommand('vscode.openFolder', uri);
};

function showInputBox(prompt: string, placeHolder: string, validator: any) {
const options: vscode.InputBoxOptions = {
prompt: prompt,
valueSelection: [0, 10],
placeHolder: placeHolder,
validateInput: validator
};
return vscode.window.showInputBox(options);
}




Expand Down
2 changes: 1 addition & 1 deletion src/Deployer.ts → src/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';
var node_ssh = require('node-ssh');
var validators = require('./validators/deployer');
const pomParser = require('pom-parser');
const Packager = require('./Packager');
const Packager = require('./packager');

var ssh = new node_ssh();
var folder: any;
Expand Down
19 changes: 15 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
var Packager = require('./Packager');
var Deployer = require('./Deployer');
var Creator = require('./Creator');
var Packager = require('./packager');
var Deployer = require('./deployer');
var Creator = require('./creator');
import {login} from './login';
import { register } from './register';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
Expand Down Expand Up @@ -34,9 +36,18 @@ export function activate(context: vscode.ExtensionContext) {
disposable = vscode.commands.registerCommand('extension.deployAndRun', Deployer.deployAndRun);
context.subscriptions.push(disposable);


/**
* Login
*/
disposable = vscode.commands.registerCommand('extension.login', login);
context.subscriptions.push(disposable);

/**
*
* Register
*/
disposable = vscode.commands.registerCommand('extension.register', register);
context.subscriptions.push(disposable);
}

// this method is called when your extension is deactivated
Expand Down
71 changes: 62 additions & 9 deletions src/login.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,71 @@
const core = require('totalcross-core-dev');

import {showInputBox, showInputBoxPassword} from './components/components';
import {validateLogin, validatePassword} from './validators/login';
import {Response} from './model/response';
import * as vscode from 'vscode';
export class LoginHandler {
/**
* Check if token is valid
* return promise with true, if token is valid
* Show login an then password
* return true if some error happen
*/
async verifyToken() {
async showLoginPanel() : Promise<Response>{
return new Promise(async function(resolve, reject) {
let login = await showInputBox(
'Login',
'[email protected]',
validateLogin
);
if(!login) {
return reject({
error: true,
message: 'Empty login!'
});
}
let password = await showInputBoxPassword(
'Password',
'password',
validateLogin
);

if(!password) {
return reject({
error: true,
message: 'Empty password!'
});
}

let myStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
myStatusBarItem.text = `$(sync~spin) TotalCross Login Request...`;
myStatusBarItem.show();
return core.login({
email: login,
password: password
})
.then((response: any) => {
vscode.window.showInformationMessage("TotalCross: you have successfully logged in.");
return {
error: false,
message: response
};
})
.catch((error: any) => {
vscode.window
.showErrorMessage("TotalCross: something got wrong, verify your credentials and try again");
return {
error: true,
message: error
};
})
.then(() => myStatusBarItem.hide());
});

}

/**
* Show login an then password
*/
async showLoginPanel() {


}
}

export function login() {
let loginHandler = new LoginHandler();
loginHandler.showLoginPanel();
}
4 changes: 4 additions & 0 deletions src/model/response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Response {
error: boolean;
message: any;
}
File renamed without changes.
Loading

0 comments on commit bd2c520

Please sign in to comment.