aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkimdahey <claire_kim1@brown.edu>2019-12-05 11:57:15 -0500
committerkimdahey <claire_kim1@brown.edu>2019-12-05 11:57:15 -0500
commit88a716d8b7abb0255feea5bc32843ba68910eff5 (patch)
tree0008bbaf477522545102726d444aa2fb277c10c7
parent70583fa47bd9920d1823d381708c81283534d6ce (diff)
password reset live
-rw-r--r--package.json2
-rw-r--r--src/client/util/SettingsManager.scss34
-rw-r--r--src/client/util/SettingsManager.tsx50
-rw-r--r--src/server/ApiManagers/UserManager.ts49
4 files changed, 113 insertions, 22 deletions
diff --git a/package.json b/package.json
index 499aefdb5..574c7e7fa 100644
--- a/package.json
+++ b/package.json
@@ -229,4 +229,4 @@
"xoauth2": "^1.2.0",
"youtube": "^0.1.0"
}
-} \ No newline at end of file
+}
diff --git a/src/client/util/SettingsManager.scss b/src/client/util/SettingsManager.scss
index 0d637868b..228625182 100644
--- a/src/client/util/SettingsManager.scss
+++ b/src/client/util/SettingsManager.scss
@@ -1,17 +1,45 @@
@import "../views/globalCssVariables";
+.dialogue-box {
+ background-color: whitesmoke !important;
+ color: grey;
+
+ button {
+ background: $lighter-alt-accent;
+ outline: none;
+ border-radius: 5px;
+ border: 0px;
+ color: #fcfbf7;
+ text-transform: uppercase;
+ letter-spacing: 2px;
+ font-size: 75%;
+ padding: 10px;
+ transition: transform 0.2s;
+ margin: 2px;
+ }
+}
+
.settings-interface {
display: flex;
flex-direction: column;
+ input {
+ border-radius: 5px;
+ border: none;
+ padding: 4px 4px 4px 10px;
+ margin: 2px;
+ }
+
.settings-body {
display: flex;
flex-direction: row;
+
.settings-type {
display: flex;
flex-direction: column;
flex-basis: 30%;
+
}
.settings-content {
@@ -20,6 +48,10 @@
flex-direction: column;
justify-content: space-between;
+ button {
+ background: $darker-alt-accent;
+ }
+
input {
min-width: 100%;
}
@@ -40,7 +72,7 @@
color: $dark-color;
text-transform: uppercase;
letter-spacing: 2px;
- font-size: 75%;
+ font-size: 120%;
}
.close-button {
diff --git a/src/client/util/SettingsManager.tsx b/src/client/util/SettingsManager.tsx
index ee2d9ff21..0fcb80a3f 100644
--- a/src/client/util/SettingsManager.tsx
+++ b/src/client/util/SettingsManager.tsx
@@ -7,7 +7,7 @@ import * as fa from '@fortawesome/free-solid-svg-icons';
import { SelectionManager } from "./SelectionManager";
import "./SettingsManager.scss";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { Identified } from "../Network";
+import { Networking } from "../Network";
library.add(fa.faWindowClose);
@@ -36,21 +36,31 @@ export default class SettingsManager extends React.Component<{}> {
}
private dispatchRequest = async () => {
- const curr_pass = this.curr_password_ref.current!.value;
- 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(resp.error);
+ const curr_pass = this.curr_password_ref.current?.value;
+ const new_pass = this.new_password_ref.current?.value;
+ const new_confirm = this.new_confirm_ref.current?.value;
+
+ if (!(curr_pass && new_pass && new_confirm)) {
+ alert("Hey we're missing some fields!");
+ return;
+ }
+
+ const passwordBundle = {
+ curr_pass,
+ new_pass,
+ new_confirm
+ };
+ const { error } = await Networking.PostToServer('/internalResetPassword', passwordBundle);
+ if (error) {
+ alert("Uh oh! " + error);
+ return;
}
- console.log('go!');
- // do stuff with response
+
+ alert("Password successfully updated!");
+ }
+
+ onClick = (event: any) => {
+ console.log(event);
}
private get settingsInterface() {
@@ -64,13 +74,13 @@ export default class SettingsManager extends React.Component<{}> {
</div>
<div className="settings-body">
<div className="settings-type">
- <p>changeable settings</p>
- <p>static data</p>
+ <button onClick={this.onClick} value="settings">settings</button>
+ <button onClick={this.onClick} value="data">data</button>
</div>
<div className="settings-content">
- <input ref={this.curr_password_ref} />
- <input ref={this.new_password_ref} />
- <input ref={this.new_confirm_ref} />
+ <input placeholder="current password" ref={this.curr_password_ref} />
+ <input placeholder="new password" ref={this.new_password_ref} />
+ <input placeholder="confirm new password" ref={this.new_confirm_ref} />
<button onClick={this.dispatchRequest}>submit</button>
this changes with what you select!
</div>
diff --git a/src/server/ApiManagers/UserManager.ts b/src/server/ApiManagers/UserManager.ts
index 0f7d14320..7e8ceb189 100644
--- a/src/server/ApiManagers/UserManager.ts
+++ b/src/server/ApiManagers/UserManager.ts
@@ -2,6 +2,8 @@ import ApiManager, { Registration } from "./ApiManager";
import { Method } from "../RouteManager";
import { Database } from "../database";
import { msToTime } from "../ActionUtilities";
+import * as bcrypt from "bcrypt-nodejs";
+import { Opt } from "../../new_fields/Doc";
export const timeMap: { [id: string]: number } = {};
interface ActivityUnit {
@@ -37,6 +39,53 @@ export default class UserManager extends ApiManager {
});
register({
+ method: Method.POST,
+ subscription: '/internalResetPassword',
+ onValidation: async ({ user, req, res }) => {
+ const result: any = {};
+ const { curr_pass, new_pass, new_confirm } = req.body;
+ // perhaps should assert whether curr password is entered correctly
+ const validated = await new Promise<Opt<boolean>>(resolve => {
+ bcrypt.compare(curr_pass, user.password, (err, passwords_match) => {
+ if (err) {
+ result.error = "Incorrect current password";
+ res.send(result);
+ resolve(undefined);
+ } else {
+ resolve(passwords_match);
+ }
+ });
+ });
+
+ if (validated === undefined) {
+ return;
+ }
+
+ req.assert("new_pass", "Password must be at least 4 characters long").len({ min: 4 });
+ req.assert("new_confirm", "Passwords do not match").equals(new_pass);
+
+ // was there error in validating new passwords?
+ if (req.validationErrors()) {
+ // was there error?
+ result.error = req.validationErrors();
+ }
+
+ user.password = new_pass;
+ user.passwordResetToken = undefined;
+ user.passwordResetExpires = undefined;
+
+ user.save(err => {
+ if (err) {
+ result.error = "saving";
+ }
+ });
+
+ res.send(result);
+ }
+ });
+
+
+ register({
method: Method.GET,
subscription: "/activity",
onValidation: ({ res }) => {