Skip to content

Commit e7b208c

Browse files
Merge branch 'oauth' of github.com:StoDevX/AAO-React-Native into oauth
2 parents 678303d + 18e8387 commit e7b208c

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

views/settings/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ export default class SettingsView extends React.Component {
5959
this.props.navigator.push({
6060
id: 'SISLoginView',
6161
index: this.props.route.index + 1,
62+
props: {
63+
onLoginComplete: status => this.setState({success: status}),
64+
},
6265
})
6366
}
6467

views/settings/login.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@ import startsWith from 'lodash/startsWith'
1515
import CookieManager from 'react-native-cookies'
1616
import LoadingView from '../components/loading'
1717

18+
const COOKIE_NAME = 'JSESSIONID'
1819
const HOME_URL = 'https://www.stolaf.edu/sis/index.cfm'
1920
const LOGIN_URL = 'https://www.stolaf.edu/sis/login.cfm'
2021
const AUTH_REJECTED_URL = 'https://www.stolaf.edu/sis/login.cfm?error=access_denied#'
2122

2223

2324
export 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

Comments
 (0)