summaryrefslogtreecommitdiff
path: root/src/Actions/auth.ts
blob: fb26c980d0c419ab6aaa6cb0d5dc1091a27fb61a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Dispatch } from 'redux';

const auth = {
    'login': () => (dispatch: Dispatch) => {
        dispatch({
            type: 'authLoad',
            loading: true,
        })
        fetch("https://www.ingress.com/intel", { "credentials": "include", "referrer": "https://intel.ingress.com/" })
            .then(r => r.text())
            .then(t => {
                const s1 = t.match(/gen_dashboard_(.+?)\.js/)
                if (s1 == null) {
                    throw new Error("V not found")
                }
                const v = s1[1]
                const s2 = t.match(/var PLAYER = (.+?)\;\n/)
                if (s2 == null) {
                    throw new Error("user not found")
                }
                const user = JSON.parse(s2[1])
                const s3 = t.match(/\<input type='hidden' name='csrfmiddlewaretoken' value='(.+?)' \/\>/)
                if (s3 == null) {
                    throw new Error("csrf not found")
                }
                const csrf = s3[1]
                return { v, user, csrf }
            // })
            // .then(({ v, user }) => {
            //     return CookieManager.get("https://intel.ingress.com")
            //         .then(cookies => {
            //             const csrf = cookies['csrftoken']
            //             return { v, csrf, user }
            //         })
            }).then(({ v, csrf, user }) =>
                dispatch({
                    type: 'authSet',
                    v, csrf, user
                })
            )
    }
}

export default auth