aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkimdahey <claire_kim1@brown.edu>2019-12-07 17:21:40 -0500
committerkimdahey <claire_kim1@brown.edu>2019-12-07 17:21:40 -0500
commit130aaa1a8f2525db12479fcfef2204ed85a2b58b (patch)
tree556db84faccbd28cdad3ad72c01a24935c38c06c
parent88a716d8b7abb0255feea5bc32843ba68910eff5 (diff)
rolled back to working state, saving new changes
-rw-r--r--src/client/util/SettingsManager.tsx49
-rw-r--r--src/server/ApiManagers/UserManager.ts13
2 files changed, 46 insertions, 16 deletions
diff --git a/src/client/util/SettingsManager.tsx b/src/client/util/SettingsManager.tsx
index 0fcb80a3f..e475cac1f 100644
--- a/src/client/util/SettingsManager.tsx
+++ b/src/client/util/SettingsManager.tsx
@@ -17,6 +17,9 @@ export default class SettingsManager extends React.Component<{}> {
@observable private isOpen = false;
@observable private dialogueBoxOpacity = 1;
@observable private overlayOpacity = 0.4;
+ @observable private settingsContent = "settings";
+ @observable private errorText = "";
+ @observable private successText = "";
private curr_password_ref = React.createRef<HTMLInputElement>();
private new_password_ref = React.createRef<HTMLInputElement>();
private new_confirm_ref = React.createRef<HTMLInputElement>();
@@ -35,13 +38,15 @@ export default class SettingsManager extends React.Component<{}> {
SettingsManager.Instance = this;
}
+ @action
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;
if (!(curr_pass && new_pass && new_confirm)) {
- alert("Hey we're missing some fields!");
+ this.changeAlertText("Hey, we're missing some fields!", "");
+ // alert("Hey we're missing some fields!");
return;
}
@@ -50,17 +55,31 @@ export default class SettingsManager extends React.Component<{}> {
new_pass,
new_confirm
};
- const { error } = await Networking.PostToServer('/internalResetPassword', passwordBundle);
+
+ const res = await Networking.PostToServer('/internalResetPassword', passwordBundle);
+ const error = res.error;
+ console.log(res, "is res");
if (error) {
- alert("Uh oh! " + error);
+ console.log(error, error[0].msg);
+ this.changeAlertText("Uh oh! " + error[0].msg + "...", "");
+ // alert("Uh oh! " + error.msg);
return;
}
- alert("Password successfully updated!");
+ this.changeAlertText("", "Password successfully updated!");
+ console.log('success!');
+ // alert("Password successfully updated!");
+ }
+
+ @action
+ private changeAlertText = (errortxt: string, successtxt: string) => {
+ this.errorText = errortxt;
+ this.successText = successtxt;
}
+ @action
onClick = (event: any) => {
- console.log(event);
+ this.settingsContent = event.currentTarget.value;
}
private get settingsInterface() {
@@ -77,13 +96,19 @@ export default class SettingsManager extends React.Component<{}> {
<button onClick={this.onClick} value="settings">settings</button>
<button onClick={this.onClick} value="data">data</button>
</div>
- <div className="settings-content">
- <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>
+ {this.settingsContent === "settings" ?
+ <div className="settings-content">
+ change password here:
+ <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} />
+ {this.errorText ? <div className="error-text">{this.errorText}</div> : undefined}
+ {this.successText ? <div className="success-text">{this.successText}</div> : undefined}
+ <button onClick={this.dispatchRequest}>submit</button>
+
+ </div>
+ :
+ <div className="settings-content">hello?</div>}
</div>
</div>
diff --git a/src/server/ApiManagers/UserManager.ts b/src/server/ApiManagers/UserManager.ts
index 7e8ceb189..3a7e924ee 100644
--- a/src/server/ApiManagers/UserManager.ts
+++ b/src/server/ApiManagers/UserManager.ts
@@ -47,8 +47,8 @@ export default class UserManager extends ApiManager {
// 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";
+ if (err || !passwords_match) {
+ result.error = [{ msg: "Incorrect current password" }];
res.send(result);
resolve(undefined);
} else {
@@ -61,9 +61,13 @@ export default class UserManager extends ApiManager {
return;
}
- req.assert("new_pass", "Password must be at least 4 characters long").len({ min: 4 });
+ // 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);
+ // if (req.assert("new_pass", "Password must be at least 4 characters long").len({ min: 4 })) {
+ // result.inch = "interesting";
+ // }
+
// was there error in validating new passwords?
if (req.validationErrors()) {
// was there error?
@@ -76,7 +80,7 @@ export default class UserManager extends ApiManager {
user.save(err => {
if (err) {
- result.error = "saving";
+ result.error = [{ msg: "Error while saving new password" }];
}
});
@@ -85,6 +89,7 @@ export default class UserManager extends ApiManager {
});
+
register({
method: Method.GET,
subscription: "/activity",