-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a developer options to the app (currently only deletes local st…
…orage credentials), partially addresses #9 , dartfmt everything
- Loading branch information
1 parent
df68f4a
commit c3004c8
Showing
10 changed files
with
142 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,66 @@ | ||
import 'dart:convert'; | ||
import 'package:app/storage.dart'; | ||
|
||
class CEICredentials{ | ||
class CEICredentials { | ||
String _cpf; | ||
String _password; | ||
final String _filename = "cei_credentials.json"; | ||
|
||
CEICredentials(this._cpf, this._password); | ||
|
||
CEICredentials .empty(){ | ||
CEICredentials.empty() { | ||
_cpf = ""; | ||
_password = ""; | ||
} | ||
|
||
@override | ||
String toString(){ | ||
String toString() { | ||
return "CPF: $_cpf"; | ||
} | ||
|
||
fromJson(Map<String, dynamic> json){ | ||
fromJson(Map<String, dynamic> json) { | ||
_cpf = json['cpf']; | ||
_password = json['password']; | ||
} | ||
|
||
|
||
Map<String, dynamic> toJson() => | ||
{ | ||
Map<String, dynamic> toJson() => { | ||
'cpf': _cpf, | ||
'password': _password, | ||
}; | ||
|
||
save({bool safe_save=false}){ | ||
if (!safe_save){ | ||
Storage credStorage = Storage(_filename); | ||
credStorage.write(jsonEncode(this.toJson())); | ||
} | ||
else{ | ||
save({bool safeSave = false}) { | ||
if (!safeSave) { | ||
Storage credStorage = Storage(_filename); | ||
credStorage.write(jsonEncode(this.toJson())); | ||
} else { | ||
print("Not implemented yet."); | ||
} | ||
} | ||
|
||
load() async{ | ||
load() async { | ||
Storage credStorage = Storage(_filename); | ||
Map<String, dynamic> credJson = jsonDecode(await credStorage.read()); | ||
this.fromJson(credJson); | ||
} | ||
|
||
exists() async{ | ||
exists() async { | ||
Storage credStorage = Storage(_filename); | ||
return await credStorage.exists(); | ||
} | ||
} | ||
|
||
delete() async { | ||
Storage credStorage = Storage(_filename); | ||
return await credStorage.delete(); | ||
} | ||
|
||
bool validateCredentials() { | ||
// Check if the CPF/password combo is registered in the CEI system | ||
return validateCPF(_cpf); | ||
} | ||
} | ||
|
||
bool validateCPF(String cpf) { | ||
RegExp exp = new RegExp(r"[0-9]{3}\.?[0-9]{3}\.?[0-9]{3}[\.-]?[0-9]{2}"); | ||
RegExpMatch hasMatch = exp.firstMatch(cpf); | ||
return hasMatch != null && ((hasMatch.end - hasMatch.start) == cpf.length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:app/CEICredentials.dart'; | ||
|
||
redirect(BuildContext context) async{ | ||
redirect(BuildContext context) async { | ||
CEICredentials creds = CEICredentials.empty(); | ||
bool hasCredentials = await creds.exists(); | ||
if (hasCredentials){ | ||
Navigator.of(context).pushReplacementNamed('/home'); | ||
} | ||
else{ | ||
Navigator.of(context).pushReplacementNamed('/login'); | ||
} | ||
|
||
} | ||
String route = hasCredentials ? "/home" : "/login"; | ||
Navigator.of(context).pushReplacementNamed(route); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:app/CEICredentials.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class DeveloperSettings extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text('Developer Settings'), | ||
), | ||
body: ListView( | ||
children: ListTile.divideTiles(context: context, tiles: [ | ||
ListTile( | ||
title: Text("Erase CEI credentials from local storage"), | ||
onTap: () => {CEICredentials.empty().delete()}, | ||
), | ||
ListTile( | ||
title: Text("Option 2"), | ||
), | ||
ListTile( | ||
title: Text("Option 3"), | ||
) | ||
]).toList(), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
import 'package:flutter/material.dart'; | ||
import "appInitializer.dart"; | ||
|
||
class SplashScreen extends StatelessWidget{ | ||
class SplashScreen extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context){ | ||
Widget build(BuildContext context) { | ||
redirect(context); | ||
return Scaffold( | ||
body: Center(child: Text("Loading...")) | ||
); | ||
return Scaffold(body: Center(child: Text("Loading..."))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters