Skip to content

Commit

Permalink
Merge pull request #3 from abc873693/develop
Browse files Browse the repository at this point in the history
Update to v0.0.3
  • Loading branch information
abc873693 authored Jun 10, 2019
2 parents 00a6262 + 7ced728 commit d408825
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 41 deletions.
Binary file added assets/images/ic_email.webp
Binary file not shown.
Binary file added assets/images/ic_fb.webp
Binary file not shown.
Binary file added assets/images/ic_github.webp
Binary file not shown.
6 changes: 6 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ PODS:
- FMDB (~> 2.7.2)
- url_launcher (0.0.1):
- Flutter
- webview_flutter (0.0.1):
- Flutter

DEPENDENCIES:
- firebase_analytics (from `.symlinks/plugins/firebase_analytics/ios`)
Expand All @@ -122,6 +124,7 @@ DEPENDENCIES:
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
- webview_flutter (from `.symlinks/plugins/webview_flutter/ios`)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
Expand Down Expand Up @@ -162,6 +165,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/sqflite/ios"
url_launcher:
:path: ".symlinks/plugins/url_launcher/ios"
webview_flutter:
:path: ".symlinks/plugins/webview_flutter/ios"

SPEC CHECKSUMS:
Firebase: 8d77bb33624ae9b62d745d82ec023de5f70f7e4f
Expand All @@ -188,6 +193,7 @@ SPEC CHECKSUMS:
shared_preferences: 1feebfa37bb57264736e16865e7ffae7fc99b523
sqflite: ff1d9da63c06588cc8d1faf7256d741f16989d5a
url_launcher: 0067ddb8f10d36786672aa0722a21717dba3a298
webview_flutter: 1aa7604e6cdb451a9b7ed2c37d5454c0b440246b

PODFILE CHECKSUM: ebd43b443038e611b86ede96e613bd6033c49497

Expand Down
2 changes: 2 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"${BUILT_PRODUCTS_DIR}/shared_preferences/shared_preferences.framework",
"${BUILT_PRODUCTS_DIR}/sqflite/sqflite.framework",
"${BUILT_PRODUCTS_DIR}/url_launcher/url_launcher.framework",
"${BUILT_PRODUCTS_DIR}/webview_flutter/webview_flutter.framework",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
Expand All @@ -318,6 +319,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sqflite.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/url_launcher.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/webview_flutter.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down
7 changes: 7 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>io.flutter.embedded_views_preview</key>
<string>YES</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
Expand Down
11 changes: 11 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import 'package:nsysu_ap/utils/app_localizations.dart';
import 'package:nsysu_ap/utils/firebase_analytics_utils.dart';
import 'package:nsysu_ap/utils/utils.dart';

import 'pages/about/about_us_page.dart';
import 'pages/about/open_source_page.dart';
import 'pages/course_page.dart';
import 'pages/home_page.dart';
import 'pages/setting_page.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
Expand All @@ -37,7 +43,12 @@ class MyApp extends StatelessWidget {
debugShowCheckedModeBanner: false,
routes: <String, WidgetBuilder>{
Navigator.defaultRouteName: (context) => LoginPage(),
HomePage.routerName: (context) => HomePage(),
CoursePage.routerName: (context) => CoursePage(),
ScorePage.routerName: (context) => ScorePage(),
SettingPage.routerName: (context) => SettingPage(),
AboutUsPage.routerName: (context) => AboutUsPage(),
OpenSourcePage.routerName: (context) => OpenSourcePage(),
},
theme: ThemeData(
brightness: brightness,
Expand Down
25 changes: 16 additions & 9 deletions lib/pages/course_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class CoursePageState extends State<CoursePage>

bool isOffline = false;

List<TableRow> list = [];

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -334,17 +336,22 @@ class CoursePageState extends State<CoursePage>
state = _State.loading;
});
var prefs = await SharedPreferences.getInstance();
courseData = await Helper.instance.getCourseData(
Helper.instance
.getCourseData(
prefs.getString(Constants.PREF_USERNAME),
semesterData.semester.value,
);
setState(() {
if (courseData.status == 200)
state = _State.finish;
else if (courseData.status == 204)
state = _State.empty;
else
state = _State.error;
)
.then((courseData) {
this.courseData = courseData;
if (mounted)
setState(() {
if (courseData.status == 200)
state = _State.finish;
else if (courseData.status == 204)
state = _State.empty;
else
state = _State.error;
});
});
}
}
63 changes: 44 additions & 19 deletions lib/pages/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:nsysu_ap/widgets/progress_dialog.dart';
import 'package:nsysu_ap/widgets/yes_no_dialog.dart';
import 'package:package_info/package_info.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:webview_flutter/webview_flutter.dart';

import 'home_page.dart';

Expand All @@ -39,6 +40,8 @@ class LoginPageState extends State<LoginPage>

final encrypter = Encrypter(AES(Constants.key, mode: AESMode.cbc));

var _controller;

@override
void initState() {
super.initState();
Expand All @@ -65,22 +68,39 @@ class LoginPageState extends State<LoginPage>
return OrientationBuilder(builder: (_, orientation) {
return Scaffold(
resizeToAvoidBottomPadding: orientation == Orientation.portrait,
backgroundColor: Resource.Colors.blue,
body: Center(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 30.0),
child: orientation == Orientation.portrait
? Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceAround,
mainAxisSize: MainAxisSize.min,
children: _renderContent(orientation),
)
: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: _renderContent(orientation),
),
),
body: Stack(
alignment: Alignment(0, 0),
children: <Widget>[
SizedBox(
child: WebView(
initialUrl: 'https://sso.nsysu.edu.tw/index.php/passport/login',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) {
_controller = controller;
},
onPageFinished: (s) {
//print('onPageFinished = $s');
},
debuggingEnabled: true,
),
),
Container(
alignment: Alignment(0, 0),
color: Resource.Colors.blue,
padding: EdgeInsets.symmetric(horizontal: 30.0),
child: orientation == Orientation.portrait
? Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceAround,
mainAxisSize: MainAxisSize.min,
children: _renderContent(orientation),
)
: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: _renderContent(orientation),
),
)
],
),
);
});
Expand Down Expand Up @@ -410,19 +430,24 @@ class LoginPageState extends State<LoginPage>

