-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8165c97
commit d0c6950
Showing
8 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Source code from | ||
// https://github.com/tommy351/eh-redux/blob/master/lib/screens/login/screen.dart | ||
// https://github.com/tommy351/eh-redux/blob/master/lib/utils/cookie.dart | ||
|
||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'dart:collection'; | ||
import 'dart:developer' as developer; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:webview_flutter/webview_flutter.dart'; | ||
|
||
Map<String, String> parseCookies(String cookies) { | ||
final result = HashMap<String, String>(); | ||
|
||
for (final cookie in cookies.split(';')) { | ||
final index = cookie.indexOf('='); | ||
|
||
if (index > -1) { | ||
final key = cookie.substring(0, index).trim(); | ||
final value = cookie.substring(index + 1).trim(); | ||
result[key] = value; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
// Input id-pwd login? | ||
// Or cookie? | ||
|
||
class LoginScreen extends StatefulWidget { | ||
@override | ||
_LoginScreenState createState() => _LoginScreenState(); | ||
} | ||
|
||
class _LoginScreenState extends State<LoginScreen> { | ||
static const _loginUrl = 'https://e-hentai.org/bounce_login.php'; | ||
|
||
final _webViewController = Completer<WebViewController>(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text("Login"), | ||
), | ||
body: WebView( | ||
initialUrl: _loginUrl, | ||
javascriptMode: JavascriptMode.unrestricted, | ||
onWebViewCreated: (controller) { | ||
_webViewController.complete(controller); | ||
}, | ||
onPageFinished: (url) { | ||
_checkCookie(); | ||
}, | ||
), | ||
); | ||
} | ||
|
||
Future<void> _checkCookie() async { | ||
final controller = await _webViewController.future; | ||
final cookieString = | ||
jsonDecode(await controller.evaluateJavascript('document.cookie')) | ||
as String; | ||
final cookies = parseCookies(cookieString); | ||
developer.log('Get cookies: $cookies'); | ||
|
||
if (cookies.containsKey('ipb_member_id')) { | ||
// await sessionStore.setSession(cookieString); | ||
// await _cookieManager.clearCookies(); | ||
Navigator.pop(context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters