@@ -6,7 +6,10 @@ import { FormattedMessage, injectIntl } from 'react-intl';
66import Button from '../../components/widgets/TheButton' ;
77import Box from '../../components/widgets/Box' ;
88import Callout from '../../components/widgets/Callout' ;
9+ import Explanation from '../../components/widgets/Explanation' ;
910import { LinkIcon , LoadingIcon , SuccessIcon } from '../../components/icons' ;
11+ import NiceCheckbox from '../../components/forms/NiceCheckbox' ;
12+
1013import { externalLogin , externalLoginFailed , statusTypes } from '../../redux/modules/auth.js' ;
1114import { statusSelector , loginErrorSelector } from '../../redux/selectors/auth.js' ;
1215import { hasErrorMessage , getErrorMessage } from '../../locales/apiErrorMessages.js' ;
@@ -17,22 +20,27 @@ export const openPopupWindow = url =>
1720 : null ;
1821
1922class ExternalLoginBox extends Component {
20- state = { pending : false , lastError : null } ;
23+ state = { pending : false , lastError : null , short : false } ;
2124
2225 constructor ( props ) {
2326 super ( props ) ;
2427 this . popupWindow = null ;
2528 this . pollPopupClosed = null ;
2629 }
2730
31+ setShort = ( ) => {
32+ this . setState ( { short : ! this . state . short } ) ;
33+ } ;
34+
2835 // Handle the messages from our popup window...
2936 messageHandler = e => {
37+ const { shortSessionConfig, login } = this . props ;
3038 const token = e . data ; // the message should be the external JWT token
3139
3240 if ( token !== null && e . source === this . popupWindow && this . popupWindow !== null ) {
3341 // cancel the window and the interval
3442 this . popupWindow . postMessage ( 'received' , e . origin ) ;
35- this . props . login ( token , this . popupWindow , error => {
43+ login ( token , this . state . short && shortSessionConfig ? shortSessionConfig * 60 : null , this . popupWindow , error => {
3644 if ( hasErrorMessage ( error ) ) {
3745 this . setState ( { lastError : error } ) ;
3846 }
@@ -93,6 +101,7 @@ class ExternalLoginBox extends Component {
93101 const {
94102 name,
95103 helpUrl,
104+ shortSessionConfig = null ,
96105 loginStatus,
97106 loginError,
98107 intl : { formatMessage } ,
@@ -150,6 +159,18 @@ class ExternalLoginBox extends Component {
150159 </ p >
151160 ) }
152161
162+ { shortSessionConfig && shortSessionConfig > 0 && (
163+ < NiceCheckbox name = "external.short" checked = { this . state . short } onChange = { this . setShort } >
164+ < FormattedMessage id = "app.loginForm.short" defaultMessage = "Short session" /> ({ shortSessionConfig } min)
165+ < Explanation id = "loginForm.shortSession" >
166+ < FormattedMessage
167+ id = "app.loginForm.short.explanation"
168+ defaultMessage = "Use short session on public computers to reduce the risk of unauthorized access to your account (if you forget to log out)."
169+ />
170+ </ Explanation >
171+ </ NiceCheckbox >
172+ ) }
173+
153174 { ! pending && ( loginStatus === statusTypes . LOGIN_FAILED || this . state . lastError ) && (
154175 < Callout variant = "danger" className = "mt-3" >
155176 { loginError || this . state . lastError ? (
@@ -170,6 +191,7 @@ ExternalLoginBox.propTypes = {
170191 url : PropTypes . string . isRequired ,
171192 service : PropTypes . string . isRequired ,
172193 helpUrl : PropTypes . string ,
194+ shortSessionConfig : PropTypes . number ,
173195 loginStatus : PropTypes . string ,
174196 loginError : PropTypes . object ,
175197 login : PropTypes . func . isRequired ,
@@ -184,8 +206,8 @@ export default connect(
184206 loginError : loginErrorSelector ( state , service ) ,
185207 } ) ,
186208 ( dispatch , { service, afterLogin = null } ) => ( {
187- login : ( token , popupWindow , errorHandler = null ) => {
188- const promise = dispatch ( externalLogin ( service , token , popupWindow ) ) ;
209+ login : ( token , expiration , popupWindow , errorHandler = null ) => {
210+ const promise = dispatch ( externalLogin ( service , token , expiration , popupWindow ) ) ;
189211 return ( afterLogin ? promise . then ( afterLogin ) : promise ) . catch ( e => errorHandler && errorHandler ( e ) ) ;
190212 } ,
191213 fail : ( ) => dispatch ( externalLoginFailed ( service ) ) ,
0 commit comments