(this.input.newPasswordAgain = ref) } />;
const setPassword = ();
if (this.state.step === 1) {
return [requestCodeButton];
} if (this.state.step === 2) {
return [codeInput, verifyCodeButton];
} return [newPasswordInput, newPasswordAgainInput, setPassword];
};
setPassword = () => {
this.messages.clearErrorSuccess();
if (CustomInput.hasInvalidInput(this.input, ["newPassword", "newPasswordAgain"])) {
this.messages.clearAddError("Some fields are incorrect. Please fix them before continuing.");
} else if (CustomInput.isTheSame(this.input, ["newPassword", "newPasswordAgain"])) {
this.messages.clearAddError("New password and new password again need to be the same.");
} else {
io.getSocket(socket => {
socket.emit("users.changePasswordWithCode", this.state.code, this.input.newPassword.getValue(), res => {
if (res.status === "success") {
this.messages.clearAddSuccess("Successfully set password. Redirecting you to the settings page.");
location.href = "/settings";
} else {
this.messages.addError(res.message);
}
});
});
}
};
requestCode = () => {
this.messages.clearErrorSuccess();
io.getSocket(socket => {
socket.emit("users.requestPassword", res => {
if (res.status === "success") {
this.messages.clearAddSuccess("Successfully requested code.");
this.messages.clearAddInfo("We have sent a unique code to your email address.");
this.setState({
step: 2,
});
} else {
this.messages.addError(res.message);
}
});
});
};
verifyCode = () => {
this.messages.clearErrorSuccess();
if (CustomInput.hasInvalidInput(this.input, ["code"])) {
this.messages.clearAddError("Some fields are incorrect. Please fix them before continuing.");
} else {
io.getSocket(socket => {
socket.emit("users.verifyPasswordCode", this.input.code.getValue(), res => {
if (res.status === "success") {
this.messages.clearAddSuccess("Successfully verified code.");
this.setState({
step: 3,
code: this.input.code.getValue(),
});
} else {
this.messages.addError(res.message);
}
});
});
}
};
render() {
return (
Set Password
(this.messages = ref) } />
{ this.getActions() }
);
}
}