Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added password reset functionality #2058

Merged
merged 9 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Datumaro] Added model info and source info commands (<https://github.com/opencv/cvat/pull/1973>)
- [Datumaro] Dataset statistics (<https://github.com/opencv/cvat/pull/1668>)
- [Datumaro] Multi-dataset merge (https://github.com/opencv/cvat/pull/1695)
- Added password reset functionality (<https://github.com/opencv/cvat/pull/2058>)


### Changed
- Shape coordinates are rounded to 2 digits in dumped annotations (<https://github.com/opencv/cvat/pull/1970>)
Expand Down
2 changes: 1 addition & 1 deletion cvat-core/package-lock.json

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

2 changes: 1 addition & 1 deletion cvat-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-core",
"version": "3.4.0",
"version": "3.5.0",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "babel.config.js",
"scripts": {
Expand Down
8 changes: 8 additions & 0 deletions cvat-core/src/api-implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@
await serverProxy.server.changePassword(oldPassword, newPassword1, newPassword2);
};

cvat.server.resetPassword.implementation = async (email) => {
await serverProxy.server.resetPassword(email);
};

cvat.server.resetPasswordConfirm.implementation = async(newPassword1, newPassword2, uid, token) => {
await serverProxy.server.resetPasswordConfirm(newPassword1, newPassword2, uid, token);
};

cvat.server.authorized.implementation = async () => {
const result = await serverProxy.server.authorized();
return result;
Expand Down
35 changes: 35 additions & 0 deletions cvat-core/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ function build() {
* @method changePassword
* @async
* @memberof module:API.cvat.server
* @param {string} oldPassword Current password for the account
* @param {string} newPassword1 New password for the account
* @param {string} newPassword2 Confirmation password for the account
* @throws {module:API.cvat.exceptions.PluginError}
* @throws {module:API.cvat.exceptions.ServerError}
*/
Expand All @@ -206,6 +209,38 @@ function build() {
.apiWrapper(cvat.server.changePassword, oldPassword, newPassword1, newPassword2);
return result;
},
/**
* Method allows to reset user password
* @method resetPassword
* @async
* @memberof module:API.cvat.server
* @param {string} email A email address for the account
* @throws {module:API.cvat.exceptions.PluginError}
* @throws {module:API.cvat.exceptions.ServerError}
*/
async resetPassword(email) {
const result = await PluginRegistry
.apiWrapper(cvat.server.resetPassword, email);
return result;
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
},
/**
* Method allows to confirm reset user password
* @method resetPasswordConfirm
* @async
* @memberof module:API.cvat.server
* @param {string} newPassword1 New password for the account
* @param {string} newPassword2 Confirmation password for the account
* @param {string} uid User id
* @param {string} token Request authentication token
* @throws {module:API.cvat.exceptions.PluginError}
* @throws {module:API.cvat.exceptions.ServerError}
*/
async resetPasswordConfirm(newPassword1, newPassword2, uid, token) {
const result = await PluginRegistry
.apiWrapper(cvat.server.resetPasswordConfirm, newPassword1, newPassword2,
uid, token);
return result;
},
/**
* Method allows to know whether you are authorized on the server
* @method authorized
Expand Down
37 changes: 37 additions & 0 deletions cvat-core/src/server-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,41 @@
}
}

async function resetPassword(email) {
try {
const data = JSON.stringify({
email,
});
await Axios.post(`${config.backendAPI}/auth/password/reset`, data, {
proxy: config.proxy,
headers: {
'Content-Type': 'application/json',
},
});
} catch (errorData) {
throw generateError(errorData);
}
}

async function resetPasswordConfirm(newPassword1, newPassword2, uid, token) {
try {
const data = JSON.stringify({
new_password1: newPassword1,
new_password2: newPassword2,
uid,
token,
});
await Axios.post(`${config.backendAPI}/auth/password/reset/confirm`, data, {
proxy: config.proxy,
headers: {
'Content-Type': 'application/json',
},
});
} catch (errorData) {
throw generateError(errorData);
}
}

async function authorized() {
try {
await module.exports.users.getSelf();
Expand Down Expand Up @@ -787,6 +822,8 @@
login,
logout,
changePassword,
resetPassword,
resetPasswordConfirm,
authorized,
register,
request: serverRequest,
Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/package-lock.json

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

2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.7.2",
"version": "1.8.0",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
64 changes: 59 additions & 5 deletions cvat-ui/src/actions/auth-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export enum AuthActionTypes {
CHANGE_PASSWORD_SUCCESS = 'CHANGE_PASSWORD_SUCCESS',
CHANGE_PASSWORD_FAILED = 'CHANGE_PASSWORD_FAILED',
SWITCH_CHANGE_PASSWORD_DIALOG = 'SWITCH_CHANGE_PASSWORD_DIALOG',
RESET_PASSWORD = 'RESET_PASSWORD',
RESET_PASSWORD_SUCCESS = 'RESET_PASSWORD_SUCCESS',
RESET_PASSWORD_FAILED = 'RESET_PASSWORD_FAILED',
RESET_PASSWORD_CONFIRM = 'RESET_PASSWORD_CONFIRM',
RESET_PASSWORD_CONFIRM_SUCCESS = 'RESET_PASSWORD_CONFIRM_SUCCESS',
RESET_PASSWORD_CONFIRM_FAILED = 'RESET_PASSWORD_CONFIRM_FAILED',
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
LOAD_AUTH_ACTIONS = 'LOAD_AUTH_ACTIONS',
LOAD_AUTH_ACTIONS_SUCCESS = 'LOAD_AUTH_ACTIONS_SUCCESS',
LOAD_AUTH_ACTIONS_FAILED = 'LOAD_AUTH_ACTIONS_FAILED',
Expand All @@ -50,9 +56,22 @@ export const authActions = {
switchChangePasswordDialog: (showChangePasswordDialog: boolean) => (
createAction(AuthActionTypes.SWITCH_CHANGE_PASSWORD_DIALOG, { showChangePasswordDialog })
),
resetPassword: () => createAction(AuthActionTypes.RESET_PASSWORD),
resetPasswordSuccess: () => createAction(AuthActionTypes.RESET_PASSWORD_SUCCESS),
resetPasswordFailed: (error: any) => (
createAction(AuthActionTypes.RESET_PASSWORD_FAILED, { error })
),
resetPasswordConfirm: () => createAction(AuthActionTypes.RESET_PASSWORD_CONFIRM),
resetPasswordConfirmSuccess: () => createAction(AuthActionTypes.RESET_PASSWORD_CONFIRM_SUCCESS),
resetPasswordConfirmFailed: (error: any) => (
createAction(AuthActionTypes.RESET_PASSWORD_CONFIRM_FAILED, { error })
),
loadServerAuthActions: () => createAction(AuthActionTypes.LOAD_AUTH_ACTIONS),
loadServerAuthActionsSuccess: (allowChangePassword: boolean) => (
createAction(AuthActionTypes.LOAD_AUTH_ACTIONS_SUCCESS, { allowChangePassword })
loadServerAuthActionsSuccess: (allowChangePassword: boolean, allowResetPassword: boolean) => (
createAction(AuthActionTypes.LOAD_AUTH_ACTIONS_SUCCESS, {
allowChangePassword,
allowResetPassword,
})
),
loadServerAuthActionsFailed: (error: any) => (
createAction(AuthActionTypes.LOAD_AUTH_ACTIONS_FAILED, { error })
Expand Down Expand Up @@ -136,16 +155,51 @@ export const changePasswordAsync = (oldPassword: string,
}
};

export const resetPasswordAsync = (email: string): ThunkAction => async (dispatch) => {
dispatch(authActions.resetPassword());

try {
await cvat.server.resetPassword(email);
dispatch(authActions.resetPasswordSuccess());
} catch (error) {
dispatch(authActions.resetPasswordFailed(error));
}
};

export const resetPasswordConfirmAsync = (
newPassword1: string,
newPassword2: string,
uid: string,
token: string,
): ThunkAction => async (dispatch) => {
dispatch(authActions.resetPasswordConfirm());

try {
await cvat.server.resetPasswordConfirm(newPassword1, newPassword2, uid, token);
dispatch(authActions.resetPasswordConfirmSuccess());
} catch (error) {
dispatch(authActions.resetPasswordConfirmFailed(error));
}
};

export const loadAuthActionsAsync = (): ThunkAction => async (dispatch) => {
dispatch(authActions.loadServerAuthActions());

try {
const promises: Promise<boolean>[] = [
isReachable(`${cvat.config.backendAPI}/auth/password/change`, 'OPTIONS'),
isReachable(`${cvat.config.backendAPI}/auth/password/reset`, 'OPTIONS'),
isReachable(`${cvat.config.backendAPI}/auth/password/reset/confirm`, 'OPTIONS'),
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
];
const [allowChangePassword] = await Promise.all(promises);

dispatch(authActions.loadServerAuthActionsSuccess(allowChangePassword));
const [
allowChangePassword,
allowResetPassword,
allowResetPasswordConfirm] = await Promise.all(promises);

dispatch(authActions.loadServerAuthActionsSuccess(
allowChangePassword,
allowResetPassword && allowResetPasswordConfirm,
));
} catch (error) {
dispatch(authActions.loadServerAuthActionsFailed(error));
}
Expand Down
13 changes: 8 additions & 5 deletions cvat-ui/src/components/cvat-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import ModelsPageContainer from 'containers/models-page/models-page';
import AnnotationPageContainer from 'containers/annotation-page/annotation-page';
import LoginPageContainer from 'containers/login-page/login-page';
import RegisterPageContainer from 'containers/register-page/register-page';
import ResetPasswordPageContainer from 'components/reset-password-page/reset-password-page';
import ResetPasswordPageConfirmContainer from 'components/reset-password-confirm-page/reset-password-confirm-page';
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
import HeaderContainer from 'containers/header/header';
import { customWaViewHit } from 'utils/enviroment';

Expand Down Expand Up @@ -57,7 +59,6 @@ interface CVATAppProps {
userAgreementsInitialized: boolean;
authActionsFetching: boolean;
authActionsInitialized: boolean;
allowChangePassword: boolean;
notifications: NotificationsState;
user: any;
}
Expand Down Expand Up @@ -125,14 +126,14 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
return;
}

if (user == null) {
return;
}

if (!authActionsInitialized && !authActionsFetching) {
loadAuthActions();
}

if (user == null) {
return;
}

if (!formatsInitialized && !formatsFetching) {
loadFormats();
}
Expand Down Expand Up @@ -298,6 +299,8 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
<Switch>
<Route exact path='/auth/register' component={RegisterPageContainer} />
<Route exact path='/auth/login' component={LoginPageContainer} />
<Route exact path='/auth/password/reset' component={ResetPasswordPageContainer} />
<Route exact path='/auth/password/reset/confirm' component={ResetPasswordPageConfirmContainer} />
<Redirect to='/auth/login' />
</Switch>
</GlobalErrorBoundary>
Expand Down
12 changes: 12 additions & 0 deletions cvat-ui/src/components/login-page/login-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import CookieDrawer from './cookie-policy-drawer';

interface LoginPageComponentProps {
fetching: boolean;
renderResetPassword: boolean;
onLogin: (username: string, password: string) => void;
}

Expand All @@ -29,6 +30,7 @@ function LoginPageComponent(props: LoginPageComponentProps & RouteComponentProps
const {
fetching,
onLogin,
renderResetPassword,
} = props;

return (
Expand All @@ -50,6 +52,16 @@ function LoginPageComponent(props: LoginPageComponentProps & RouteComponentProps
</Text>
</Col>
</Row>
{ renderResetPassword
&& (
<Row type='flex' justify='start' align='top'>
<Col>
<Text strong>
<Link to='/auth/password/reset'>Forgot your password?</Link>
</Text>
</Col>
</Row>
)}
</Col>
</Row>
<CookieDrawer />
Expand Down
Loading