Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
Revert "feat: add password change capability in profile (#298)"
Browse files Browse the repository at this point in the history
This reverts commit 33ea788.
  • Loading branch information
MichaelKohler committed Feb 12, 2020
1 parent fef81db commit 92afdd9
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 165 deletions.
33 changes: 1 addition & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"test": "npm run lint && npm run build && npm run test:frontend && npm run test:shared"
},
"dependencies": {
"axios": "^0.19.2",
"connected-react-router": "^6.6.1",
"hammerjs": "^2.0.8",
"hash.js": "^1.1.7",
Expand Down
5 changes: 1 addition & 4 deletions shared/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Sentences from './db/collections/sentences-meta';
export const BUCKET_NAME = 'App';

export default class DB {

constructor(remote, username, password) {
this.username = username;
this.password = password;
Expand Down Expand Up @@ -92,10 +93,6 @@ export default class DB {
return this.user.removeLanguage(language);
}

async changePassword(user, password, newPassword) {
return this.user.changePassword(user, password, newPassword);
}

async getSentences(language) {
return this.sentences.getAll(language);
}
Expand Down
17 changes: 0 additions & 17 deletions shared/db/collections/user.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from 'axios';
import DB from '../../db.js';

const NAME = 'User';
Expand Down Expand Up @@ -59,22 +58,6 @@ export default class User {
return user.data;
}

async changePassword(username, password, newPassword) {
const apiUrl = `${this.server._remote}/accounts/${username}`;
const data = {
data: {
password: newPassword,
},
};

return axios.put(apiUrl, data, {
auth: {
username,
password,
},
});
}

async getAllUsers() {
try {
const collection = await this.getCollection();
Expand Down
12 changes: 0 additions & 12 deletions web/css/profile.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,3 @@ button.remove-lang {
box-shadow: none;
text-decoration: underline;
}

#change-password {
max-width: 600px;
}

#change-password button {
margin: 0;
}

#change-password .form-error {
text-align: left;
}
33 changes: 0 additions & 33 deletions web/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export const ACTION_SUBMIT_SENTENCES_FAILURE_SINGLE = 'SUBMIT_SENTENCES_FAILURE_

export const ACTION_SETTINGS_CHANGED = 'ACTION_SETTINGS_CHANGED';
export const ACTION_SETTINGS_CHANGED_FAILURE = 'ACTION_SETTINGS_CHANGED_FAILURE';
export const ACTION_PASSWORD_CHANGED = 'ACTION_PASSWORD_CHANGED';
export const ACTION_PASSWORD_CHANGE_FAILURE = 'ACTION_PASSWORD_CHANGE_FAILURE';

const VALID_USERNAME_CHARACTERS = /^[a-zA-Z0-9]+$/;

Expand Down Expand Up @@ -82,24 +80,6 @@ export function setSetting(key, value) {
};
}

export function changePassword(password) {
return async function(dispatch, getState) {
if (!password) {
return dispatch(passwordChangedFailure());
}

try {
const state = getState();
const db = new WebDB(state.app.username, state.app.password);
await db.changePassword(state.app.username, state.app.password, password);
dispatch(passwordChanged(password));
} catch (err) {
dispatch(passwordChangedFailure());
throw err;
}
};
}

export function addLanguage(language) {
return async function(dispatch, getState) {
try {
Expand Down Expand Up @@ -214,19 +194,6 @@ export function settingsChangedFailure() {
};
}

export function passwordChanged(newPassword) {
return {
type: ACTION_PASSWORD_CHANGED,
newPassword,
};
}

export function passwordChangedFailure() {
return {
type: ACTION_PASSWORD_CHANGE_FAILURE,
};
}

export function sendAddLanguage() {
return {
type: ACTION_ADD_LANGUAGE_REQUEST,
Expand Down
54 changes: 4 additions & 50 deletions web/src/components/pages/profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { Link } from 'react-router-dom';
import { getLanguageName } from '../../../../shared/languages';
import { arrayCompare } from '../../../../shared/util';
import WebDB from '../../web-db';
import {
addLanguage,
removeLanguage,
setSetting,
changePassword,
} from '../../actions';
import { addLanguage, removeLanguage, setSetting } from '../../actions';
import LanguageSelector from '../language-selector';

import '../../../css/profile.css';
Expand All @@ -20,8 +15,6 @@ const DEFAULT_STATE = {
totalValidated: 0,
languageInfo: {},
loading: false,
passwordEntered: false,
passwordsMatching: true,
};

class Profile extends React.Component {
Expand All @@ -30,8 +23,6 @@ class Profile extends React.Component {
this.state = DEFAULT_STATE;
this.onAdd = this.onAdd.bind(this);
this.onRemove = this.onRemove.bind(this);
this.onPasswordSubmit = this.onPasswordSubmit.bind(this);
this.checkPasswordInput = this.checkPasswordInput.bind(this);
this.activateSwipeReview = this.activateSwipeReview.bind(this);
this.deactivateSwipeReview = this.deactivateSwipeReview.bind(this);
}
Expand Down Expand Up @@ -145,35 +136,19 @@ class Profile extends React.Component {
this.props.setSetting('useSwipeReview', false);
}

onPasswordSubmit() {
const password = document.querySelector('#password').value;
this.props.changePassword(password);
}

checkPasswordInput() {
const password = document.querySelector('#password').value;
const passwordRepeat = document.querySelector('#password-repeat').value;
const valid = password && passwordRepeat && password == passwordRepeat;

this.setState({
passwordEntered: Boolean(password) && Boolean(passwordRepeat),
passwordsMatching: valid,
});
}

render() {
const {
username,
languages,
pending,
settings = {},
settingsChangedFailureMessage,
passwordChanged,
} = this.props;
console.log('settings changed?', settingsChangedFailureMessage);
const { useSwipeReview } = settings;

return (
<>
<form>
<h2>Profile: { username }</h2>

{ languages && languages.length > 0 && (
Expand Down Expand Up @@ -219,25 +194,6 @@ class Profile extends React.Component {
onClick={this.onAdd} className="add-language">Add</button>
</section>

<section>
<h2>Change Password</h2>
<p>Note that you will be logged out after changing the password. Please login with your new password.</p>
<form id="change-password" onSubmit={this.onPasswordSubmit}>
{passwordChanged === false && (
<p className="form-error">Password could not be changed. Please try again later.</p>
)}
<section>
<label htmlFor="password">Password</label>
<input type="password" id="password" onChange={this.checkPasswordInput} />
<label htmlFor="password-repeat">Repeat password</label>
<input type="password" id="password-repeat" onChange={this.checkPasswordInput} />
{!this.state.passwordsMatching && (<p className="password-error">Passwords do not match.</p>)}
{passwordChanged && (<p>Password changed successfully.</p>)}
<button disabled={!this.state.passwordEntered || !this.state.passwordsMatching}>Submit</button>
</section>
</form>
</section>

<section>
<h2>Settings</h2>
{settingsChangedFailureMessage && (
Expand All @@ -256,7 +212,7 @@ class Profile extends React.Component {
<button onClick={this.deactivateSwipeReview}>Use Normal Review Tool</button>
)}
</section>
</>
</form>
);
}
}
Expand Down Expand Up @@ -289,7 +245,6 @@ function mapStateToProps(state) {
pending: state.app.pendingLanguages,
settings: state.app.settings,
settingsChangedFailureMessage: state.app.settingsChangedFailureMessage,
passwordChanged: state.app.passwordChanged,
};
}

Expand All @@ -298,7 +253,6 @@ function mapDispatchToProps(dispatch) {
addLanguage: (language) => dispatch(addLanguage(language)),
removeLanguage: (language) => dispatch(removeLanguage(language)),
setSetting: (key, value) => dispatch(setSetting(key, value)),
changePassword: (password) => dispatch(changePassword(password)),
};
}

Expand Down
16 changes: 0 additions & 16 deletions web/src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import {
ACTION_SUBMIT_SENTENCES_FAILURE_SINGLE,
ACTION_SETTINGS_CHANGED,
ACTION_SETTINGS_CHANGED_FAILURE,
ACTION_PASSWORD_CHANGED,
ACTION_PASSWORD_CHANGE_FAILURE,
} from '../actions';

import {
Expand All @@ -40,7 +38,6 @@ export const INITIAL_STATE = {
errorMessage: null,
sentenceSubmissionFailures: [],
settingsChangedFailureMessage: '',
passwordChanged: null,
};

function copyInto(oldObj, newObj) {
Expand Down Expand Up @@ -174,19 +171,6 @@ function reducer(state = INITIAL_STATE, action) {
settingsChangedFailureMessage: 'Could not change settings. Please try again.',
});

case ACTION_PASSWORD_CHANGED:
return copyInto(state, {
authed: false,
username: null,
password: state.newPassword,
passwordChanged: true,
});

case ACTION_PASSWORD_CHANGE_FAILURE:
return copyInto(state, {
passwordChanged: false,
});

default:
return state;
}
Expand Down

0 comments on commit 92afdd9

Please sign in to comment.