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

Allow to login into UI with token from api/v1/auth/login #2234

Merged
merged 12 commits into from
Oct 9, 2020
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.2.0] - Unreleased

### Added

- Ability to login into CVAT-UI with token from api/v1/auth/login (<https://github.com/openvinotoolkit/cvat/pull/2234>)
- Added eslint-prettier integration & code autoformat in precommiting hook
- Added layout grids toggling ('ctrl + alt + Enter')
- Added password reset functionality (<https://github.com/opencv/cvat/pull/2058>)
Expand Down
145 changes: 81 additions & 64 deletions cvat-ui/package-lock.json

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

3 changes: 2 additions & 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.9.11",
"version": "1.9.12",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down Expand Up @@ -73,6 +73,7 @@
"prop-types": "^15.7.2",
"react": "^16.9.0",
"react-color": "^2.18.1",
"react-cookie": "^4.0.3",
"react-dom": "^16.9.0",
"react-hotkeys": "^2.0.0",
"react-redux": "^7.1.1",
Expand Down
3 changes: 2 additions & 1 deletion cvat-ui/src/components/cvat-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Header from 'components/header/header';
import ResetPasswordPageConfirmComponent from 'components/reset-password-confirm-page/reset-password-confirm-page';
import ResetPasswordPageComponent from 'components/reset-password-page/reset-password-page';
import ShorcutsDialog from 'components/shortcuts-dialog/shortcuts-dialog';
import LoginWithTokenComponent from 'components/login-with-token/login-with-token';
import AnnotationPageContainer from 'containers/annotation-page/annotation-page';
import CreateTaskPageContainer from 'containers/create-task-page/create-task-page';
import LoginPageContainer from 'containers/login-page/login-page';
Expand All @@ -32,7 +33,6 @@ import showPlatformNotification, { platformInfo, stopNotifications } from 'utils
import '../styles.scss';



interface CVATAppProps {
loadFormats: () => void;
loadUsers: () => void;
Expand Down Expand Up @@ -336,6 +336,7 @@ 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/login-with-token/:sessionId/:token' component={LoginWithTokenComponent} />
<Route exact path='/auth/password/reset' component={ResetPasswordPageComponent} />
<Route exact path='/auth/password/reset/confirm' component={ResetPasswordPageConfirmComponent} />
<Redirect to='/auth/login' />
Expand Down
27 changes: 27 additions & 0 deletions cvat-ui/src/components/login-with-token/login-with-token.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2020 Intel Corporation
//
// SPDX-License-Identifier: MIT

import React, { useEffect } from 'react';
import { Redirect, useParams } from 'react-router';
import { useCookies } from 'react-cookie';

export default function LoginWithTokenComponent(): JSX.Element {
const { sessionId, token } = useParams();
const [cookies, setCookie] = useCookies(['sessionid', 'csrftoken']);

const expires1y = new Date(new Date().setFullYear(new Date().getFullYear() + 1));
const expires2w = new Date(new Date().setDate(new Date().getDate() + 13));

setCookie('sessionid', sessionId, { path: '/', expires: expires2w });
setCookie('csrftoken', token, { path: '/', expires: expires1y });

useEffect(() => () => {
window.location.reload();
}, [cookies.sessionid, cookies.csrftoken]);

if (cookies.sessionid && cookies.csrftoken) {
return (<Redirect to='/tasks' />);
}
return (<></>);
}