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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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 password reset functionality (<https://github.com/opencv/cvat/pull/2058>)
- Ability to work with data on the fly (https://github.com/opencv/cvat/pull/2007)
- Annotation in process outline color wheel (<https://github.com/opencv/cvat/pull/2084>)
Expand Down
50 changes: 48 additions & 2 deletions cvat-ui/package-lock.json

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

1 change: 1 addition & 0 deletions cvat-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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
2 changes: 2 additions & 0 deletions cvat-ui/src/components/cvat-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Text from 'antd/lib/typography/Text';
import notification from 'antd/lib/notification';

import GlobalErrorBoundary from 'components/global-error-boundary/global-error-boundary';
import LoginWithTokenComponent from './login-with-token/login-with-token';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use absolute import: components/login-with-token/login-with-token, or put the line after all absolute (linter says that relative import should occur after absolute)

import ShorcutsDialog from 'components/shortcuts-dialog/shortcuts-dialog';
import TasksPageContainer from 'containers/tasks-page/tasks-page';
import CreateTaskPageContainer from 'containers/create-task-page/create-task-page';
Expand Down Expand Up @@ -337,6 +338,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
21 changes: 21 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,21 @@
// Copyright (C) 2020 Intel Corporation
//
// SPDX-License-Identifier: MIT

import React from 'react';
import {Redirect, useParams} from "react-router";
import {useCookies } from "react-cookie";
tdowgiel marked this conversation as resolved.
Show resolved Hide resolved

export default function LoginWithTokenComponent(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add return type for the function JSX.Element

const { sessionId, token } = useParams()
const [cookies, setCookie] = useCookies(['sessionid', 'csrftoken'])
const expires = new Date(new Date().setFullYear(new Date().getFullYear() + 1))
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
setCookie('sessionid', sessionId, {path: '/', expires })
setCookie('csrftoken', token, {path: '/', expires})
tdowgiel marked this conversation as resolved.
Show resolved Hide resolved

if ( cookies['sessionid'] && cookies['csrftoken']) {
window.location.reload();
<Redirect to="/tasks" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose redirect after reload is useless. Moreover it should be wrapped into return ();
Maybe something like window.location = window.location.origin; would be more suitable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason. I need to reload window to apply this changes. However, i have fixed issue with endless reloading when wrong token, by moving this to useEffect

}
return(<></>);
};