@@ -15,16 +15,21 @@ import startsWith from 'lodash/startsWith'
1515import CookieManager from 'react-native-cookies'
1616import LoadingView from '../components/loading'
1717
18+ const COOKIE_NAME = 'JSESSIONID'
1819const HOME_URL = 'https://www.stolaf.edu/sis/index.cfm'
1920const LOGIN_URL = 'https://www.stolaf.edu/sis/login.cfm'
2021const AUTH_REJECTED_URL = 'https://www.stolaf.edu/sis/login.cfm?error=access_denied#'
2122
2223
2324export default class SISLoginView extends React . Component {
25+ static propTypes = {
26+ onLoginComplete : React . PropTypes . func ,
27+ } ;
28+
2429 state = {
2530 loggedIn : false ,
2631 cookieLoaded : false ,
27- }
32+ } ;
2833
2934 componentWillMount ( ) {
3035 this . loadCookie ( )
@@ -33,8 +38,8 @@ export default class SISLoginView extends React.Component {
3338 loadCookie = ( ) => {
3439 CookieManager . get ( HOME_URL , cookie => {
3540 let isAuthenticated
36- // If it differs, change `cookie.remember_me` to whatever the name for your persistent cookie is!!!
37- if ( cookie && cookie . indexOf ( 'remember_me' ) != - 1 ) {
41+
42+ if ( cookie && cookie . indexOf ( COOKIE_NAME ) != - 1 ) {
3843 isAuthenticated = true
3944 } else {
4045 isAuthenticated = false
@@ -44,6 +49,7 @@ export default class SISLoginView extends React.Component {
4449 loggedIn : isAuthenticated ,
4550 loadedCookie : true ,
4651 } )
52+ this . props . onLoginComplete ( isAuthenticated )
4753 } )
4854 }
4955
@@ -68,8 +74,13 @@ export default class SISLoginView extends React.Component {
6874 this . setState ( {
6975 loggedIn : true ,
7076 } )
77+ // TODO: figure out a way to do this that doesn't involve reaching
78+ // into the parent? But this migth be the good way. Think about it.
79+ this . props . onLoginComplete ( true )
80+ this . props . navigator . pop ( )
7181 } else if ( startsWith ( navState . url , AUTH_REJECTED_URL ) ) {
72- this . navigator . pop ( )
82+ this . props . onLoginComplete ( false )
83+ this . props . navigator . pop ( )
7384 }
7485 }
7586
0 commit comments