Fakultas Ilmu Komputer UI

Commit 6bd2bab3 authored by Usman Sidiq's avatar Usman Sidiq
Browse files

Merge branch 'dev-sidiq' into 'PBI-3-registrasi_login'

Fungsional Register dan Login

See merge request !52
parents 719e66ac 80780510
Pipeline #42297 passed with stages
in 8 minutes and 56 seconds
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"google_maps_flutter","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_maps_flutter-0.5.24+1\\\\","dependencies":[]},{"name":"location","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location-2.5.3\\\\","dependencies":[]},{"name":"path_provider","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.5\\\\","dependencies":[]},{"name":"sqflite","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.3.0\\\\","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_plugin_android_lifecycle-1.0.6\\\\","dependencies":[]},{"name":"google_maps_flutter","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_maps_flutter-0.5.24+1\\\\","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location-2.5.3\\\\","dependencies":[]},{"name":"path_provider","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.5\\\\","dependencies":[]},{"name":"sqflite","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.3.0\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-0.0.4\\\\","dependencies":[]},{"name":"sqflite","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.3.0\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"google_maps_flutter","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-04-20 14:48:37.594917","version":"1.15.17"}
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"google_maps_flutter","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}]}
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:ppl_disabilitas/config/styles.dart';
import 'package:ppl_disabilitas/page/login/login.dart';
import 'package:shared_preferences/shared_preferences.dart';
class BisaGoDrawer extends StatelessWidget {
final List<Map<String, dynamic>> drawerList = [
{'title': 'Beranda', 'icon': Icons.home},
{'title': 'Riwayat Pencarian', 'icon': Icons.history},
{'title': 'Tentang Aplikasi', 'icon': Icons.info},
{'title': 'Log out', 'icon': Icons.keyboard_backspace}
{'title': 'Login', 'icon': Icons.keyboard_backspace}
];
@override
......@@ -24,10 +26,14 @@ class BisaGoDrawer extends StatelessWidget {
),
child: Row(
children: <Widget>[
FloatingActionButton(
backgroundColor: Colors.white,
elevation: 0,
onPressed: () => {},
SizedBox(
width: 40,
child: FloatingActionButton(
heroTag: null,
backgroundColor: Colors.white,
elevation: 0,
onPressed: () => {},
),
),
Padding(
padding: EdgeInsets.all(doubleSpace),
......@@ -52,6 +58,7 @@ class BisaGoDrawer extends StatelessWidget {
menus.forEach((menu) {
drawerItem.add(menu);
});
return Theme(
data: Theme.of(context).copyWith(
canvasColor: greenPrimary,
......@@ -79,7 +86,10 @@ class BisaGoDrawer extends StatelessWidget {
),
),
onTap: () {
Navigator.pushNamed(context, '/login');
if(title == 'Login') {
checkLoginStatus(context);
title = 'Logout';
}
},
),
decoration: BoxDecoration(
......@@ -90,4 +100,19 @@ class BisaGoDrawer extends StatelessWidget {
),
);
}
checkLoginStatus(BuildContext context) async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
if(sharedPreferences.getString("token") == null) {
_navigateToLoginPage(context);
}
else {
await sharedPreferences.clear();
await Navigator.pushNamed(context, '/');
}
}
void _navigateToLoginPage(BuildContext context) {
final route = MaterialPageRoute(builder: (_) => Login());
Navigator.of(context).push(route);
}
}
import 'package:json_annotation/json_annotation.dart';
part 'pengguna.g.dart';
@JsonSerializable()
class UserListResponse {
List<User> listUser;
UserListResponse();
factory UserListResponse.fromJson(Map<String, dynamic> json) => _$UserListResponseFromJson(json);
Map<String, dynamic> toJson() => _$UserListResponseToJson(this);
}
@JsonSerializable(nullable: true)
class User {
String username;
String phonenumber;
String email;
String password;
User();
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
Map<String, dynamic> toJson() => _$UserToJson(this);
}
\ No newline at end of file
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'pengguna.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
UserListResponse _$UserListResponseFromJson(Map<String, dynamic> json) {
return UserListResponse()
..listUser = (json['listUser'] as List)
?.map(
(e) => e == null ? null : User.fromJson(e as Map<String, dynamic>))
?.toList();
}
Map<String, dynamic> _$UserListResponseToJson(UserListResponse instance) =>
<String, dynamic>{
'listUser': instance.listUser,
};
User _$UserFromJson(Map<String, dynamic> json) {
return User()
..username = json['username'] as String
..phonenumber = json['phonenumber'] as String
..email = json['email'] as String
..password = json['password'] as String;
}
Map<String, dynamic> _$UserToJson(User instance) => <String, dynamic>{
'username': instance.username,
'phonenumber': instance.phonenumber,
'email': instance.email,
'password': instance.password,
};
import 'dart:convert';
class User {
bool is_login;
String username;
String phonenumber;
String name;
String email;
String password;
String phone_number;
String token;
User({this.username, this.phonenumber, this.email, this.password});
User({this.is_login, this.username, this.name, this.email, this.phone_number, this.token});
factory User.fromJson(Map<String, dynamic> map) {
return User(
username: map["username"], phonenumber: map["phonenumber"], email: map["email"], password: map["password"]);
username: map["username"],
name: map["name"],
email: map["email"],
phone_number: map["phone_number"],);
}
Map<String, dynamic> toJson() {
return {"username": username, "phonenumber": phonenumber, "email": email, "password": password};
return {"username": username, "name": name, "email": email, "phone_number": phone_number};
}
@override
String toString() {
return 'User{"username": $username, "phonenumber": $phonenumber, "email": $email, "password": $password}';
return 'User{"username": $username, "name": $name, "email": $email, "phone_number": $phone_number}';
}
}
......
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ppl_disabilitas/config/styles.dart';
import 'package:ppl_disabilitas/page/registrasi/registrasi.dart';
import 'package:ppl_disabilitas/utils/customButton.dart';
import 'package:ppl_disabilitas/utils/customTextField.dart';
import 'package:ppl_disabilitas/utils/validator.dart';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
class Login extends StatefulWidget{
......@@ -14,6 +18,7 @@ class Login extends StatefulWidget{
class LoginState extends State<Login> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
SharedPreferences sharedPreferences;
Widget build(BuildContext context) {
return Scaffold(
......@@ -45,7 +50,7 @@ class LoginState extends State<Login> {
style: TextStyle(fontSize: 15),
),
onTap: () {
Navigator.pushNamed(context, '/register');
_navigateToRegistrasiPage(context);
},
),
)
......@@ -124,17 +129,27 @@ class LoginState extends State<Login> {
login(String email, String password) async {
Map data = {
'email' : email,
'username' : email,
'password' : password
};
// var jsonData;
var response = await http.post('https://my.api.mockaroo.com/register.json?key=095ee610', body: data);
sharedPreferences = await SharedPreferences.getInstance();
var response = await http.post('http://poipole-staging.herokuapp.com/api-token-auth/', body: data);
if(response.statusCode == 200) {
// jsonData = json.decode(response.body);
await Navigator.pushNamed(context, '/');
Map<String, dynamic> tokenMap = jsonDecode(response.body);
setState(() {
sharedPreferences.setString("token", tokenMap['token']);
sharedPreferences.setString("email", email);
Navigator.pushNamed(context, '/');
});
}
else {
print(response.body);
}
}
void _navigateToRegistrasiPage(BuildContext context) {
final route = MaterialPageRoute(builder: (_) => Registrasi());
Navigator.of(context).push(route);
}
}
\ No newline at end of file
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ppl_disabilitas/config/styles.dart';
import 'package:ppl_disabilitas/page/dashboard/dashboard.dart';
import 'package:ppl_disabilitas/utils/customButton.dart';
import 'package:ppl_disabilitas/utils/customTextField.dart';
//import 'package:ppl_disabilitas/network/network_interface.dart';
import 'package:ppl_disabilitas/model/user.dart';
import 'package:ppl_disabilitas/utils/validator.dart';
import 'package:http/http.dart' as http;
......@@ -137,13 +136,9 @@ class RegistrasiState extends State<Registrasi> {
final FormState form = _formKey.currentState;
if (_formKey.currentState.validate()) {
form.save();
User user = User(
username: nameController.text.toString(),
phonenumber: phoneController.text.toString(),
email: emailController.text.toString(),
password: passwordController.text.toString()
);
await createUser(user);
await createUser(nameController.text.toString(), phoneController.text.toString(),
emailController.text.toString(), passwordController.text.toString());
_showDialog();
}
}
......@@ -152,33 +147,45 @@ class RegistrasiState extends State<Registrasi> {
TextEditingController emailController = TextEditingController();
TextEditingController passwordController = TextEditingController();
// static Future<bool> register(User data) async {
// final response = await http.post(
// 'https://my.api.mockaroo.com/register.json?key=095ee610&__method=POST',
// body: data);
// if (response.statusCode == 200) {
// return true;
// }
// else {
// return false;
// }
// }
// var response = NetworkInterface().post(
// url: 'https://my.api.mockaroo.com/register.json?key=095ee610',
// bodyParams: data,
// isLogin: false
// );
}
createUser(String name, String phone_number, String email, String password) async {
Map data = {
'name' : name,
'phone_number' : phone_number,
'email' : email,
'password' : password,
};
final response = await http.post(
"http://poipole-staging.herokuapp.com/api/register/",
// headers: {"Content-Type": "application/json"},
body: data,
);
if (response.statusCode == 200) {
} else {
return false;
}
}
void _showDialog() {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Pendaftaran Berhasil"),
content: Text("Silahkan kembali ke halaman utama untuk login"),
actions: <Widget>[
FlatButton(onPressed: () {
_navigateToDashboard(context);
},
child: Text("Dashboard"))
],
);
}
);
}
Future<bool> createUser(User data) async {
final response = await http.post(
"https://my.api.mockaroo.com/register.json?key=095ee610&__method=POST",
headers: {"content-type": "application/json"},
body: userToJson(data),
);
if (response.statusCode == 200) {
return true;
} else {
return false;
void _navigateToDashboard(BuildContext context) {
final route = MaterialPageRoute(builder: (_) => Dashboard());
Navigator.of(context).push(route);
}
}
......@@ -31,6 +31,7 @@ dependencies:
flutter_dotenv: ^2.1.0
json_serializable: ^3.2.5
cached_network_image: ^2.0.0
shared_preferences: 0.5.6+3
dev_dependencies:
flutter_test:
......
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:ppl_disabilitas/component/bisago_drawer.dart';
void main() {
group('drawer tests', () {
testWidgets('my drawer test', (WidgetTester tester) async {
final loginText = "Login";
await tester.pumpWidget(MaterialApp(
home: Scaffold(
drawer: BisaGoDrawer(),
)));
await tester.dragFrom(tester.getTopLeft(find.byType(MaterialApp)), Offset(300, 0));
await tester.pumpAndSettle();
// await tester.tap(find.text(loginText));
// await tester.pumpAndSettle();
//
// final textFieldLogin = 'Masuk ke Akun';
expect(find.text(loginText), findsOneWidget);
});
});
}
\ No newline at end of file
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:ppl_disabilitas/network/network_interface.dart';
import 'package:ppl_disabilitas/page/login/login.dart';
//import 'package:http/http.dart' as http;
class MockNetwork extends Mock implements NetworkInterface {}
void main() {
MockNetwork mockNetwork;
setUp(() {
mockNetwork = MockNetwork();
when(mockNetwork.get(isLogin: false, url: anyNamed('url')))
.thenAnswer((_) async {
await Future.delayed(Duration(milliseconds: 50));
return Future<dynamic>.value([
{
"username": "dummy@mail.com",
"name": "Dummy",
"email": "dummy@mail.com",
"phone_number": "085222333444",
}
]);
});
});
testWidgets('Find Username Text Field', (WidgetTester tester) async {
final textFieldKey = Key("Text Field Akun");
await tester.pumpWidget(MaterialApp(home: Login()));
......@@ -17,12 +39,4 @@ void main() {
expect(find.byKey(textFieldKey), findsOneWidget);
});
// test('Valid API end point for validating user', () async {
// Map data = {
// 'email' : 'dummy@dummy.com',
// 'password' : 'dummypassword',
// };
// var result = await http.post('https://my.api.mockaroo.com/register.json?key=095ee610', body: data);
// expect(result.statusCode, 200);
// });
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment