From 52ce0ef0201ee18fa384b8fa6227b766d9a0c1c1 Mon Sep 17 00:00:00 2001 From: NLOG Date: Sat, 24 Oct 2020 16:50:35 +0900 Subject: [PATCH] =?UTF-8?q?"=EB=A7=A4=EC=9D=BC=20=ED=95=9C=20=EB=B2=88?= =?UTF-8?q?=EB=A7=8C=20=EC=9E=90=EB=8F=99=20=EC=A0=9C=EC=B6=9C"=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/type/JagaJindanData.dart | 11 +++++++---- lib/ui/MainPage.dart | 5 +++-- lib/ui/MainPageState.dart | 2 +- lib/ui/component/JagaJindanForm.dart | 3 ++- lib/ui/component/{credit.dart => setting.dart} | 10 ++++++++++ lib/util/sendSurvey.dart | 18 ++++++++++++++---- 6 files changed, 37 insertions(+), 12 deletions(-) rename lib/ui/component/{credit.dart => setting.dart} (89%) diff --git a/lib/type/JagaJindanData.dart b/lib/type/JagaJindanData.dart index 45658f5..6bb7df0 100644 --- a/lib/type/JagaJindanData.dart +++ b/lib/type/JagaJindanData.dart @@ -1,6 +1,6 @@ class JagaJindanData { String name, birthday, school, edu, password; - bool force, agree = false, startup = false, useNotification = false; + bool force, agree = false, startup = false, useNotification = false, submitLimitation = false; static JagaJindanData readFromJSON(dynamic json) { return new JagaJindanData( @@ -12,11 +12,13 @@ class JagaJindanData { json["force"] ?? false, json["agree"] ?? false, json["startup"] ?? false, - json["noti"] ?? false); + json["noti"] ?? false, + json["submitLimitation"] ?? false + ); } JagaJindanData(this.name, this.birthday, this.school, this.edu, this.password, - this.force, this.agree, this.startup, this.useNotification); + this.force, this.agree, this.startup, this.useNotification, this.submitLimitation); dynamic toJSON() { return { @@ -28,7 +30,8 @@ class JagaJindanData { "force": this.force, "agree": this.agree, "startup": this.startup, - "noti": this.useNotification + "noti": this.useNotification, + "submitLimitation": this.submitLimitation }; } } diff --git a/lib/ui/MainPage.dart b/lib/ui/MainPage.dart index 3348f68..75dcb84 100644 --- a/lib/ui/MainPage.dart +++ b/lib/ui/MainPage.dart @@ -10,7 +10,8 @@ import 'component/agree.dart'; class MainPage extends StatefulWidget { JagaJindanData data = - JagaJindanData("", "", "", "", "", false, false, false, false); + JagaJindanData("", "", "", "", "", false, false, false, false, false); + TextEditingController nameController = TextEditingController(), birthdayController = TextEditingController(), schoolController = TextEditingController(), @@ -28,7 +29,7 @@ class MainPage extends StatefulWidget { this.eduController.text = this.data.edu; this.passwordController.text = this.data.password; - if (this.data.startup) sendSurvey(this.data); + if (this.data.startup) sendSurvey(this.data, true); agree(pageState); await pageState.setState(() {}); diff --git a/lib/ui/MainPageState.dart b/lib/ui/MainPageState.dart index 6b0203c..b848a63 100644 --- a/lib/ui/MainPageState.dart +++ b/lib/ui/MainPageState.dart @@ -1,7 +1,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:jaga_jindan/ui/component/JagaJindanForm.dart'; -import 'package:jaga_jindan/ui/component/credit.dart'; +import 'package:jaga_jindan/ui/component/setting.dart'; import 'package:jaga_jindan/util/school.dart'; import 'package:jaga_jindan/util/sendSurvey.dart'; diff --git a/lib/ui/component/JagaJindanForm.dart b/lib/ui/component/JagaJindanForm.dart index 0bd8112..d89d94e 100644 --- a/lib/ui/component/JagaJindanForm.dart +++ b/lib/ui/component/JagaJindanForm.dart @@ -155,7 +155,8 @@ JagaJindanForm(MainPageState state) { child: ListBody( children: [ Text('앱 시작 시 자가진단 설문을 제출합니다.'), - Text('특정 시각마다 제출하는 기능은 계획 중에 있습니다.'), + Text('특정 시각마다 제출하는 기능은 계획 중 입니다.'), + Text('설정에서 "매일 한 번만 자동 제출" 옵션을 활성화하면 매일 한 번만 제출할 수 있습니다.'), ], ), ), diff --git a/lib/ui/component/credit.dart b/lib/ui/component/setting.dart similarity index 89% rename from lib/ui/component/credit.dart rename to lib/ui/component/setting.dart index b19b322..29ead51 100644 --- a/lib/ui/component/credit.dart +++ b/lib/ui/component/setting.dart @@ -47,6 +47,16 @@ showCredit(MainPageState state) async { state.widget.writeJSON(); }); }), + CheckboxListTile( + contentPadding: EdgeInsets.zero, + title: const Text('매일 한 번만 자동 제출'), + value: state.widget.data.submitLimitation, + onChanged: (bool value) { + _setState(() { + state.widget.data.submitLimitation = value; + state.widget.writeJSON(); + }); + }), Divider( color: Colors.black38, height: 50, diff --git a/lib/util/sendSurvey.dart b/lib/util/sendSurvey.dart index 789f499..d097e99 100644 --- a/lib/util/sendSurvey.dart +++ b/lib/util/sendSurvey.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:flutter/widgets.dart'; import 'package:http/http.dart' as http; import 'package:jaga_jindan/type/JagaJindanData.dart'; import 'package:jaga_jindan/util/RSAEncrypt.dart'; @@ -13,7 +14,7 @@ void showSurveyResult( toast(message); } -void sendSurvey(JagaJindanData credentials) async { +void sendSurvey(JagaJindanData credentials, [bool byAutomatic = false]) async { try { String jwt = jsonDecode((await http.post( 'https://${credentials.edu}hcs.eduro.go.kr/v2/findUser', @@ -71,14 +72,23 @@ void sendSurvey(JagaJindanData credentials) async { var userNo = int.parse(users[0]['userPNo']); String org = users[0]['orgCode']; - jwt = jsonDecode((await http.post( + var userInfo = jsonDecode((await http.post( 'https://${credentials.edu}hcs.eduro.go.kr/v2/getUserInfo', body: jsonEncode({'userPNo': userNo, 'orgCode': org}), headers: { 'Authorization': jwt, 'Content-Type': 'application/json' })) - .body)['token']; + .body); + + var submittedDate = DateTime.parse(userInfo["registerDtm"]); + + if (submittedDate.day == DateTime.now().day && byAutomatic && credentials.submitLimitation) { + showSurveyResult(false, "이미 제출한 기록이 있어 자동 제출을 취소했습니다.", credentials); + return; + } + + jwt = userInfo['token']; var res = await http.post( 'https://${credentials.edu}hcs.eduro.go.kr/registerServey', @@ -109,7 +119,7 @@ void sendSurvey(JagaJindanData credentials) async { true, "자가진단 설문이 ${DateTime.now().toString().substring(0, 19)}에 제출되었습니다.", credentials); - } catch (e) { + } catch (e, s) { showSurveyResult( false, "인증 정보를 한번 더 확인해주세요.\n오류가 계속 발생하는 경우 개발자에게 알려주세요.", credentials); //toast(e.toString());