aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/util/SettingsManager.scss16
-rw-r--r--src/client/util/SettingsManager.tsx22
-rw-r--r--src/server/index.ts48
3 files changed, 73 insertions, 13 deletions
diff --git a/src/client/util/SettingsManager.scss b/src/client/util/SettingsManager.scss
index cd9d2569a..0d637868b 100644
--- a/src/client/util/SettingsManager.scss
+++ b/src/client/util/SettingsManager.scss
@@ -17,18 +17,24 @@
.settings-content {
padding-left: 1em;
display: flex;
+ flex-direction: column;
justify-content: space-between;
+
+ input {
+ min-width: 100%;
+ }
}
}
.focus-span {
text-decoration: underline;
}
-p {
- text-align: left;
- padding: 0;
- margin: 0 0 20px 0;
-}
+
+ p {
+ text-align: left;
+ padding: 0;
+ margin: 0 0 20px 0;
+ }
h1 {
color: $dark-color;
diff --git a/src/client/util/SettingsManager.tsx b/src/client/util/SettingsManager.tsx
index 76f4bb964..ee2d9ff21 100644
--- a/src/client/util/SettingsManager.tsx
+++ b/src/client/util/SettingsManager.tsx
@@ -18,6 +18,8 @@ export default class SettingsManager extends React.Component<{}> {
@observable private dialogueBoxOpacity = 1;
@observable private overlayOpacity = 0.4;
private curr_password_ref = React.createRef<HTMLInputElement>();
+ private new_password_ref = React.createRef<HTMLInputElement>();
+ private new_confirm_ref = React.createRef<HTMLInputElement>();
public open = action(() => {
SelectionManager.DeselectAll();
@@ -35,12 +37,19 @@ export default class SettingsManager extends React.Component<{}> {
private dispatchRequest = async () => {
const curr_pass = this.curr_password_ref.current!.value;
- const { error: resultError, ...others } = await Identified.PostToServer('/internalResetPassword', { curr_pass });
- if (resultError) {
+ const new_pass = this.new_password_ref.current!.value;
+ const new_confirm = this.new_confirm_ref.current!.value;
+ console.log('ready!');
+ // const { error, hello } = await Identified.PostToServer('/internalResetPassword', { curr_pass, new_pass, new_confirm });
+ const resp = await Identified.PostToServer('/internalResetPassword', { curr_pass, new_pass, new_confirm });
+ console.log('set!');
+ console.log('response', resp);
+ console.log('hm', resp.hm);
+ if (resp.error) {
// we failed
- console.log(resultError);
+ console.log(resp.error);
}
- console.log(others);
+ console.log('go!');
// do stuff with response
}
@@ -59,7 +68,10 @@ export default class SettingsManager extends React.Component<{}> {
<p>static data</p>
</div>
<div className="settings-content">
- <input ref={this.curr_password_ref}></input>
+ <input ref={this.curr_password_ref} />
+ <input ref={this.new_password_ref} />
+ <input ref={this.new_confirm_ref} />
+ <button onClick={this.dispatchRequest}>submit</button>
this changes with what you select!
</div>
</div>
diff --git a/src/server/index.ts b/src/server/index.ts
index d96bd4d9a..df9edac50 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -19,7 +19,7 @@ import { Socket } from 'socket.io';
import * as webpack from 'webpack';
import * as wdm from 'webpack-dev-middleware';
import * as whm from 'webpack-hot-middleware';
-import { Utils } from '../Utils';
+import { Utils, returnEmptyString } from '../Utils';
import { getForgot, getLogin, getLogout, getReset, getSignup, postForgot, postLogin, postReset, postSignup } from './authentication/controllers/user_controller';
import { DashUserModel } from './authentication/models/user_model';
import { Client } from './Client';
@@ -56,6 +56,8 @@ import { reject } from 'bluebird';
import { ExifData } from 'exif';
import { Result } from '../client/northstar/model/idea/idea';
import RouteSubscriber from './RouteSubscriber';
+//@ts-ignore
+import * as bcrypt from "bcrypt-nodejs";
const download = (url: string, dest: fs.PathLike) => request.get(url).pipe(fs.createWriteStream(dest));
let youtubeApiKey: string;
@@ -671,10 +673,51 @@ addSecureRoute({
addSecureRoute({
method: Method.POST,
subscribers: '/internalResetPassword',
- onValidation: (user, _req, res) => {
+ onValidation: async (user, req, res) => {
+ const result: any = {};
+ // perhaps should assert whether curr password is entered correctly
+ const validated = await new Promise<Opt<boolean>>(resolve => {
+ bcrypt.compare(req.body.curr_pass, user.password, (err, result_1) => {
+ if (err) {
+ result.error = "Incorrect current password";
+ res.send(result);
+ resolve(undefined);
+ } else {
+ result.hm = err;
+ resolve(result_1);
+ }
+ });
+ });
+
+ if (validated === undefined) {
+ return;
+ }
+
+ result.hello = validated;
+ req.assert("new_pass", "Password must be at least 4 characters long").len({ min: 4 });
+ req.assert("new_confirm", "Passwords do not match").equals(req.body.new_pass);
+
+ // was there error in validating new passwords?
+ if (req.validationErrors()) {
+ // was there error?
+ result.error = req.validationErrors();
+ result.pass = user.password;
+ }
+
+ user.password = req.body.password;
+ user.passwordResetToken = undefined;
+ user.passwordResetExpires = undefined;
+
+ user.save(function (err) {
+ result.error = "saving";
+ // was there error?
+ });
+
// user password auth
// new pass same
// do extra stuff
+ //
+ res.send(result);
}
});
@@ -1173,7 +1216,6 @@ const suffixMap: { [type: string]: (string | [string, string | ((json: any) => a
"pdf": ["_t", "url"],
"audio": ["_t", "url"],
"web": ["_t", "url"],
- "RichTextField": ["_t", value => value.Text],
"date": ["_d", value => new Date(value.date).toISOString()],
"proxy": ["_i", "fieldId"],
"list": ["_l", list => {