aboutsummaryrefslogtreecommitdiff
path: root/src/server/authentication
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/authentication')
-rw-r--r--src/server/authentication/config/passport.ts21
-rw-r--r--src/server/authentication/models/current_user_utils.ts31
-rw-r--r--src/server/authentication/models/user_model.ts4
3 files changed, 32 insertions, 24 deletions
diff --git a/src/server/authentication/config/passport.ts b/src/server/authentication/config/passport.ts
index 0ced99b0d..286209b20 100644
--- a/src/server/authentication/config/passport.ts
+++ b/src/server/authentication/config/passport.ts
@@ -1,8 +1,6 @@
import * as passport from 'passport';
import * as passportLocal from 'passport-local';
-import _ from "lodash";
import { default as User } from '../models/user_model';
-import { Request, Response, NextFunction } from "express";
const LocalStrategy = passportLocal.Strategy;
@@ -28,21 +26,4 @@ passport.use(new LocalStrategy({ usernameField: 'email', passReqToCallback: true
return done(undefined, user);
});
});
-}));
-
-export let isAuthenticated = (req: Request, res: Response, next: NextFunction) => {
- if (req.isAuthenticated()) {
- return next();
- }
- return res.redirect("/login");
-};
-
-export let isAuthorized = (req: Request, res: Response, next: NextFunction) => {
- const provider = req.path.split("/").slice(-1)[0];
-
- if (_.find(req.user && "tokens" in req.user ? req.user["tokens"] : undefined, { kind: provider })) {
- next();
- } else {
- res.redirect(`/auth/${provider}`);
- }
-}; \ No newline at end of file
+})); \ No newline at end of file
diff --git a/src/server/authentication/models/current_user_utils.ts b/src/server/authentication/models/current_user_utils.ts
index 50bfb4832..36d4cd2f2 100644
--- a/src/server/authentication/models/current_user_utils.ts
+++ b/src/server/authentication/models/current_user_utils.ts
@@ -9,7 +9,7 @@ import { Doc, DocListCast } from "../../../new_fields/Doc";
import { List } from "../../../new_fields/List";
import { listSpec } from "../../../new_fields/Schema";
import { ScriptField, ComputedField } from "../../../new_fields/ScriptField";
-import { Cast, PromiseValue } from "../../../new_fields/Types";
+import { Cast, PromiseValue, StrCast } from "../../../new_fields/Types";
import { Utils } from "../../../Utils";
import { nullAudio } from "../../../new_fields/URLField";
import { DragManager } from "../../../client/util/DragManager";
@@ -41,12 +41,13 @@ export class CurrentUserUtils {
}
// setup the "creator" buttons for the sidebar-- eg. the default set of draggable document creation tools
- static setupCreatorButtons(doc: Doc) {
+ static setupCreatorButtons(doc: Doc, buttons?: string[]) {
const notes = CurrentUserUtils.setupNoteTypes(doc);
doc.noteTypes = Docs.Create.TreeDocument(notes, { title: "Note Types", height: 75 });
doc.activePen = doc;
const docProtoData: { title: string, icon: string, drag?: string, ignoreClick?: boolean, click?: string, ischecked?: string, activePen?: Doc, backgroundColor?: string, dragFactory?: Doc }[] = [
{ title: "collection", icon: "folder", ignoreClick: true, drag: 'Docs.Create.FreeformDocument([], { nativeWidth: undefined, nativeHeight: undefined, width: 150, height: 100, title: "freeform" })' },
+ { title: "preview", icon: "expand", ignoreClick: true, drag: 'Docs.Create.DocumentDocument(ComputedField.MakeFunction("selectedDocs(this,true,[_last_])?.[0]"), { width: 250, height: 250, title: "container" })' },
{ title: "todo item", icon: "check", ignoreClick: true, drag: 'getCopy(this.dragFactory, true)', dragFactory: notes[notes.length - 1] },
{ title: "web page", icon: "globe-asia", ignoreClick: true, drag: 'Docs.Create.WebDocument("https://en.wikipedia.org/wiki/Hedgehog", { width: 300, height: 300, title: "New Webpage" })' },
{ title: "cat image", icon: "cat", ignoreClick: true, drag: 'Docs.Create.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", { width: 200, title: "an image of a cat" })' },
@@ -60,7 +61,7 @@ export class CurrentUserUtils {
{ title: "use scrubber", icon: "eraser", click: 'activateScrubber(this.activePen.pen = sameDocs(this.activePen.pen, this) ? undefined : this);', ischecked: `sameDocs(this.activePen.pen, this)`, backgroundColor: "green", activePen: doc },
{ title: "use drag", icon: "mouse-pointer", click: 'deactivateInk();this.activePen.pen = this;', ischecked: `sameDocs(this.activePen.pen, this)`, backgroundColor: "white", activePen: doc },
];
- return docProtoData.map(data => Docs.Create.FontIconDocument({
+ return docProtoData.filter(d => !buttons || !buttons.includes(d.title)).map(data => Docs.Create.FontIconDocument({
nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, dropAction: data.click ? "copy" : undefined, title: data.title, icon: data.icon, ignoreClick: data.ignoreClick,
onDragStart: data.drag ? ScriptField.MakeFunction(data.drag) : undefined, onClick: data.click ? ScriptField.MakeScript(data.click) : undefined,
ischecked: data.ischecked ? ComputedField.MakeFunction(data.ischecked) : undefined, activePen: data.activePen,
@@ -68,6 +69,27 @@ export class CurrentUserUtils {
}));
}
+ static async updateCreatorButtons(doc: Doc) {
+ const toolsBtn = await Cast(doc.ToolsBtn, Doc);
+ if (toolsBtn) {
+ const stackingDoc = await Cast(toolsBtn.sourcePanel, Doc);
+ if (stackingDoc) {
+ const stackdocs = await Cast(stackingDoc.data, listSpec(Doc));
+ if (stackdocs) {
+ const dragset = await Cast(stackdocs[0], Doc);
+ if (dragset) {
+ const dragdocs = await Cast(dragset.data, listSpec(Doc));
+ if (dragdocs) {
+ const dragDocs = await Promise.all(dragdocs);
+ const newButtons = this.setupCreatorButtons(doc, dragDocs.map(d => StrCast(d.title)));
+ newButtons.map(nb => Doc.AddDocToList(dragset, "data", nb));
+ }
+ }
+ }
+ }
+ }
+ }
+
// setup the Creator button which will display the creator panel. This panel will include the drag creators and the color picker. when clicked, this panel will be displayed in the target container (ie, sidebarContainer)
static setupToolsPanel(sidebarContainer: Doc, doc: Doc) {
// setup a masonry view of all he creators
@@ -202,6 +224,7 @@ export class CurrentUserUtils {
doc.undoBtn && reaction(() => UndoManager.undoStack.slice(), () => Doc.GetProto(doc.undoBtn as Doc).opacity = UndoManager.CanUndo() ? 1 : 0.4, { fireImmediately: true });
doc.redoBtn && reaction(() => UndoManager.redoStack.slice(), () => Doc.GetProto(doc.redoBtn as Doc).opacity = UndoManager.CanRedo() ? 1 : 0.4, { fireImmediately: true });
+ this.updateCreatorButtons(doc);
return doc;
}
@@ -299,4 +322,4 @@ export class CurrentUserUtils {
};
return recurs([] as Attribute[], schema ? schema.rootAttributeGroup : undefined);
}
-} \ No newline at end of file
+}
diff --git a/src/server/authentication/models/user_model.ts b/src/server/authentication/models/user_model.ts
index cc670a03a..78e39dbc1 100644
--- a/src/server/authentication/models/user_model.ts
+++ b/src/server/authentication/models/user_model.ts
@@ -73,7 +73,11 @@ userSchema.pre("save", function save(next) {
});
const comparePassword: comparePasswordFunction = function (this: DashUserModel, candidatePassword, cb) {
+ // Choose one of the following bodies for authentication logic.
+ // secure
bcrypt.compare(candidatePassword, this.password, cb);
+ // bypass password
+ // cb(undefined, true);
};
userSchema.methods.comparePassword = comparePassword;