if (Platform.isAndroid || Platform.isIOS)
prefs.setString(Constants.PREF_USERNAME, _username.text);
var base64md5Password = await _controller
?.evaluateJavascript('base64_md5("${_password.text}")');
base64md5Password = base64md5Password.replaceAll('\"', '');
Helper.instance
.login(_username.text, _password.text)
.selcrsLogin(_username.text, base64md5Password)
.then((response) async {
if (Navigator.canPop(context)) Navigator.pop(context, 'dialog');
if (Platform.isAndroid || Platform.isIOS) {
if (response == 403) {
Utils.showToast(context, app.loginFail);
} else if (Platform.isAndroid || Platform.isIOS) {
prefs.setString(Constants.PREF_USERNAME, _username.text);
if (isRememberPassword) {
await prefs.setString(Constants.PREF_PASSWORD,
encrypter.encrypt(_password.text, iv: Constants.iv).base64);
}
prefs.setBool(Constants.PREF_IS_OFFLINE_LOGIN, false);
_navigateToFilterObject(context);
}
_navigateToFilterObject(context);
}).catchError((e) {
if (Navigator.canPop(context)) Navigator.pop(context, 'dialog');
});
Expand Down
24 changes: 15 additions & 9 deletions lib/pages/score_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,21 @@ class ScorePageState extends State<ScorePage>
setState(() {
state = _State.loading;
});
scoreData = await Helper.instance.getScoreData(
scoreSemesterData.year.value, scoreSemesterData.semester.value);
setState(() {
if (scoreData.status == 200) {
state = _State.finish;
} else if (scoreData.status == 204) {
state = _State.empty;
} else {
state = _State.error;
Helper.instance
.getScoreData(
scoreSemesterData.year.value, scoreSemesterData.semester.value)
.then((scoreData) {
this.scoreData = scoreData;
if (mounted) {
setState(() {
if (scoreData.status == 200) {
state = _State.finish;
} else if (scoreData.status == 204) {
state = _State.empty;
} else {
state = _State.error;
}
});
}
});
}
Expand Down
46 changes: 43 additions & 3 deletions lib/utils/helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,46 @@ class Helper {
}
}

Future<int> selcrsLogin(String username, String password) async {
print(DateTime.now());
bool score = true, course = true;
var scoreResponse = await http.post(
'http://selcrs.nsysu.edu.tw/scoreqry/sco_query_prs_sso2.asp',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: {
'SID': username,
'PASSWD': password,
'ACTION': '0',
'INTYPE': '1',
},
);
String text = big5.decode(scoreResponse.bodyBytes);
if (text.contains("資料錯誤請重新輸入")) score = false;
//print('text = ${text}');
scoreCookie = scoreResponse.headers['set-cookie'];
var courseResponse = await http.post(
'http://selcrs.nsysu.edu.tw/menu4/Studcheck_sso2.asp',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: {
'stuid': username,
'SPassword': password,
},
);
text = big5.decode(courseResponse.bodyBytes);
if (text.contains("學號碼密碼不符")) course = false;
courseCookie = courseResponse.headers['set-cookie'];
//print('text = ${text}');
print(DateTime.now());
if (score && course)
return 200;
else
return 403;
}

Future<int> login(String username, String password) async {
print(DateTime.now());
var response = await http.post(
Expand Down Expand Up @@ -74,7 +114,7 @@ class Helper {
headers: {'Cookie': courseCookie},
);
String text = big5.decode(response.bodyBytes);
print('text = ${text}');
//print('text = ${text}');
var document = parse(text, encoding: 'BIG-5');
var tdDoc = document.getElementsByTagName('td');
var userInfo = UserInfo();
Expand Down Expand Up @@ -133,7 +173,7 @@ class Helper {
status: (trDoc.length == 0) ? 204 : 200,
messages: '',
courseTables: (trDoc.length == 0) ? null : CourseTables());
print(DateTime.now());
//print(DateTime.now());
for (var i = 0; i < trDoc.length; i++) {
var tdDoc = trDoc[i].getElementsByTagName('td');
if (i == 0) continue;
Expand Down Expand Up @@ -174,7 +214,7 @@ class Helper {
if (courseData.courseTables.sunday.length == 0)
courseData.courseTables.sunday = null;
}
print(DateTime.now());
//print(DateTime.now());
return courseData;
}

Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
webview_flutter:
dependency: "direct main"
description:
name: webview_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.9+1"
sdks:
dart: ">=2.2.2 <3.0.0"
flutter: ">=1.5.0 <2.0.0"
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: nsysu_ap
description: NSYSU AP

version: 0.0.2+2
version: 0.0.3+3

environment:
sdk: ">=2.2.2 <3.0.0"
Expand All @@ -16,6 +16,7 @@ dependencies:
shared_preferences: ^0.5.3+1
package_info: ^0.4.0+4
url_launcher: ^5.0.3
webview_flutter: ^0.3.9+1
firebase_core: ^0.4.0+3
firebase_analytics: ^3.0.2
firebase_remote_config: ^0.2.0+2
Expand Down

0 comments on commit d408825

Please sign in to comment.