Debugging V4 and adding some security logic.
This commit is contained in:
parent
2584717ae8
commit
f6bf1068bb
6 changed files with 190 additions and 68 deletions
|
@ -53,81 +53,84 @@ export class AdminDialog extends IGBDialog {
|
|||
let deployer = new GBDeployer(min.core, importer);
|
||||
|
||||
min.dialogs.add("/admin", [
|
||||
async (dc, args) => {
|
||||
const prompt = "Please, authenticate:";
|
||||
await dc.prompt('textPrompt', prompt);
|
||||
},
|
||||
async (dc, value) => {
|
||||
var text = value.response;
|
||||
const user = min.userState.get(dc.context);
|
||||
async (dc, args) => {
|
||||
const prompt = "Please, authenticate:";
|
||||
await dc.prompt('textPrompt', prompt);
|
||||
},
|
||||
async (dc, value) => {
|
||||
let text = value;
|
||||
const user = min.userState.get(dc.context);
|
||||
|
||||
if (
|
||||
!user.authenticated ||
|
||||
text === GBConfigService.get("ADMIN_PASS")
|
||||
) {
|
||||
user.authenticated = true;
|
||||
dc.context.sendActivity(
|
||||
"Welcome to Pragmatismo.io GeneralBots Administration."
|
||||
);
|
||||
await dc.prompt('textPrompt', "Which task do you wanna run now?");
|
||||
} else {
|
||||
dc.endAll();
|
||||
}
|
||||
},
|
||||
async (dc, value) => {
|
||||
var text = value;
|
||||
const user = min.userState.get(dc.context);
|
||||
if (
|
||||
!user.authenticated ||
|
||||
text === GBConfigService.get("ADMIN_PASS")
|
||||
) {
|
||||
user.authenticated = true;
|
||||
dc.context.sendActivity(
|
||||
"Welcome to Pragmatismo.io GeneralBots Administration."
|
||||
);
|
||||
await dc.prompt('textPrompt', "Which task do you wanna run now?");
|
||||
} else {
|
||||
dc.endAll();
|
||||
}
|
||||
},
|
||||
async (dc, value) => {
|
||||
var text = value;
|
||||
const user = min.userState.get(dc.context);
|
||||
|
||||
if (text === "quit") {
|
||||
user.authenticated = false;
|
||||
dc.replace("/");
|
||||
} else if (text === "sync") {
|
||||
min.core.syncDatabaseStructure(() => { });
|
||||
dc.context.sendActivity("Sync started...");
|
||||
if (text === "quit") {
|
||||
user.authenticated = false;
|
||||
dc.replace("/");
|
||||
} else if (text === "sync") {
|
||||
min.core.syncDatabaseStructure(() => { });
|
||||
dc.context.sendActivity("Sync started...");
|
||||
dc.replace("/admin", {
|
||||
firstRun: false
|
||||
});
|
||||
} else if (text.split(" ")[0] === "rebuildIndex") {
|
||||
AdminDialog.rebuildIndexCommand(min, dc, () =>
|
||||
dc.replace("/admin", {
|
||||
firstRun: false
|
||||
});
|
||||
} else if (text.split(" ")[0] === "rebuildIndex") {
|
||||
AdminDialog.rebuildIndexCommand(min, dc, () =>
|
||||
})
|
||||
);
|
||||
} else if (text.split(" ")[0] === "deployPackage") {
|
||||
AdminDialog.deployPackageCommand(text, dc, deployer, min, () =>
|
||||
dc.replace("/admin", {
|
||||
firstRun: false
|
||||
})
|
||||
);
|
||||
} else if (text.split(" ")[0] === "redeployPackage") {
|
||||
AdminDialog.undeployPackageCommand(text, min, dc, () => {
|
||||
AdminDialog.deployPackageCommand(text, dc, deployer, min, () => {
|
||||
dc.context.sendActivity("Redeploy done.");
|
||||
dc.replace("/admin", {
|
||||
firstRun: false
|
||||
})
|
||||
);
|
||||
} else if (text.split(" ")[0] === "deployPackage") {
|
||||
AdminDialog.deployPackageCommand(text, dc, deployer, min, () =>
|
||||
dc.replace("/admin", {
|
||||
firstRun: false
|
||||
})
|
||||
);
|
||||
} else if (text.split(" ")[0] === "redeployPackage") {
|
||||
AdminDialog.undeployPackageCommand(text, min, dc, () => {
|
||||
AdminDialog.deployPackageCommand(text, dc, deployer, min, () => {
|
||||
dc.context.sendActivity("Redeploy done.");
|
||||
dc.replace("/admin", {
|
||||
firstRun: false
|
||||
});
|
||||
});
|
||||
});
|
||||
} else if (text.split(" ")[0] === "undeployPackage") {
|
||||
AdminDialog.undeployPackageCommand(text, min, dc, () =>
|
||||
dc.replace("/admin", {
|
||||
firstRun: false
|
||||
})
|
||||
);
|
||||
} else if (text.split(" ")[0] === "applyPackage") {
|
||||
dc.context.sendActivity("Applying in progress...");
|
||||
min.core.loadInstance(text.split(" ")[1], (item, err) => {
|
||||
dc.context.sendActivity("Applying done...");
|
||||
dc.replace("/");
|
||||
});
|
||||
});
|
||||
} else if (text.split(" ")[0] === "undeployPackage") {
|
||||
AdminDialog.undeployPackageCommand(text, min, dc, () =>
|
||||
dc.replace("/admin", {
|
||||
firstRun: false
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
} else if (text.split(" ")[0] === "applyPackage") {
|
||||
dc.context.sendActivity("Applying in progress...");
|
||||
min.core.loadInstance(text.split(" ")[1], (item, err) => {
|
||||
dc.context.sendActivity("Applying done...");
|
||||
dc.replace("/");
|
||||
});
|
||||
dc.replace("/admin", {
|
||||
firstRun: false
|
||||
});
|
||||
} else if (text.split(" ")[0] === "rat") {
|
||||
min.conversationalService.sendEvent(dc, "play", { playerType: "login", data: null });
|
||||
dc.context.sendActivity("Realize login clicando no botão de login, por favor...");
|
||||
}
|
||||
])
|
||||
}
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
static undeployPackageCommand(text: any, min: GBMinInstance, dc, cb) {
|
||||
let packageName = text.split(" ")[1];
|
||||
let importer = new GBImporter(min.core);
|
||||
|
|
|
@ -56,7 +56,8 @@ export class WelcomeDialog extends IGBDialog {
|
|||
date < 12 ? "bom dia" : date < 18 ? "boa tarde" : "boa noite";
|
||||
|
||||
let messages = [`Oi, ${msg}.`, `Oi!`, `Olá, ${msg}`, `Olá!`];
|
||||
|
||||
dc.context.sendActivity(messages[0]);
|
||||
|
||||
if (dc.context.activity && dc.context.activity.text != "") {
|
||||
await dc.replace("/answer", { query: dc.context.activity.text });
|
||||
}
|
||||
|
|
|
@ -240,13 +240,18 @@ export class GBMinService {
|
|||
|
||||
const state = conversationState.get(context);
|
||||
const dc = min.dialogs.createContext(context, state);
|
||||
|
||||
|
||||
const user = min.userState.get(dc.context);
|
||||
if (!user.loaded) {
|
||||
min.conversationalService.sendEvent(
|
||||
dc,
|
||||
"loadInstance",
|
||||
min.instance // TODO: Send just necessary values.
|
||||
{
|
||||
instanceId: instance.instanceId,
|
||||
botId: instance.botId,
|
||||
theme: instance.theme,
|
||||
secret: instance.webchatKey, // TODO: Use token.
|
||||
}
|
||||
);
|
||||
|
||||
user.loaded = true;
|
||||
|
@ -263,10 +268,12 @@ export class GBMinService {
|
|||
|
||||
// Check to see if anyone replied. If not then start echo dialog
|
||||
|
||||
if (!context.responded) {
|
||||
if (!user.once) {
|
||||
await dc.begin('/');
|
||||
} else if (context.activity.name === "whoAmI") {
|
||||
dc.begin("/whoAmI");
|
||||
} else if (context.activity.text === "admin") {
|
||||
dc.begin("/admin");
|
||||
} else if (context.activity.name === "showSubjects") {
|
||||
dc.begin("/menu");
|
||||
} else if (context.activity.name === "giveFeedback") {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "default.gbui",
|
||||
"version": "0.0.10",
|
||||
"version": "0.0.11",
|
||||
"private": true,
|
||||
"homepage": ".",
|
||||
"dependencies": {
|
||||
|
@ -8,6 +8,7 @@
|
|||
"botframework-webchat": "^0.14.2",
|
||||
"deep-extend": "^0.6.0",
|
||||
"fetch": "^1.1.0",
|
||||
"msal": "^0.2.2",
|
||||
"react": "^16.4.2",
|
||||
"react-dom": "^16.4.2",
|
||||
"react-helmet": "^5.2.0",
|
||||
|
|
|
@ -34,6 +34,7 @@ import React from "react";
|
|||
import GBMarkdownPlayer from "./players/GBMarkdownPlayer.js";
|
||||
import GBImagePlayer from "./players/GBImagePlayer.js";
|
||||
import GBVideoPlayer from "./players/GBVideoPlayer.js";
|
||||
import GBLoginPlayer from "./players/GBLoginPlayer.js";
|
||||
import GBBulletPlayer from "./players/GBBulletPlayer.js";
|
||||
import SidebarMenu from "./components/SidebarMenu.js";
|
||||
import GBCss from "./components/GBCss.js";
|
||||
|
@ -223,6 +224,16 @@ class GBUIApp extends React.Component {
|
|||
/>
|
||||
);
|
||||
break;
|
||||
case "login":
|
||||
playerComponent = (
|
||||
<GBLoginPlayer
|
||||
app={this}
|
||||
ref={player => {
|
||||
this.player = player;
|
||||
}}
|
||||
/>
|
||||
);
|
||||
break;
|
||||
default:
|
||||
console.log(
|
||||
"GBERROR: Unknow player type specified on message from server."
|
||||
|
|
99
deploy/default.gbui/src/players/GBLoginPlayer.js
Normal file
99
deploy/default.gbui/src/players/GBLoginPlayer.js
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*****************************************************************************\
|
||||
| ( )_ _ |
|
||||
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
|
||||
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
|
||||
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
|
||||
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
|
||||
| | | ( )_) | |
|
||||
| (_) \___/' |
|
||||
| |
|
||||
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
|
||||
| Licensed under the AGPL-3.0. |
|
||||
| |
|
||||
| According to our dual licensing model, this program can be used either |
|
||||
| under the terms of the GNU Affero General Public License, version 3, |
|
||||
| or under a proprietary license. |
|
||||
| |
|
||||
| The texts of the GNU Affero General Public License with an additional |
|
||||
| permission and of our proprietary license can be found at and |
|
||||
| in the LICENSE file you have received along with this program. |
|
||||
| |
|
||||
| This program is distributed in the hope that it will be useful, |
|
||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
| GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| "General Bots" is a registered trademark of Pragmatismo.io. |
|
||||
| The licensing of the program under the AGPLv3 does not imply a |
|
||||
| trademark license. Therefore any rights, title and interest in |
|
||||
| our trademarks remain entirely with us. |
|
||||
| |
|
||||
\*****************************************************************************/
|
||||
|
||||
import React from "react";
|
||||
import { UserAgentApplication } from "msal";
|
||||
|
||||
class GBLoginPlayer extends React.Component {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
token: "",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
login() {
|
||||
|
||||
let config = {
|
||||
tenant: "pragmatismo.onmicrosoft.com", //"6ecb2a67-15af-4582-ab85-cc65096ce471",
|
||||
signUpSignInPolicy: "b2c_1_susi",
|
||||
clientID: '47cbaa05-dbb4-46f8-8608-da386c5131f1'}
|
||||
|
||||
|
||||
let authority = "https://login.microsoftonline.com/tfp/" +
|
||||
config.tenant + "/" +
|
||||
config.signUpSignInPolicy;
|
||||
|
||||
let userAgentApplication = new UserAgentApplication(
|
||||
config.clientID, authority,
|
||||
function (errorDesc, token, error, tokenType) {
|
||||
console.log(token);
|
||||
}
|
||||
);
|
||||
|
||||
let graphScopes = ["Directory.AccessAsUser.All"];
|
||||
|
||||
userAgentApplication.loginPopup(graphScopes).then(function (idToken) {
|
||||
userAgentApplication.acquireTokenSilent(graphScopes).then(function (accessToken) {
|
||||
console.log(accessToken);
|
||||
|
||||
}, function (error) {
|
||||
userAgentApplication.acquireTokenPopup(graphScopes).then(function (accessToken) {
|
||||
console.log(accessToken);
|
||||
|
||||
}, function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
})
|
||||
}, function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
|
||||
play() {
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<button
|
||||
value="Login"
|
||||
onClick={this.login}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default GBLoginPlayer;
|
Loading…
Add table
Reference in a new issue