diff options
Diffstat (limited to 'src/Actions/auth.ts')
-rw-r--r-- | src/Actions/auth.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Actions/auth.ts b/src/Actions/auth.ts new file mode 100644 index 0000000..fb26c98 --- /dev/null +++ b/src/Actions/auth.ts @@ -0,0 +1,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
\ No newline at end of file |