Skip to content

Commit

Permalink
Merge pull request #44 from fga-eps-mds/feature/89-apagar-conta
Browse files Browse the repository at this point in the history
#89 [US02] - Apagar Conta
  • Loading branch information
brenno-silva authored Apr 29, 2021
2 parents 583124b + 2abfbad commit f7faeb9
Show file tree
Hide file tree
Showing 21 changed files with 707 additions and 126 deletions.
40 changes: 0 additions & 40 deletions hortum_mobile/lib/data/change_password_backend.dart

This file was deleted.

41 changes: 0 additions & 41 deletions hortum_mobile/lib/data/update_user_backend.dart

This file was deleted.

92 changes: 92 additions & 0 deletions hortum_mobile/lib/data/user_data_backend.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:hortum_mobile/globals.dart';

class UserAPI {
Dio dio;

UserAPI([Dio client]) {
if (client == null) {
this.dio = Dio();
} else {
this.dio = client;
}
}

Future updateUser({String username, String email}) async {
//Trocar o IPLOCAL pelo ip de sua máquina
String url = 'http://$ip:8000/users/update/';

var header = {
"Content-Type": "application/json",
"Authorization": "Bearer " + actualUser.tokenAccess,
};

Map params = {
"username": username,
"email": email,
};
params.removeWhere((key, value) => value == null);

String _body = json.encode(params);
Response response = await dio.patch(url,
data: _body,
options: Options(
headers: header,
validateStatus: (status) {
return status <= 500;
},
));
return response.statusCode;
}

Future changePassword(String actualPassword, String newPassword) async {
//Trocar o IPLOCAL pelo ip de sua máquina
var url = 'http://$ip:8000/users/change-password/';
var header = {
"Content-Type": "application/json",
"Authorization": "Bearer " + actualUser.tokenAccess,
};

Map params = {
"old_password": actualPassword,
"new_password": newPassword,
};

String _body = json.encode(params);
Response response = await dio.patch(url,
data: _body,
options: Options(
headers: header,
validateStatus: (status) {
return status <= 500;
},
));
return response.statusCode;
}

Future deleteUser(String password) async {
String url = 'http://$ip:8000/users/delete/';

var header = {
"Content-Type": "application/json",
"Authorization": "Bearer " + actualUser.tokenAccess,
};

Map params = {
"password": password,
};

String _body = json.encode(params);
Response response = await dio.delete(url,
data: _body,
options: Options(
headers: header,
validateStatus: (status) {
return status <= 500;
},
));
return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:hortum_mobile/components/circle_style.dart';
import 'package:hortum_mobile/components/footer.dart';
import 'package:hortum_mobile/views/advanced_settings/components/change_password_button.dart';
import 'package:hortum_mobile/views/advanced_settings/components/delete_account_button.dart';
import 'package:hortum_mobile/views/advanced_settings/components/logout_button.dart';

class AdvancedSettingsPage extends StatefulWidget {
final Dio dio;

const AdvancedSettingsPage({this.dio, Key key}) : super(key: key);
@override
_AdvancedSettingsStatePage createState() => _AdvancedSettingsStatePage();
}

class _AdvancedSettingsStatePage extends State<AdvancedSettingsPage> {
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
body: Stack(children: [
SingleChildScrollView(
child: Column(
children: [
CircleStyle(color: Color(0xff478C5C), opacity: 0.2),
Text(
'AVANÇADO',
style: TextStyle(
color: Colors.black,
fontSize: 40,
fontFamily: 'Comfortaa-Regular',
letterSpacing: -0.33,
fontWeight: FontWeight.w300),
),
Container(
padding: EdgeInsets.only(top: size.height * 0.1),
child: Column(
children: [
ChangePasswordButton(),
DeleteAccountButton(),
LogoutButton(),
],
)),
Container(
margin: EdgeInsets.only(top: size.height * 0.05),
height: size.height / 5,
child: Image.asset("assets/images/logo.png"),
),
],
),
),
Footer(),
]),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'package:hortum_mobile/views/change_password/change_password_page.dart';

class ChangePasswordButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return TextButton(
key: Key('changePasswordButton'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ChangePasswordPage()),
);
},
style: ButtonStyle(
padding: MaterialStateProperty.all<EdgeInsets>((EdgeInsets.only(
left: size.width * 0.125, right: size.width * 0.125))),
backgroundColor: MaterialStateProperty.all<Color>(Color(0xff75CE90)),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
))),
child: Text(
"MUDAR SENHA",
style: TextStyle(
fontSize: 15.0,
color: Colors.white,
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'package:hortum_mobile/views/delete_account/delete_account_page.dart';

class DeleteAccountButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return TextButton(
key: Key('deleteAccountButton'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => DeleteAccountPage()),
);
},
style: ButtonStyle(
padding: MaterialStateProperty.all<EdgeInsets>((EdgeInsets.only(
left: size.width * 0.125, right: size.width * 0.125))),
backgroundColor: MaterialStateProperty.all<Color>(Color(0xff75CE90)),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
))),
child: Text(
"EXCLUIR CONTA",
style: TextStyle(
fontSize: 15.0,
color: Colors.white,
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:hortum_mobile/globals.dart';
import 'package:hortum_mobile/views/login/login_page.dart';

class LogoutButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Container(
child: TextButton(
key: Key('logoutButton'),
onPressed: () {
actualUser.deleteUser();
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => LoginPage()),
(route) => false);
},
style: ButtonStyle(
padding: MaterialStateProperty.all<EdgeInsets>(EdgeInsets.only(
left: size.width * 0.21, right: size.width * 0.21)),
backgroundColor: MaterialStateProperty.all<Color>(Color(0xff75CE90)),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
))),
child: Text(
"SAIR",
style: TextStyle(
fontSize: 15.0,
color: Colors.white,
),
),
));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:hortum_mobile/data/change_password_backend.dart';
import 'package:hortum_mobile/data/user_data_backend.dart';
import 'package:hortum_mobile/globals.dart';
import 'package:hortum_mobile/views/home_customer/home_customer_page.dart';
import 'package:hortum_mobile/views/home_productor/home_productor_page.dart';

class ChangePasswordServices {
static Future changePassword(Dio dio, String actualPasswordForm,
String newPasswordForm, BuildContext context) async {
ChangePasswordAPI changeData = new ChangePasswordAPI(dio);
UserAPI changeData = new UserAPI(dio);
var response =
await changeData.changePassword(actualPasswordForm, newPasswordForm);

Expand Down
Loading

0 comments on commit f7faeb9

Please sign in to comment.