Initial commit
This commit is contained in:
commit
0de917f6ba
|
@ -0,0 +1,34 @@
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
# Build generated files
|
||||||
|
dist
|
||||||
|
lib
|
||||||
|
release
|
||||||
|
solution
|
||||||
|
temp
|
||||||
|
*.sppkg
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# OSX
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Visual Studio files
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
.vs
|
||||||
|
bin
|
||||||
|
obj
|
||||||
|
|
||||||
|
# Resx Generated Code
|
||||||
|
*.resx.ts
|
||||||
|
|
||||||
|
# Styles Generated Code
|
||||||
|
*.scss.ts
|
||||||
|
*.scss.d.ts
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"msjsdiag.debugger-for-chrome"
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Install Chrome Debugger Extension for Visual Studio Code to debug your components with the
|
||||||
|
* Chrome browser: https://aka.ms/spfx-debugger-extensions
|
||||||
|
*/
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [{
|
||||||
|
"name": "Local workbench",
|
||||||
|
"type": "chrome",
|
||||||
|
"request": "launch",
|
||||||
|
"url": "https://localhost:4321/temp/workbench.html",
|
||||||
|
"webRoot": "${workspaceRoot}",
|
||||||
|
"sourceMaps": true,
|
||||||
|
"sourceMapPathOverrides": {
|
||||||
|
"webpack:///.././src/*": "${webRoot}/src/*",
|
||||||
|
"webpack:///../../../src/*": "${webRoot}/src/*",
|
||||||
|
"webpack:///../../../../src/*": "${webRoot}/src/*",
|
||||||
|
"webpack:///../../../../../src/*": "${webRoot}/src/*"
|
||||||
|
},
|
||||||
|
"runtimeArgs": [
|
||||||
|
"--remote-debugging-port=9222"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Hosted workbench",
|
||||||
|
"type": "chrome",
|
||||||
|
"request": "launch",
|
||||||
|
"url": "https://enter-your-SharePoint-site/_layouts/workbench.aspx",
|
||||||
|
"webRoot": "${workspaceRoot}",
|
||||||
|
"sourceMaps": true,
|
||||||
|
"sourceMapPathOverrides": {
|
||||||
|
"webpack:///.././src/*": "${webRoot}/src/*",
|
||||||
|
"webpack:///../../../src/*": "${webRoot}/src/*",
|
||||||
|
"webpack:///../../../../src/*": "${webRoot}/src/*",
|
||||||
|
"webpack:///../../../../../src/*": "${webRoot}/src/*"
|
||||||
|
},
|
||||||
|
"runtimeArgs": [
|
||||||
|
"--remote-debugging-port=9222",
|
||||||
|
"-incognito"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
// Place your settings in this file to overwrite default and user settings.
|
||||||
|
{
|
||||||
|
// Configure glob patterns for excluding files and folders in the file explorer.
|
||||||
|
"files.exclude": {
|
||||||
|
"**/.git": true,
|
||||||
|
"**/.DS_Store": true,
|
||||||
|
"**/bower_components": true,
|
||||||
|
"**/coverage": true,
|
||||||
|
"**/lib-amd": true,
|
||||||
|
"src/**/*.scss.ts": true
|
||||||
|
},
|
||||||
|
"typescript.tsdk": ".\\node_modules\\typescript\\lib"
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"@microsoft/generator-sharepoint": {
|
||||||
|
"isCreatingSolution": true,
|
||||||
|
"environment": "spo",
|
||||||
|
"version": "1.12.1",
|
||||||
|
"libraryName": "sp-fx-app-dev-simple-password-vault",
|
||||||
|
"libraryId": "d091b369-f63d-459c-846e-5a4323e31745",
|
||||||
|
"packageManager": "npm",
|
||||||
|
"isDomainIsolated": false,
|
||||||
|
"componentType": "webpart"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
# sp-fx-app-dev-simple-password-vault
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
Short summary on functionality and used technologies.
|
||||||
|
|
||||||
|
[picture of the solution in action, if possible]
|
||||||
|
|
||||||
|
## Used SharePoint Framework Version
|
||||||
|
|
||||||
|
![version](https://img.shields.io/npm/v/@microsoft/sp-component-base/latest?color=green)
|
||||||
|
|
||||||
|
## Applies to
|
||||||
|
|
||||||
|
- [SharePoint Framework](https://aka.ms/spfx)
|
||||||
|
- [Microsoft 365 tenant](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant)
|
||||||
|
|
||||||
|
> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/o365devprogram)
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
> Any special pre-requisites?
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
|
||||||
|
Solution|Author(s)
|
||||||
|
--------|---------
|
||||||
|
folder name | Author details (name, company, twitter alias with link)
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
Version|Date|Comments
|
||||||
|
-------|----|--------
|
||||||
|
1.1|March 10, 2021|Update comment
|
||||||
|
1.0|January 29, 2021|Initial release
|
||||||
|
|
||||||
|
## Disclaimer
|
||||||
|
|
||||||
|
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Minimal Path to Awesome
|
||||||
|
|
||||||
|
- Clone this repository
|
||||||
|
- Ensure that you are at the solution folder
|
||||||
|
- in the command-line run:
|
||||||
|
- **npm install**
|
||||||
|
- **gulp serve**
|
||||||
|
|
||||||
|
> Include any additional steps as needed.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
Description of the extension that expands upon high-level summary above.
|
||||||
|
|
||||||
|
This extension illustrates the following concepts:
|
||||||
|
|
||||||
|
- topic 1
|
||||||
|
- topic 2
|
||||||
|
- topic 3
|
||||||
|
|
||||||
|
> Notice that better pictures and documentation will increase the sample usage and the value you are providing for others. Thanks for your submissions advance.
|
||||||
|
|
||||||
|
> Share your web part with others through Microsoft 365 Patterns and Practices program to get visibility and exposure. More details on the community, open-source projects and other activities from http://aka.ms/m365pnp.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Getting started with SharePoint Framework](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant)
|
||||||
|
- [Building for Microsoft teams](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/build-for-teams-overview)
|
||||||
|
- [Use Microsoft Graph in your solution](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/using-microsoft-graph-apis)
|
||||||
|
- [Publish SharePoint Framework applications to the Marketplace](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/publish-to-marketplace-overview)
|
||||||
|
- [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) - Guidance, tooling, samples and open-source controls for your Microsoft 365 development
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||||
|
"version": "2.0",
|
||||||
|
"bundles": {
|
||||||
|
"password-vault-web-part": {
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"entrypoint": "./lib/webparts/passwordVault/PasswordVaultWebPart.js",
|
||||||
|
"manifest": "./src/webparts/passwordVault/PasswordVaultWebPart.manifest.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"externals": {},
|
||||||
|
"localizedResources": {
|
||||||
|
"PasswordVaultWebPartStrings": "lib/webparts/passwordVault/loc/{locale}.js",
|
||||||
|
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
|
||||||
|
"deployCdnPath": "./release/assets/"
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
|
||||||
|
"workingDir": "./release/assets/",
|
||||||
|
"account": "<!-- STORAGE ACCOUNT NAME -->",
|
||||||
|
"container": "sp-fx-app-dev-simple-password-vault",
|
||||||
|
"accessKey": "<!-- ACCESS KEY -->"
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||||
|
"solution": {
|
||||||
|
"name": "sp-fx-app-dev-simple-password-vault-client-side-solution",
|
||||||
|
"id": "d091b369-f63d-459c-846e-5a4323e31745",
|
||||||
|
"version": "1.0.0.0",
|
||||||
|
"includeClientSideAssets": true,
|
||||||
|
"isDomainIsolated": false,
|
||||||
|
"developer": {
|
||||||
|
"name": "",
|
||||||
|
"websiteUrl": "",
|
||||||
|
"privacyUrl": "",
|
||||||
|
"termsOfUseUrl": "",
|
||||||
|
"mpnId": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"paths": {
|
||||||
|
"zippedPackage": "solution/sp-fx-app-dev-simple-password-vault.sppkg"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
|
||||||
|
"port": 4321,
|
||||||
|
"https": true,
|
||||||
|
"initialPage": "https://localhost:5432/workbench",
|
||||||
|
"api": {
|
||||||
|
"port": 5432,
|
||||||
|
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||||
|
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://raw.githubusercontent.com/s-KaiNet/spfx-fast-serve/master/schema/config.latest.schema.json",
|
||||||
|
"cli": {
|
||||||
|
"isLibraryComponent": false
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* User webpack settings file. You can add your own settings here.
|
||||||
|
* Changes from this file will be merged into the base webpack configuration file.
|
||||||
|
* This file will not be overwritten by the subsequent spfx-fast-serve calls.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// you can add your project related webpack configuration here, it will be merged using webpack-merge module
|
||||||
|
// i.e. plugins: [new webpack.Plugin()]
|
||||||
|
const webpackConfig = {
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
"@webparts": path.resolve(__dirname, "..", "src/webparts"),
|
||||||
|
"@src": path.resolve(__dirname, "..", "src"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// for even more fine-grained control, you can apply custom webpack settings using below function
|
||||||
|
const transformConfig = function (initialWebpackConfig) {
|
||||||
|
// transform the initial webpack config here, i.e.
|
||||||
|
// initialWebpackConfig.plugins.push(new webpack.Plugin()); etc.
|
||||||
|
|
||||||
|
return initialWebpackConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
webpackConfig,
|
||||||
|
transformConfig
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const build = require('@microsoft/sp-build-web');
|
||||||
|
|
||||||
|
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
|
||||||
|
build.addSuppression(/Warning - \[sass\] The local CSS class/gi);
|
||||||
|
|
||||||
|
var getTasks = build.rig.getTasks;
|
||||||
|
build.rig.getTasks = function () {
|
||||||
|
var result = getTasks.call(build.rig);
|
||||||
|
|
||||||
|
result.set('serve', result.get('serve-deprecated'));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* fast-serve */
|
||||||
|
const { addFastServe } = require("spfx-fast-serve-helpers");
|
||||||
|
addFastServe(build);
|
||||||
|
/* end of fast-serve */
|
||||||
|
|
||||||
|
/* CUSTOM ALIAS */
|
||||||
|
const path = require('path');
|
||||||
|
build.configureWebpack.mergeConfig({
|
||||||
|
additionalConfiguration: (generatedConfiguration) => {
|
||||||
|
if(!generatedConfiguration.resolve.alias){
|
||||||
|
generatedConfiguration.resolve.alias = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// webparts folder
|
||||||
|
generatedConfiguration.resolve.alias['@webparts'] = path.resolve( __dirname, 'lib/webparts')
|
||||||
|
|
||||||
|
//root src folder
|
||||||
|
generatedConfiguration.resolve.alias['@src'] = path.resolve( __dirname, 'lib')
|
||||||
|
|
||||||
|
return generatedConfiguration;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* CUSTOM ALIAS END */
|
||||||
|
|
||||||
|
build.initialize(require('gulp'));
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
"name": "sp-fx-app-dev-simple-password-vault",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"private": true,
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "gulp bundle",
|
||||||
|
"clean": "gulp clean",
|
||||||
|
"test": "gulp test",
|
||||||
|
"serve": "gulp bundle --custom-serve --max_old_space_size=4096 && fast-serve"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@microsoft/sp-core-library": "1.12.1",
|
||||||
|
"@microsoft/sp-lodash-subset": "1.12.1",
|
||||||
|
"@microsoft/sp-office-ui-fabric-core": "1.12.1",
|
||||||
|
"@microsoft/sp-property-pane": "1.12.1",
|
||||||
|
"@microsoft/sp-webpart-base": "1.12.1",
|
||||||
|
"@pnp/spfx-controls-react": "2.9.0",
|
||||||
|
"@spfxappdev/framework": "^1.0.7",
|
||||||
|
"@types/crypto-js": "^4.1.1",
|
||||||
|
"crypto-js": "^4.1.1",
|
||||||
|
"office-ui-fabric-react": "7.156.0",
|
||||||
|
"react": "16.9.0",
|
||||||
|
"react-dom": "16.9.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@microsoft/decorators": "^1.14.0",
|
||||||
|
"@microsoft/rush-stack-compiler-3.7": "0.2.3",
|
||||||
|
"@microsoft/sp-application-base": "^1.14.0",
|
||||||
|
"@microsoft/sp-build-web": "1.12.1",
|
||||||
|
"@microsoft/sp-module-interfaces": "1.12.1",
|
||||||
|
"@microsoft/sp-tslint-rules": "1.12.1",
|
||||||
|
"@microsoft/sp-webpart-workbench": "1.12.1",
|
||||||
|
"@types/react": "16.9.36",
|
||||||
|
"@types/react-dom": "16.9.8",
|
||||||
|
"@types/webpack-env": "1.13.1",
|
||||||
|
"ajv": "~5.2.2",
|
||||||
|
"gulp": "~4.0.2",
|
||||||
|
"spfx-fast-serve-helpers": "~1.12.0"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,6 @@
|
||||||
|
export interface IVaultData {
|
||||||
|
masterPW: string;
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
note: string;
|
||||||
|
}
|
|
@ -0,0 +1,184 @@
|
||||||
|
import * as CryptoJS from 'crypto-js';
|
||||||
|
import { isNullOrEmpty, toBoolean } from '@spfxappdev/utility';
|
||||||
|
import { SessionStorage } from '@spfxappdev/storage';
|
||||||
|
import { IVaultData } from '@src/interfaces/IVaultData';
|
||||||
|
|
||||||
|
|
||||||
|
export interface IPasswordVaultService {
|
||||||
|
// encryptPassword(password: string): string;
|
||||||
|
// decryptPassword(encryptedPassword: string): string;
|
||||||
|
// encryptUsername(username: string): string;
|
||||||
|
// decryptUsername(encryptedUsername: string): string;
|
||||||
|
// encryptDescription(description: string): string;
|
||||||
|
// decryptDescription(encryptedDescription: string): string;
|
||||||
|
encryptData(plainData: IVaultData): IVaultData;
|
||||||
|
decryptData(encryptedData: IVaultData): IVaultData;
|
||||||
|
open(masterPW: string, encryptedMasterPW: string): boolean;
|
||||||
|
isOpen(): boolean;
|
||||||
|
close(): void;
|
||||||
|
setMasterPassword(plainPassword: string): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export class PasswordVaultService implements IPasswordVaultService {
|
||||||
|
|
||||||
|
private cache: SessionStorage = null;
|
||||||
|
|
||||||
|
private secretKey: string = "SPFxAppDevSecret";
|
||||||
|
|
||||||
|
private instanceId: string = "";
|
||||||
|
|
||||||
|
private encryptedInstanceId: string = "";
|
||||||
|
|
||||||
|
private secretWasSet: boolean = false;
|
||||||
|
|
||||||
|
private isVaultOpen: boolean = false;
|
||||||
|
|
||||||
|
private plainMasterPW: string = "";
|
||||||
|
|
||||||
|
private hashedMasterPw: string = "";
|
||||||
|
|
||||||
|
private get masterSecretKey(): string {
|
||||||
|
return `${this.secretKey}_M@5t€r`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private get userNameSecretKey(): string {
|
||||||
|
return `${this.secretKey}_U5€r_${this.plainMasterPW}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private get passwordSecretKey(): string {
|
||||||
|
return `${this.secretKey}_P@5Sw0Rd_${this.plainMasterPW}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private get noteSecretKey(): string {
|
||||||
|
return `${this.secretKey}_n0t3_${this.plainMasterPW}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(instanceId: string) {
|
||||||
|
|
||||||
|
this.instanceId = instanceId;
|
||||||
|
this.encryptedInstanceId = this.encrypt(instanceId, instanceId);
|
||||||
|
this.setSecret(`SPFxAppDevSecret_${instanceId}`);
|
||||||
|
|
||||||
|
this.cache = new SessionStorage(
|
||||||
|
{
|
||||||
|
...SessionStorage.DefaultSettings,
|
||||||
|
...{
|
||||||
|
DefaultTimeToLife: 5
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.isVaultOpen = toBoolean(this.cache.get(this.encryptedInstanceId));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public encryptData(plainData: Omit<IVaultData, "masterPW">): IVaultData {
|
||||||
|
return {
|
||||||
|
masterPW: this.hashedMasterPw,
|
||||||
|
username: this.encryptUsername(plainData.username),
|
||||||
|
password: this.encryptPassword(plainData.password),
|
||||||
|
note: this.encryptNote(plainData.note)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public decryptData(encryptedData: IVaultData): IVaultData {
|
||||||
|
|
||||||
|
if(!this.isVaultOpen) {
|
||||||
|
return {
|
||||||
|
masterPW: "",
|
||||||
|
username: "",
|
||||||
|
password: "",
|
||||||
|
note: ""
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
masterPW: "",
|
||||||
|
username: this.decryptUsername(encryptedData.username),
|
||||||
|
password: this.decryptPassword(encryptedData.password),
|
||||||
|
note: this.decryptNote(encryptedData.note)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public open(masterPW: string, encryptedMasterPW: string): boolean {
|
||||||
|
const masterPWEncrypted = CryptoJS.HmacSHA256(masterPW, this.masterSecretKey);
|
||||||
|
|
||||||
|
if(masterPWEncrypted.toString() == encryptedMasterPW) {
|
||||||
|
this.isVaultOpen = true;
|
||||||
|
// this.cache.set(this.encryptedInstanceId, true);
|
||||||
|
this.plainMasterPW = masterPW;
|
||||||
|
this.hashedMasterPw = masterPWEncrypted.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public isOpen(): boolean {
|
||||||
|
return this.isVaultOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public close(): void {
|
||||||
|
this.isVaultOpen = false;
|
||||||
|
// this.cache.set(this.encryptedInstanceId, false);
|
||||||
|
this.plainMasterPW = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public setMasterPassword(plainPassword: string): string {
|
||||||
|
this.plainMasterPW = plainPassword;
|
||||||
|
this.hashedMasterPw = CryptoJS.HmacSHA256(plainPassword, this.masterSecretKey).toString();
|
||||||
|
return this.hashedMasterPw;
|
||||||
|
}
|
||||||
|
|
||||||
|
private setSecret(secretKey: string): void {
|
||||||
|
if(this.secretWasSet) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.secretWasSet = true;
|
||||||
|
this.secretKey = secretKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
private encrypt(text: string, secret: string): string {
|
||||||
|
if(isNullOrEmpty(text)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CryptoJS.AES.encrypt(text, secret).toString(CryptoJS.format.OpenSSL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private decrypt(encryptedText: string, secret: string): string {
|
||||||
|
if(isNullOrEmpty(encryptedText)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bytes = CryptoJS.AES.decrypt(encryptedText, secret);
|
||||||
|
return bytes.toString(CryptoJS.enc.Utf8);
|
||||||
|
}
|
||||||
|
|
||||||
|
private encryptPassword(password: string): string {
|
||||||
|
return this.encrypt(password, this.passwordSecretKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private decryptPassword(encryptedPassword: string): string {
|
||||||
|
return this.decrypt(encryptedPassword, this.passwordSecretKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private encryptUsername(username: string): string {
|
||||||
|
return this.encrypt(username, this.userNameSecretKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private decryptUsername(encryptedUsername: string): string {
|
||||||
|
return this.decrypt(encryptedUsername, this.userNameSecretKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private encryptNote(note: string): string {
|
||||||
|
return this.encrypt(note, this.noteSecretKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
private decryptNote(encryptedNote: string): string {
|
||||||
|
return this.decrypt(encryptedNote, this.noteSecretKey);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
import {
|
||||||
|
IPropertyPaneField,
|
||||||
|
PropertyPaneFieldType,
|
||||||
|
IPropertyPaneCustomFieldProps
|
||||||
|
} from '@microsoft/sp-property-pane';
|
||||||
|
|
||||||
|
export interface IPropertyPaneAboutWebPartProps {
|
||||||
|
/**
|
||||||
|
* An UNIQUE key indicates the identity of this control
|
||||||
|
*/
|
||||||
|
key: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An UNIQUE key indicates the identity of this control
|
||||||
|
*/
|
||||||
|
html: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IPropertyWebPartInformationPropsInternal extends IPropertyPaneAboutWebPartProps, IPropertyPaneCustomFieldProps {
|
||||||
|
}
|
||||||
|
|
||||||
|
class PropertyPaneAboutWebPartBuilder implements IPropertyPaneField<IPropertyPaneAboutWebPartProps> {
|
||||||
|
//Properties defined by IPropertyPaneField
|
||||||
|
public targetProperty: string;
|
||||||
|
public type: PropertyPaneFieldType = PropertyPaneFieldType.Custom;
|
||||||
|
public properties: IPropertyWebPartInformationPropsInternal;
|
||||||
|
|
||||||
|
private elem: HTMLElement;
|
||||||
|
|
||||||
|
public constructor(_properties: IPropertyPaneAboutWebPartProps) {
|
||||||
|
this.properties = {
|
||||||
|
key: _properties.key,
|
||||||
|
html: _properties.html,
|
||||||
|
onRender: this.onRender.bind(this)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): void {
|
||||||
|
if (!this.elem) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.onRender(this.elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onRender(elem: HTMLElement, ctx?: any, changeCallback?: (targetProperty?: string, newValue?: any) => void): void {
|
||||||
|
if (!this.elem) {
|
||||||
|
this.elem = elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.elem.innerHTML = this.properties.html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PropertyPaneAboutWebPart(properties: IPropertyPaneAboutWebPartProps): IPropertyPaneField<IPropertyPaneAboutWebPartProps> {
|
||||||
|
return new PropertyPaneAboutWebPartBuilder(properties);
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||||
|
"id": "2c2420ee-ffdf-4dce-800f-d0d09f02bffd",
|
||||||
|
"alias": "PasswordVaultWebPart",
|
||||||
|
"componentType": "WebPart",
|
||||||
|
|
||||||
|
// The "*" signifies that the version should be taken from the package.json
|
||||||
|
"version": "*",
|
||||||
|
"manifestVersion": 2,
|
||||||
|
|
||||||
|
// If true, the component can only be installed on sites where Custom Script is allowed.
|
||||||
|
// Components that allow authors to embed arbitrary script code should set this to true.
|
||||||
|
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
|
||||||
|
"requiresCustomScript": false,
|
||||||
|
"supportedHosts": ["SharePointWebPart"],
|
||||||
|
|
||||||
|
"preconfiguredEntries": [{
|
||||||
|
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
|
||||||
|
"group": { "default": "Other" },
|
||||||
|
"title": { "default": "PasswordVault" },
|
||||||
|
"description": { "default": "PasswordVault description" },
|
||||||
|
"officeFabricIconFontName": "ProtectRestrict",
|
||||||
|
"properties": {
|
||||||
|
"masterPW": "",
|
||||||
|
"username": "",
|
||||||
|
"password": "",
|
||||||
|
"note": ""
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
|
@ -0,0 +1,112 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as ReactDom from 'react-dom';
|
||||||
|
import { Version } from '@microsoft/sp-core-library';
|
||||||
|
import { IPropertyPaneConfiguration } from '@microsoft/sp-property-pane';
|
||||||
|
import { ISPFxAppDevClientSideWebPartProps, SPFxAppDevClientSideWebPart } from '@spfxappdev/framework';
|
||||||
|
import PasswordVault, { IPasswordVaultProps } from './components/PasswordVault';
|
||||||
|
import { PasswordVaultService, IPasswordVaultService } from '@src/services/PasswordVaultService';
|
||||||
|
import { IVaultData } from '@src/interfaces/IVaultData';
|
||||||
|
import { PropertyPaneAboutWebPart } from '../PropertyPaneAboutWebPart';
|
||||||
|
import * as strings from 'PasswordVaultWebPartStrings';
|
||||||
|
|
||||||
|
export interface IPasswordVaultWebPartProps extends ISPFxAppDevClientSideWebPartProps, IVaultData {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default class PasswordVaultWebPart extends SPFxAppDevClientSideWebPart<IPasswordVaultWebPartProps> {
|
||||||
|
|
||||||
|
private passwordVaultService: IPasswordVaultService = null;
|
||||||
|
|
||||||
|
public onInit(): Promise<void> {
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
super.onInit().then(() => {
|
||||||
|
this.passwordVaultService = new PasswordVaultService(this.context.instanceId);
|
||||||
|
return resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): void {
|
||||||
|
|
||||||
|
this.log(this.properties);
|
||||||
|
const element: React.ReactElement<IPasswordVaultProps> = React.createElement(
|
||||||
|
PasswordVault,
|
||||||
|
{
|
||||||
|
WebPart: this,
|
||||||
|
Title: this.properties.Title,
|
||||||
|
passwordVaultService: this.passwordVaultService,
|
||||||
|
masterPW: this.properties.masterPW,
|
||||||
|
username: this.properties.username,
|
||||||
|
password: this.properties.password,
|
||||||
|
note: this.properties.note,
|
||||||
|
onTitleChanged: (title: string): void => {
|
||||||
|
this.onTitleChanged(title);
|
||||||
|
},
|
||||||
|
onVaultDataChanged: (vaultData: IVaultData): void => {
|
||||||
|
this.onVaultDataChanged(vaultData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
ReactDom.render(element, this.domElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getLogCategory(): string {
|
||||||
|
return 'PasswordVaultWebPart';
|
||||||
|
}
|
||||||
|
|
||||||
|
public onTitleChanged(title: string): void {
|
||||||
|
this.properties.Title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public onVaultDataChanged(vaultData: IVaultData): void {
|
||||||
|
this.properties.masterPW = vaultData.masterPW;
|
||||||
|
this.properties.note = vaultData.note;
|
||||||
|
this.properties.password = vaultData.password;
|
||||||
|
this.properties.username = vaultData.username;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onDispose(): void {
|
||||||
|
ReactDom.unmountComponentAtNode(this.domElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected get dataVersion(): Version {
|
||||||
|
return Version.parse('1.0');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
|
||||||
|
return {
|
||||||
|
pages: [
|
||||||
|
{
|
||||||
|
header: {
|
||||||
|
description: ''
|
||||||
|
},
|
||||||
|
groups: [
|
||||||
|
{
|
||||||
|
groupName: strings.WebPartPropertyGroupAbout,
|
||||||
|
groupFields: [
|
||||||
|
PropertyPaneAboutWebPart({
|
||||||
|
key: `bbc94d63-5630-4077-b6a8-6b8d37551766_${this.context.instanceId}`,
|
||||||
|
html: `
|
||||||
|
<div>
|
||||||
|
<h3>Author</h3>
|
||||||
|
<a href="https://spfx-app.dev/" data-interception="off" target="_blank">SPFx-App.dev</a>
|
||||||
|
<h3>Version</h3>
|
||||||
|
${this.context.manifest.version}
|
||||||
|
<h3>Web Part Instance id</h3>
|
||||||
|
${this.context.instanceId}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<a href="https://github.com/SPFxAppDev/sp-rte-webpart" target="_blank">More info</a>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,132 @@
|
||||||
|
//@import '~office-ui-fabric-react/dist/sass/References.scss';
|
||||||
|
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
|
||||||
|
|
||||||
|
.passwordVault {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global {
|
||||||
|
|
||||||
|
.spfxappdev-grid {
|
||||||
|
box-sizing: border-box;
|
||||||
|
zoom: 1;
|
||||||
|
padding: 0 8px;
|
||||||
|
|
||||||
|
&::before,
|
||||||
|
&::after {
|
||||||
|
display: table;
|
||||||
|
content: '';
|
||||||
|
line-height: 0;
|
||||||
|
-webkit-box-sizing: inherit;
|
||||||
|
box-sizing: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
clear: both;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-row {
|
||||||
|
margin: 0 -8px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
zoom: 1;
|
||||||
|
|
||||||
|
&::before,
|
||||||
|
&::after {
|
||||||
|
display: table;
|
||||||
|
content: '';
|
||||||
|
line-height: 0;
|
||||||
|
-webkit-box-sizing: inherit;
|
||||||
|
box-sizing: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
clear: both;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
&-col {
|
||||||
|
position: relative;
|
||||||
|
min-height: 1px;
|
||||||
|
// padding-left: 8px;
|
||||||
|
// padding-right: 8px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-sm1 {
|
||||||
|
width: 8.33%
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-sm2 {
|
||||||
|
width: 16.66%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-sm3 {
|
||||||
|
width: 25%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-sm4 {
|
||||||
|
width: 33.33%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-sm5 {
|
||||||
|
width: 41.66%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-sm6 {
|
||||||
|
width: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-sm7 {
|
||||||
|
width: 58.33%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-sm8 {
|
||||||
|
width: 66.66%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-sm9 {
|
||||||
|
width:75%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-sm10 {
|
||||||
|
width: 83.33%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-sm11 {
|
||||||
|
width: 91.66%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-sm12 {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-grid-col .ms-TextField-suffix {
|
||||||
|
cursor: pointer;
|
||||||
|
background-color: #fff;
|
||||||
|
color: $ms-color-themePrimary;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: $ms-color-neutralLighter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-grid-col .ms-TextField-reveal.ms-Button {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spfxappdev-grid-col .quill {
|
||||||
|
border: solid 1px #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-footer {
|
||||||
|
margin-top: 10px;
|
||||||
|
|
||||||
|
button {
|
||||||
|
margin-right: 15px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,391 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import styles from './PasswordVault.module.scss';
|
||||||
|
import { SPFxAppDevWebPartComponent, ISPFxAppDevWebPartComponentProps } from '@spfxappdev/framework';
|
||||||
|
import PasswordVaultWebPart from '../PasswordVaultWebPart';
|
||||||
|
import { IPasswordVaultService } from '@src/services/PasswordVaultService';
|
||||||
|
import { DefaultButton, Icon, Label, MessageBar, MessageBarType, PrimaryButton, TextField } from 'office-ui-fabric-react';
|
||||||
|
import { WebPartTitle } from "@pnp/spfx-controls-react/lib/WebPartTitle";
|
||||||
|
import { RichText } from "@pnp/spfx-controls-react/lib/RichText";
|
||||||
|
import { IVaultData } from '@src/interfaces/IVaultData';
|
||||||
|
import * as strings from 'PasswordVaultWebPartStrings';
|
||||||
|
|
||||||
|
interface IPasswordVaultState {
|
||||||
|
isVaultOpen: boolean;
|
||||||
|
showWrongMasterInfo: boolean;
|
||||||
|
isSaveButtonDisabled: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IPasswordVaultProps extends ISPFxAppDevWebPartComponentProps<PasswordVaultWebPart> {
|
||||||
|
passwordVaultService: IPasswordVaultService;
|
||||||
|
masterPW?: string;
|
||||||
|
username?: string;
|
||||||
|
password?: string;
|
||||||
|
note?: string;
|
||||||
|
onTitleChanged?(value: string): void;
|
||||||
|
onVaultDataChanged?(vaultData: IVaultData): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class PasswordVault extends SPFxAppDevWebPartComponent<PasswordVaultWebPart, IPasswordVaultProps, IPasswordVaultState> {
|
||||||
|
|
||||||
|
public static defaultProps: IPasswordVaultProps = {
|
||||||
|
Title: "",
|
||||||
|
WebPart: null,
|
||||||
|
passwordVaultService: null
|
||||||
|
};
|
||||||
|
|
||||||
|
public state: IPasswordVaultState = {
|
||||||
|
isVaultOpen: this.isVaultOpen,
|
||||||
|
showWrongMasterInfo: false,
|
||||||
|
isSaveButtonDisabled: this.helper.functions.isNullOrEmpty(this.props.masterPW)
|
||||||
|
};
|
||||||
|
|
||||||
|
private get isVaultOpen(): boolean {
|
||||||
|
|
||||||
|
let showForm: boolean = false;
|
||||||
|
|
||||||
|
if(this.WebPart.IsPageInEditMode) {
|
||||||
|
showForm = this.helper.functions.isNullOrEmpty(this.props.masterPW);
|
||||||
|
}
|
||||||
|
|
||||||
|
return showForm ||
|
||||||
|
(!this.helper.functions.isNullOrEmpty(this.props.masterPW) &&
|
||||||
|
this.props.passwordVaultService.isOpen());
|
||||||
|
}
|
||||||
|
|
||||||
|
private enteredMasterPW: string = "";
|
||||||
|
|
||||||
|
private encryptedData: IVaultData = null;
|
||||||
|
|
||||||
|
private decryptedData: IVaultData = null;
|
||||||
|
|
||||||
|
private isNewVault: boolean = true;
|
||||||
|
|
||||||
|
private editModeNote: string;
|
||||||
|
|
||||||
|
private editModePw: string;
|
||||||
|
|
||||||
|
private editModeUsername: string;
|
||||||
|
|
||||||
|
constructor(props: IPasswordVaultProps) {
|
||||||
|
super(props);
|
||||||
|
this.encryptedData = {
|
||||||
|
masterPW: props.masterPW,
|
||||||
|
username: props.username,
|
||||||
|
password: props.password,
|
||||||
|
note: props.note
|
||||||
|
};
|
||||||
|
|
||||||
|
this.decryptedData = this.props.passwordVaultService.decryptData(this.encryptedData);
|
||||||
|
this.isNewVault = this.helper.functions.isNullOrEmpty(props.masterPW);
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): React.ReactElement<IPasswordVaultProps> {
|
||||||
|
return (
|
||||||
|
<div className={styles.passwordVault}>
|
||||||
|
<WebPartTitle displayMode={this.WebPart.displayMode}
|
||||||
|
title={this.props.Title}
|
||||||
|
updateProperty={(title: string) => {
|
||||||
|
if(this.helper.functions.isFunction(this.props.onTitleChanged)) {
|
||||||
|
this.props.onTitleChanged(title);
|
||||||
|
}
|
||||||
|
}} />
|
||||||
|
{this.props.WebPart.IsPageInEditMode &&
|
||||||
|
this.renderEditMode()}
|
||||||
|
|
||||||
|
{!this.props.WebPart.IsPageInEditMode &&
|
||||||
|
this.renderDisplayMode()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private renderDisplayMode(): JSX.Element {
|
||||||
|
const props: IPasswordVaultProps = this.props;
|
||||||
|
const showCopyToClipboard: boolean = this.helper.functions.issetDeep(window, "navigator.clipboard.writeText");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{this.helper.functions.isNullOrEmpty(props.masterPW) &&
|
||||||
|
<MessageBar messageBarType={MessageBarType.info}>
|
||||||
|
{strings.NoMasterPasswordSetLabel}
|
||||||
|
</MessageBar>
|
||||||
|
}
|
||||||
|
|
||||||
|
{this.renderOpenVaultForm()}
|
||||||
|
|
||||||
|
{this.state.isVaultOpen &&
|
||||||
|
<div className='spfxappdev-grid'>
|
||||||
|
{!this.helper.functions.isNullOrEmpty(this.decryptedData.username) &&
|
||||||
|
<div className="spfxappdev-grid-row">
|
||||||
|
<div className="spfxappdev-grid-col spfxappdev-sm12">
|
||||||
|
<TextField
|
||||||
|
label={strings.UsernameLabel}
|
||||||
|
disabled={true}
|
||||||
|
defaultValue={this.decryptedData.username}
|
||||||
|
onRenderSuffix={() => {
|
||||||
|
|
||||||
|
if(!showCopyToClipboard) {
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Icon iconName={"Copy"} className="copy-icon" onClick={() => { this.copyToClipboard(this.decryptedData.username); }} />
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
{!this.helper.functions.isNullOrEmpty(this.decryptedData.password) &&
|
||||||
|
<div className="spfxappdev-grid-row">
|
||||||
|
<div className="spfxappdev-grid-col spfxappdev-sm12">
|
||||||
|
<TextField
|
||||||
|
label={strings.PasswordLabel}
|
||||||
|
type="password"
|
||||||
|
disabled={true}
|
||||||
|
canRevealPassword={true}
|
||||||
|
defaultValue={this.decryptedData.password}
|
||||||
|
onRenderSuffix={() => {
|
||||||
|
|
||||||
|
if(!showCopyToClipboard) {
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Icon iconName={"Copy"} className="copy-icon" onClick={() => { this.copyToClipboard(this.decryptedData.password); }} />
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
{!this.helper.functions.isNullOrEmpty(this.decryptedData.note) &&
|
||||||
|
<>
|
||||||
|
<Label>{strings.NoteLabel}</Label>
|
||||||
|
<RichText
|
||||||
|
isEditMode={false}
|
||||||
|
value={this.decryptedData.note}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
|
||||||
|
<div className="spfxappdev-grid-row grid-footer">
|
||||||
|
<div className="spfxappdev-grid-col spfxappdev-sm12">
|
||||||
|
{!this.helper.functions.isNullOrEmpty(this.props.masterPW) &&
|
||||||
|
<DefaultButton onClick={() => {
|
||||||
|
this.closeVault();
|
||||||
|
}}>
|
||||||
|
{strings.CloseVaultLabel}
|
||||||
|
</DefaultButton>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private renderEditMode(): JSX.Element {
|
||||||
|
const wp: PasswordVaultWebPart = this.WebPart;
|
||||||
|
|
||||||
|
const showForm: boolean = this.state.isVaultOpen;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{this.renderOpenVaultForm()}
|
||||||
|
|
||||||
|
{showForm &&
|
||||||
|
<div className='spfxappdev-grid'>
|
||||||
|
<div className="spfxappdev-grid-row">
|
||||||
|
<div className="spfxappdev-grid-col spfxappdev-sm12">
|
||||||
|
<TextField
|
||||||
|
label={this.isNewVault ? strings.SetMasterPasswordLabel : strings.ChangeMasterPasswordLabel}
|
||||||
|
type="password"
|
||||||
|
required={this.isNewVault}
|
||||||
|
canRevealPassword={true}
|
||||||
|
onChange={(ev: any, newValue: string) => {
|
||||||
|
this.enteredMasterPW = newValue;
|
||||||
|
this.setState({
|
||||||
|
isSaveButtonDisabled: this.isSaveButtonDisabled()
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="spfxappdev-grid-row">
|
||||||
|
<div className="spfxappdev-grid-col spfxappdev-sm12">
|
||||||
|
<TextField
|
||||||
|
label={strings.UsernameLabel}
|
||||||
|
type="text"
|
||||||
|
onChange={(ev: any, newValue: string) => {
|
||||||
|
this.editModeUsername = newValue;
|
||||||
|
this.setState({
|
||||||
|
isSaveButtonDisabled: this.isSaveButtonDisabled()
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
defaultValue={this.decryptedData.username}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="spfxappdev-grid-row">
|
||||||
|
<div className="spfxappdev-grid-col spfxappdev-sm12">
|
||||||
|
<TextField
|
||||||
|
label={strings.PasswordLabel}
|
||||||
|
type="password"
|
||||||
|
canRevealPassword={true}
|
||||||
|
onChange={(ev: any, newValue: string) => {
|
||||||
|
this.editModePw = newValue;
|
||||||
|
this.setState({
|
||||||
|
isSaveButtonDisabled: this.isSaveButtonDisabled()
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
defaultValue={this.decryptedData.password}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="spfxappdev-grid-row">
|
||||||
|
<div className="spfxappdev-grid-col spfxappdev-sm12">
|
||||||
|
<Label>{strings.NoteLabel}</Label>
|
||||||
|
<RichText
|
||||||
|
isEditMode={wp.IsPageInEditMode}
|
||||||
|
value={this.decryptedData.note}
|
||||||
|
onChange={(note: string): string => {
|
||||||
|
this.editModeNote = note;
|
||||||
|
this.decryptedData.note = note;
|
||||||
|
this.setState({
|
||||||
|
isSaveButtonDisabled: this.isSaveButtonDisabled()
|
||||||
|
});
|
||||||
|
|
||||||
|
return note;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div className="spfxappdev-grid-row grid-footer">
|
||||||
|
<div className="spfxappdev-grid-col spfxappdev-sm12">
|
||||||
|
<PrimaryButton disabled={this.state.isSaveButtonDisabled} onClick={() => {
|
||||||
|
this.isNewVault = false;
|
||||||
|
let encryptedMaster = this.props.masterPW;
|
||||||
|
if(!this.enteredMasterPW.IsEmpty()) {
|
||||||
|
encryptedMaster = this.props.passwordVaultService.setMasterPassword(this.enteredMasterPW);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.encryptedData = this.props.passwordVaultService.encryptData({
|
||||||
|
masterPW: encryptedMaster,
|
||||||
|
note: this.editModeNote,
|
||||||
|
password: this.editModePw,
|
||||||
|
username: this.editModeUsername
|
||||||
|
});
|
||||||
|
|
||||||
|
this.decryptedData = this.props.passwordVaultService.decryptData(this.encryptedData);
|
||||||
|
|
||||||
|
this.props.onVaultDataChanged(this.encryptedData);
|
||||||
|
|
||||||
|
}}>
|
||||||
|
{strings.SaveLabel}
|
||||||
|
</PrimaryButton>
|
||||||
|
|
||||||
|
{!this.helper.functions.isNullOrEmpty(this.props.masterPW) &&
|
||||||
|
<DefaultButton onClick={() => {
|
||||||
|
this.closeVault();
|
||||||
|
}}>
|
||||||
|
{strings.CloseVaultLabel}
|
||||||
|
</DefaultButton>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private renderOpenVaultForm(): JSX.Element {
|
||||||
|
|
||||||
|
if(this.helper.functions.isNullOrEmpty(this.props.masterPW)) {
|
||||||
|
return (<></>);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (<>
|
||||||
|
{!this.state.isVaultOpen &&
|
||||||
|
<>
|
||||||
|
|
||||||
|
{this.state.showWrongMasterInfo &&
|
||||||
|
<MessageBar messageBarType={MessageBarType.error}>
|
||||||
|
{strings.WrongPasswordLabel}
|
||||||
|
</MessageBar>
|
||||||
|
}
|
||||||
|
<div className='spfxappdev-grid'>
|
||||||
|
<div className="spfxappdev-grid-row">
|
||||||
|
<div className="spfxappdev-grid-col spfxappdev-sm12">
|
||||||
|
<TextField
|
||||||
|
label={strings.MasterPasswordLabel}
|
||||||
|
type="password"
|
||||||
|
canRevealPassword={true}
|
||||||
|
onChange={(ev: any, newValue: string) => {
|
||||||
|
this.enteredMasterPW = newValue;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="spfxappdev-grid-row grid-footer">
|
||||||
|
<div className="spfxappdev-grid-col spfxappdev-sm12">
|
||||||
|
<PrimaryButton onClick={() => {
|
||||||
|
|
||||||
|
this.onOpenVault();
|
||||||
|
|
||||||
|
}}>
|
||||||
|
{strings.OpenVaultLabel}
|
||||||
|
</PrimaryButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
</>);
|
||||||
|
}
|
||||||
|
|
||||||
|
private isSaveButtonDisabled(): boolean {
|
||||||
|
if(this.isNewVault && this.helper.functions.isNullOrEmpty(this.enteredMasterPW)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private closeVault(): void {
|
||||||
|
this.props.passwordVaultService.close();
|
||||||
|
this.setState({
|
||||||
|
isVaultOpen: false,
|
||||||
|
showWrongMasterInfo: false
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private onOpenVault(): void {
|
||||||
|
const props: IPasswordVaultProps = this.props;
|
||||||
|
const isCorrectPW = props.passwordVaultService.open(this.enteredMasterPW, props.masterPW);
|
||||||
|
this.enteredMasterPW = "";
|
||||||
|
|
||||||
|
if(isCorrectPW) {
|
||||||
|
this.decryptedData = props.passwordVaultService.decryptData(this.encryptedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.editModeNote = this.decryptedData.note;
|
||||||
|
this.editModePw = this.decryptedData.password;
|
||||||
|
this.editModeUsername = this.decryptedData.username;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
isVaultOpen: isCorrectPW,
|
||||||
|
showWrongMasterInfo: !isCorrectPW
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private copyToClipboard(text: string): void {
|
||||||
|
window.navigator.clipboard.writeText(text);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
define([], function() {
|
||||||
|
return {
|
||||||
|
"WebPartPropertyGroupAbout": "Über das Webpart",
|
||||||
|
"NoMasterPasswordSetLabel": "Es wurde noch kein Master Passwort hinterlegt. Bitte hinterlegen Sie ein Masterpasswort.",
|
||||||
|
"PasswordLabel": "Passwort",
|
||||||
|
"MasterPasswordLabel": "Master Passwort",
|
||||||
|
"SetMasterPasswordLabel": "Master Passwort",
|
||||||
|
"ChangeMasterPasswordLabel": "Master Passwort ändern",
|
||||||
|
"UsernameLabel": "Benutezrname",
|
||||||
|
"NoteLabel": "Notiz",
|
||||||
|
"CloseVaultLabel": "Tresor schließen",
|
||||||
|
"SaveLabel": "Speichern",
|
||||||
|
"WrongPasswordLabel": "Falsches Passwort",
|
||||||
|
"OpenVaultLabel": "Tresor entsperren",
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,16 @@
|
||||||
|
define([], function() {
|
||||||
|
return {
|
||||||
|
"WebPartPropertyGroupAbout": "About",
|
||||||
|
"NoMasterPasswordSetLabel": "No master password has been stored yet. Please store a master password.",
|
||||||
|
"PasswordLabel": "Password",
|
||||||
|
"MasterPasswordLabel": "Master Password",
|
||||||
|
"SetMasterPasswordLabel": "Master Password",
|
||||||
|
"ChangeMasterPasswordLabel": "Change Master Password",
|
||||||
|
"UsernameLabel": "Username",
|
||||||
|
"NoteLabel": "Note",
|
||||||
|
"CloseVaultLabel": "Close vault",
|
||||||
|
"SaveLabel": "Save",
|
||||||
|
"WrongPasswordLabel": "Wrong Password",
|
||||||
|
"OpenVaultLabel": "Open vault",
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,19 @@
|
||||||
|
declare interface IPasswordVaultWebPartStrings {
|
||||||
|
WebPartPropertyGroupAbout: string;
|
||||||
|
NoMasterPasswordSetLabel: string;
|
||||||
|
PasswordLabel: string;
|
||||||
|
MasterPasswordLabel: string;
|
||||||
|
SetMasterPasswordLabel: string;
|
||||||
|
ChangeMasterPasswordLabel: string;
|
||||||
|
UsernameLabel: string;
|
||||||
|
NoteLabel: string;
|
||||||
|
CloseVaultLabel: string;
|
||||||
|
SaveLabel: string;
|
||||||
|
WrongPasswordLabel: string;
|
||||||
|
OpenVaultLabel: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'PasswordVaultWebPartStrings' {
|
||||||
|
const strings: IPasswordVaultWebPartStrings;
|
||||||
|
export = strings;
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 383 B |
|
@ -0,0 +1,40 @@
|
||||||
|
{
|
||||||
|
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.7/includes/tsconfig-web.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es5",
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"jsx": "react",
|
||||||
|
"declaration": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"outDir": "lib",
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@src/*": ["src/*"],
|
||||||
|
"@webparts/*": ["src/webparts/*"]
|
||||||
|
},
|
||||||
|
"inlineSources": false,
|
||||||
|
"strictNullChecks": false,
|
||||||
|
"noUnusedLocals": false,
|
||||||
|
"typeRoots": [
|
||||||
|
"./node_modules/@types",
|
||||||
|
"./node_modules/@microsoft"
|
||||||
|
],
|
||||||
|
"types": [
|
||||||
|
"webpack-env"
|
||||||
|
],
|
||||||
|
"lib": [
|
||||||
|
"es5",
|
||||||
|
"dom",
|
||||||
|
"es2015.collection",
|
||||||
|
"es2015.promise"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*.ts",
|
||||||
|
"src/**/*.tsx"
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"extends": "./node_modules/@microsoft/sp-tslint-rules/base-tslint.json",
|
||||||
|
"rules": {
|
||||||
|
"class-name": false,
|
||||||
|
"export-name": false,
|
||||||
|
"forin": false,
|
||||||
|
"label-position": false,
|
||||||
|
"member-access": true,
|
||||||
|
"no-arg": false,
|
||||||
|
"no-console": false,
|
||||||
|
"no-construct": false,
|
||||||
|
"no-duplicate-variable": true,
|
||||||
|
"no-eval": false,
|
||||||
|
"no-function-expression": true,
|
||||||
|
"no-internal-module": true,
|
||||||
|
"no-shadowed-variable": true,
|
||||||
|
"no-switch-case-fall-through": true,
|
||||||
|
"no-unnecessary-semicolons": true,
|
||||||
|
"no-unused-expression": true,
|
||||||
|
"no-use-before-declare": true,
|
||||||
|
"no-with-statement": true,
|
||||||
|
"semicolon": true,
|
||||||
|
"trailing-comma": false,
|
||||||
|
"typedef": false,
|
||||||
|
"typedef-whitespace": false,
|
||||||
|
"use-named-parameter": true,
|
||||||
|
"variable-name": false,
|
||||||
|
"whitespace": false
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue