Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
RIT_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
고원빈
2021-05-25 12:55:59 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ba1656c2a4f5d75ee9ec9064e255bea795576fdd
ba1656c2
1 parent
be50621b
[frontend] login authorization 문제 해결
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
132 additions
and
47 deletions
frontend/README.md
frontend/flutter_application_1/lib/src/repository/getMedicineApi.dart
frontend/flutter_application_1/lib/src/screens/DashBoard.dart
frontend/flutter_application_1/lib/src/screens/Register/BottleList.dart
frontend/flutter_application_1/lib/src/screens/Register/DetailMedicine.dart
frontend/flutter_application_1/lib/src/screens/Register/HubList.dart
frontend/flutter_application_1/lib/src/screens/Register/RegisterBottle.dart
frontend/flutter_application_1/lib/src/screens/Register/RegsiterHub.dart
frontend/flutter_application_1/lib/src/screens/Register/SearchMedicine.dart
frontend/flutter_application_1/lib/src/screens/Register/SignInPage.dart
frontend/flutter_application_1/lib/src/screens/models/Bottle.dart
frontend/flutter_application_1/lib/src/screens/models/User.dart
frontend/flutter_application_1/lib/src/utils/user_secure_stoarge.dart
frontend/flutter_application_1/pubspec.lock
frontend/flutter_application_1/pubspec.yaml
frontend/README.md
View file @
ba1656c
...
...
@@ -82,3 +82,5 @@ appbar 관련 디자인은 추후 구현 예정
+
메인 페이지 데이터 출력 완료
### 2021-05-25
+
로그인 권한 문제 해결
\ No newline at end of file
...
...
frontend/flutter_application_1/lib/src/repository/getMedicineApi.dart
0 → 100644
View file @
ba1656c
File mode changed
frontend/flutter_application_1/lib/src/screens/DashBoard.dart
View file @
ba1656c
...
...
@@ -3,6 +3,7 @@ import 'dart:convert';
import
'package:shared_preferences/shared_preferences.dart'
;
import
'package:http/http.dart'
as
http
;
import
'package:flutter_dotenv/flutter_dotenv.dart'
;
import
'package:intl/intl.dart'
;
import
'models/Bottle.dart'
;
import
'models/Medicine.dart'
;
...
...
@@ -28,6 +29,7 @@ class _DashBoardState extends State<DashBoard> {
Bottle
_bottleinformation
=
new
Bottle
();
int
_selectedIndex
=
0
;
Medicine
_medicineInformation
=
new
Medicine
();
Widget
build
(
BuildContext
context
)
{
_selectedIndex
=
widget
.
pageNumber
;
_medicineInformation
=
widget
.
medicineInformation
;
...
...
@@ -125,17 +127,6 @@ class _DashBoardState extends State<DashBoard> {
}
Widget
mainpage
(
BuildContext
context
,
Medicine
medicineInformation
)
{
Future
<
String
>
getHubList
()
async
{
SharedPreferences
prefs
=
await
SharedPreferences
.
getInstance
();
http
.
Response
response
=
await
http
.
get
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'hub'
));
print
(
response
.
statusCode
);
}
//현재 접속 중인 허브 리스트 id와 약병 리스트 id 출력
//약 상세 정보 가져오기 --> 이건 Detail Medicine에서 가져 오면 됨
final
Size
size
=
MediaQuery
.
of
(
context
).
size
;
return
Scaffold
(
backgroundColor:
Colors
.
white
,
...
...
@@ -578,7 +569,8 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) {
child:
Text
(
bottleinformation
.
recentOpen
==
null
?
'-'
:
bottleinformation
.
recentOpen
,
:
DateFormat
.
Hm
()
.
format
(
bottleinformation
.
recentOpen
),
textAlign:
TextAlign
.
center
,
textScaleFactor:
1.0
,
style:
TextStyle
(
...
...
@@ -676,9 +668,9 @@ Widget outerInformationpage(BuildContext context, Bottle bottleinformation) {
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Text
(
bottleinformation
.
toString
()
==
null
bottleinformation
.
dosage
==
null
?
'-'
:
bottleinformation
.
toString
(),
:
bottleinformation
.
dosage
.
toString
(),
textAlign:
TextAlign
.
center
,
textScaleFactor:
1.0
,
style:
TextStyle
(
...
...
frontend/flutter_application_1/lib/src/screens/Register/BottleList.dart
View file @
ba1656c
...
...
@@ -6,6 +6,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
import
'../models/Bottle.dart'
;
import
'../DashBoard.dart'
;
import
'../models/Medicine.dart'
;
import
'../../utils/user_secure_stoarge.dart'
;
class
BottleList
extends
StatefulWidget
{
List
<
Bottle
>
bottlelist
;
...
...
@@ -21,10 +22,12 @@ class _BottleListState extends State<BottleList> {
Medicine
_medicineinformation
=
new
Medicine
();
Future
<
Bottle
>
getbottle
(
int
index
)
async
{
http
.
Response
response
=
await
http
.
get
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
String
usertoken
=
await
UserSecureStorage
.
getUserToken
();
http
.
Response
response
=
await
http
.
get
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'bottle/'
+
widget
.
bottlelist
[
index
].
bottleId
.
toString
()));
widget
.
bottlelist
[
index
].
bottleId
.
toString
()),
headers:
{
"authorization"
:
usertoken
});
if
(
response
.
statusCode
==
200
)
{
Map
<
String
,
dynamic
>
jsonData
=
jsonDecode
(
response
.
body
);
...
...
@@ -34,10 +37,13 @@ class _BottleListState extends State<BottleList> {
}
Future
<
Bottle
>
getmedicine
(
int
index
)
async
{
http
.
Response
medicineresponse
=
await
http
.
get
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
String
usertoken
=
await
UserSecureStorage
.
getUserToken
();
http
.
Response
medicineresponse
=
await
http
.
get
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'medicine/'
+
widget
.
bottlelist
[
index
].
medicineId
.
toString
()));
widget
.
bottlelist
[
index
].
medicineId
.
toString
()),
headers:
{
"authorization"
:
usertoken
},
);
if
(
medicineresponse
.
statusCode
==
200
)
{
Map
<
String
,
dynamic
>
data
=
jsonDecode
(
medicineresponse
.
body
);
_medicineinformation
=
Medicine
.
fromJson
(
data
);
...
...
@@ -91,11 +97,8 @@ class _BottleListState extends State<BottleList> {
),
trailing:
Icon
(
Icons
.
arrow_forward
),
onTap:
()
async
{
getbottle
(
index
);
getmedicine
(
index
);
print
(
_bottleinformation
);
print
(
_medicineinformation
);
await
getbottle
(
index
);
await
getmedicine
(
index
);
Navigator
.
push
(
context
,
MaterialPageRoute
(
...
...
@@ -104,8 +107,10 @@ class _BottleListState extends State<BottleList> {
bottleInformation:
_bottleinformation
,
medicineInformation:
_medicineinformation
,
),
));
}),
),
);
},
),
);
},
separatorBuilder:
(
BuildContext
contetx
,
int
index
)
=>
...
...
frontend/flutter_application_1/lib/src/screens/Register/DetailMedicine.dart
View file @
ba1656c
...
...
@@ -6,6 +6,7 @@ import 'dart:convert';
import
'package:http/http.dart'
as
http
;
import
'package:flutter_dotenv/flutter_dotenv.dart'
;
import
'../models/Medicine.dart'
;
import
'../../utils/user_secure_stoarge.dart'
;
class
DetailMedicine
extends
StatefulWidget
{
Medicine
searchMedicine
;
...
...
@@ -20,10 +21,14 @@ class _DetailMedicineState extends State<DetailMedicine> {
final
medicineDosageController
=
TextEditingController
();
//약 등록
Future
<
String
>
patchMedcine
()
async
{
String
usertoken
=
await
UserSecureStorage
.
getUserToken
();
http
.
Response
response
=
await
http
.
patch
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'bottle/'
+
widget
.
bottleId
),
headers:
{
"Content-Type"
:
"application/json"
},
headers:
{
"Content-Type"
:
"application/json"
,
"authorization"
:
usertoken
},
body:
jsonEncode
({
'medicineId'
:
widget
.
searchMedicine
.
medicineId
,
'dosage'
:
medicineDosageController
.
text
...
...
frontend/flutter_application_1/lib/src/screens/Register/HubList.dart
View file @
ba1656c
...
...
@@ -7,6 +7,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
import
'RegisterBottle.dart'
;
import
'../models/Bottle.dart'
;
import
'BottleList.dart'
;
import
'../../utils/user_secure_stoarge.dart'
;
class
HubList
extends
StatefulWidget
{
List
<
int
>
hublist
;
...
...
@@ -20,8 +21,13 @@ class _HubListState extends State<HubList> {
List
<
Bottle
>
_bottleList
=
new
List
<
Bottle
>();
//Get BottleList
Future
<
String
>
getBottleList
(
int
hubid
)
async
{
http
.
Response
response
=
await
http
.
get
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'bottle/hub/'
+
hubid
.
toString
()));
String
usertoken
=
await
UserSecureStorage
.
getUserToken
();
http
.
Response
response
=
await
http
.
get
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'bottle/hub/'
+
hubid
.
toString
()),
headers:
{
"authorization"
:
usertoken
},
);
print
(
response
.
body
);
if
(
_bottleList
.
length
!=
0
)
{
_bottleList
.
clear
();
}
...
...
frontend/flutter_application_1/lib/src/screens/Register/RegisterBottle.dart
View file @
ba1656c
...
...
@@ -6,6 +6,7 @@ import 'package:http/http.dart' as http;
import
'package:flutter_dotenv/flutter_dotenv.dart'
;
import
'SearchMedicine.dart'
;
import
'../../utils/user_secure_stoarge.dart'
;
class
RegisterBottle
extends
StatefulWidget
{
final
String
hubid
;
...
...
@@ -18,9 +19,13 @@ class _RegisterBottleState extends State<RegisterBottle> {
final
medicineBottleIDController
=
TextEditingController
();
Future
<
String
>
registerhub_Validate
()
async
{
String
usertoken
=
await
UserSecureStorage
.
getUserToken
();
http
.
Response
bottleresponse
=
await
http
.
post
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'bottle'
),
headers:
{
"Content-Type"
:
"application/json"
},
headers:
{
"Content-Type"
:
"application/json"
,
"authorization"
:
usertoken
},
body:
jsonEncode
({
'bottleId'
:
medicineBottleIDController
.
text
,
'hubId'
:
widget
.
hubid
...
...
frontend/flutter_application_1/lib/src/screens/Register/RegsiterHub.dart
View file @
ba1656c
...
...
@@ -5,6 +5,7 @@ import 'package:http/http.dart' as http;
import
'package:flutter_dotenv/flutter_dotenv.dart'
;
import
'RegisterBottle.dart'
;
import
'../../utils/user_secure_stoarge.dart'
;
class
RegisterHub
extends
StatefulWidget
{
@override
...
...
@@ -18,9 +19,13 @@ class _RegisterHubState extends State<RegisterHub> {
final
medicineHubHostController
=
TextEditingController
();
Future
<
String
>
registerhub_Validate
()
async
{
http
.
Response
hubresponse
=
await
http
.
post
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'hub'
),
headers:
{
"Content-Type"
:
"application/json"
},
String
usertoken
=
await
UserSecureStorage
.
getUserToken
();
http
.
Response
hubresponse
=
await
http
.
post
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'hub'
),
headers:
{
"Content-Type"
:
"application/json"
,
"authorization"
:
usertoken
},
body:
jsonEncode
({
'hubId'
:
medicineHubIDController
.
text
,
'host'
:
medicineHubHostController
.
text
,
...
...
frontend/flutter_application_1/lib/src/screens/Register/SearchMedicine.dart
View file @
ba1656c
...
...
@@ -5,6 +5,7 @@ import 'package:http/http.dart' as http;
import
'package:flutter_dotenv/flutter_dotenv.dart'
;
import
'../models/Medicine.dart'
;
import
'DetailMedicine.dart'
;
import
'../../utils/user_secure_stoarge.dart'
;
class
SearchMedicine
extends
StatefulWidget
{
String
bottleId
;
...
...
@@ -19,9 +20,13 @@ class _SearchMedicineState extends State<SearchMedicine> {
final
medicineCompanyController
=
TextEditingController
();
Future
<
String
>
postMeicineList
()
async
{
http
.
Response
response
=
await
http
.
post
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'medicine'
),
headers:
{
"Content-Type"
:
"application/json"
},
String
usertoken
=
await
UserSecureStorage
.
getUserToken
();
http
.
Response
response
=
await
http
.
post
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'medicine'
),
headers:
{
"Content-Type"
:
"application/json"
,
"authorization"
:
usertoken
},
body:
jsonEncode
({
'name'
:
medicineNameController
.
text
,
'company'
:
medicineCompanyController
.
text
,
...
...
frontend/flutter_application_1/lib/src/screens/Register/SignInPage.dart
View file @
ba1656c
...
...
@@ -3,10 +3,11 @@ import 'package:flutter/material.dart';
import
'package:flutter/services.dart'
;
import
'package:http/http.dart'
as
http
;
import
'package:flutter_dotenv/flutter_dotenv.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
import
'../
DashBoard
.dart'
;
import
'../
../utils/user_secure_stoarge
.dart'
;
import
'HubList.dart'
;
import
'RegsiterHub.dart'
;
import
'../models/User.dart'
;
class
SignInPage
extends
StatefulWidget
{
@override
...
...
@@ -18,9 +19,11 @@ class _SignInPageState extends State<SignInPage> {
bool
passwordVisible
=
false
;
bool
_validateEmail
=
false
;
bool
_validatePassword
=
false
;
final
emailController
=
TextEditingController
();
final
passwordController
=
TextEditingController
();
User
user
;
List
<
int
>
_hublist
=
new
List
<
int
>();
//허브이름을 만들어야 할 것 같은데 임시로 허브 id만 고르게 함
//Login 함수
...
...
@@ -28,12 +31,18 @@ class _SignInPageState extends State<SignInPage> {
http
.
Response
response
=
await
http
.
post
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'auth/login'
),
headers:
{
"Content-Type"
:
"application/json"
},
body:
jsonEncode
({
body:
jsonEncode
(
{
'userId'
:
_email
,
'password'
:
_password
,
}));
},
),
);
if
(
response
.
statusCode
==
200
)
{
Map
<
String
,
dynamic
>
data
=
jsonDecode
(
response
.
body
);
user
=
User
.
fromJson
(
data
);
print
(
user
);
return
"로그인 성공"
;
}
else
if
(
response
.
statusCode
==
400
)
{
return
"올바르지 않은 아이디 및 패스워드"
;
...
...
@@ -44,11 +53,14 @@ class _SignInPageState extends State<SignInPage> {
//Get Bottle List 함수
Future
<
String
>
getHubList
()
async
{
http
.
Response
response
=
await
http
.
get
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'hub'
));
String
usertoken
=
await
UserSecureStorage
.
getUserToken
();
http
.
Response
response
=
await
http
.
get
(
Uri
.
encodeFull
(
DotEnv
().
env
[
'SERVER_URL'
]
+
'hub'
),
headers:
{
"authorization"
:
usertoken
},
);
List
<
dynamic
>
values
=
new
List
<
dynamic
>();
print
(
values
);
if
(
_hublist
.
length
!=
0
)
{
_hublist
.
clear
();
}
...
...
@@ -228,6 +240,8 @@ class _SignInPageState extends State<SignInPage> {
RegisterHub
(),
));
}
else
if
(
result
==
"get완료"
)
{
UserSecureStorage
.
setUserToken
(
user
.
token
);
Navigator
.
push
(
context
,
MaterialPageRoute
(
...
...
frontend/flutter_application_1/lib/src/screens/models/Bottle.dart
View file @
ba1656c
...
...
@@ -3,7 +3,7 @@ class Bottle {
final
int
temperature
;
final
int
humidity
;
final
int
balance
;
final
String
recentOpen
;
final
DateTime
recentOpen
;
final
int
medicineId
;
final
int
hubId
;
final
int
dosage
;
...
...
@@ -24,7 +24,7 @@ class Bottle {
temperature:
parsedJson
[
'temperature'
],
humidity:
parsedJson
[
'humidity'
],
balance:
parsedJson
[
'balance'
],
recentOpen:
parsedJson
[
'recentOpen'
]
,
recentOpen:
DateTime
.
parse
(
parsedJson
[
'recentOpen'
])
,
medicineId:
parsedJson
[
'medicineId'
],
hubId:
parsedJson
[
'hubId'
],
dosage:
parsedJson
[
'dosage'
],
...
...
frontend/flutter_application_1/lib/src/screens/models/User.dart
0 → 100644
View file @
ba1656c
class
User
{
final
String
userId
;
final
String
token
;
User
({
this
.
userId
,
this
.
token
});
factory
User
.
fromJson
(
Map
<
String
,
dynamic
>
parsedJson
)
{
return
User
(
userId:
parsedJson
[
'userId'
],
token:
parsedJson
[
'token'
],
);
}
Map
<
String
,
dynamic
>
toJson
()
=>
{
"userId"
:
userId
,
"token"
:
token
,
};
}
frontend/flutter_application_1/lib/src/utils/user_secure_stoarge.dart
0 → 100644
View file @
ba1656c
import
'package:flutter_secure_storage/flutter_secure_storage.dart'
;
class
UserSecureStorage
{
static
final
_storage
=
FlutterSecureStorage
();
static
const
_keyToken
=
'usertoken'
;
static
const
_keyUserId
=
'userid'
;
static
Future
setUserId
(
String
userid
)
async
=>
await
_storage
.
write
(
key:
_keyUserId
,
value:
userid
);
static
Future
<
String
>
getUserID
()
async
=>
await
_storage
.
read
(
key:
_keyUserId
);
static
Future
setUserToken
(
String
userToken
)
async
=>
await
_storage
.
write
(
key:
_keyToken
,
value:
userToken
);
static
Future
<
String
>
getUserToken
()
async
=>
await
_storage
.
read
(
key:
_keyToken
);
}
frontend/flutter_application_1/pubspec.lock
View file @
ba1656c
...
...
@@ -132,6 +132,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.0"
flutter_secure_storage:
dependency: "direct main"
description:
name: flutter_secure_storage
url: "https://pub.dartlang.org"
source: hosted
version: "3.3.5"
flutter_test:
dependency: "direct dev"
description: flutter
...
...
@@ -415,4 +422,4 @@ packages:
version: "0.1.2"
sdks:
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.
12.13+hotfix.6
<2.0.0"
flutter: ">=1.
20.0
<2.0.0"
...
...
frontend/flutter_application_1/pubspec.yaml
View file @
ba1656c
...
...
@@ -38,6 +38,7 @@ dependencies:
http
:
^0.12.0+4
flutter_dotenv
:
^2.1.0
numberpicker
:
^1.3.0
flutter_secure_storage
:
^3.3.5
dev_dependencies
:
flutter_test
:
...
...
Please
register
or
login
to post a comment