Add register and sign up with supertokens
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/main.dart';
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
|
||||
class HomeAppDrawer extends StatefulWidget {
|
||||
final String userEmail;
|
||||
@@ -17,6 +18,11 @@ class _HomeAppDrawerState extends State<HomeAppDrawer> {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
Future<bool> signOut() async {
|
||||
await SuperTokens.signOut();
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//print(MzanziInnovationHub.of(context)?.theme.mode);
|
||||
@@ -55,9 +61,11 @@ class _HomeAppDrawerState extends State<HomeAppDrawer> {
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
client.auth.signOut();
|
||||
Navigator.of(context).pushNamed('/');
|
||||
onTap: () async {
|
||||
//client.auth.signOut();
|
||||
if (await signOut()) {
|
||||
Navigator.of(context).pushNamed('/');
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/homeTile.dart';
|
||||
import 'package:patient_manager/env/env.dart';
|
||||
import 'package:patient_manager/main.dart';
|
||||
|
||||
class HomeTileGrid extends StatefulWidget {
|
||||
@@ -13,6 +14,42 @@ class HomeTileGrid extends StatefulWidget {
|
||||
class _HomeTileGridState extends State<HomeTileGrid> {
|
||||
late List<List<dynamic>> tileList;
|
||||
|
||||
List<List<dynamic>> setApps() {
|
||||
if (AppEnviroment.getEnv() == "Dev") {
|
||||
return [
|
||||
[
|
||||
Icons.medication,
|
||||
"Patient Manager",
|
||||
() {
|
||||
// Navigator.of(context)
|
||||
// .pushNamed('/patient-manager', arguments: widget.userEmail);
|
||||
Navigator.popAndPushNamed(context, '/patient-manager',
|
||||
arguments: widget.userEmail);
|
||||
}
|
||||
],
|
||||
[Icons.abc, "Test 1", () {}],
|
||||
[Icons.abc, "Test 2", () {}],
|
||||
[Icons.abc, "Test 3", () {}],
|
||||
[Icons.abc, "Test 4", () {}],
|
||||
[Icons.abc, "Test 5", () {}],
|
||||
[Icons.abc, "Test 6", () {}],
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
[
|
||||
Icons.medication,
|
||||
"Patient Manager",
|
||||
() {
|
||||
// Navigator.of(context)
|
||||
// .pushNamed('/patient-manager', arguments: widget.userEmail);
|
||||
Navigator.popAndPushNamed(context, '/patient-manager',
|
||||
arguments: widget.userEmail);
|
||||
}
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
//print("Home tile gird widget: ${widget.userEmail}");
|
||||
|
||||
@@ -123,6 +123,206 @@ class _MyErrorMessageState extends State<MyErrorMessage> {
|
||||
);
|
||||
}
|
||||
|
||||
void setUserExistsError() {
|
||||
messageTypes["User Exists"] = Stack(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
width: 500,
|
||||
height: 450,
|
||||
decoration: BoxDecoration(
|
||||
color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
borderRadius: BorderRadius.circular(25.0),
|
||||
border: Border.all(
|
||||
color: MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||
width: 5.0),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.warning_amber_rounded,
|
||||
size: 100,
|
||||
color: MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||
),
|
||||
SizedBox(height: 15),
|
||||
Text(
|
||||
"Email Already Exists",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||
fontSize: 25.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 25.0),
|
||||
child: Text(
|
||||
"An account is already registered with this email address. Please try logging in or use a different email.",
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.secondaryColor(),
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 25.0),
|
||||
child: Text(
|
||||
"Here are some things to keep in mind:",
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.secondaryColor(),
|
||||
fontSize: 20.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 25.0),
|
||||
child: Text(
|
||||
"1) Are you sure you're using the correct email address associated with your account?\n2) Is your caps lock key on? Passwords are case-sensitive.\n3) If you've forgotten your password, no worries! Click on \"Forgot Password?\" to reset it.",
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.secondaryColor(),
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 5,
|
||||
right: 5,
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.close,
|
||||
color: MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||
size: 35,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void setPwdMatchError() {
|
||||
messageTypes["Password"] = Stack(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
width: 500,
|
||||
height: 450,
|
||||
decoration: BoxDecoration(
|
||||
color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
borderRadius: BorderRadius.circular(25.0),
|
||||
border: Border.all(
|
||||
color: MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||
width: 5.0),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.warning_amber_rounded,
|
||||
size: 100,
|
||||
color: MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||
),
|
||||
SizedBox(height: 15),
|
||||
Text(
|
||||
"Passwords Don't Match",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||
fontSize: 25.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 25.0),
|
||||
child: Text(
|
||||
"The password and confirm password fields do not match. Please make sure they are identical.",
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.secondaryColor(),
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 25.0),
|
||||
child: Text(
|
||||
"Here are some things to keep in mind:",
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.secondaryColor(),
|
||||
fontSize: 20.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 25.0),
|
||||
child: Text(
|
||||
"1) Are you sure you're using the correct email address associated with your account?\n2) Is your caps lock key on? Passwords are case-sensitive.\n3) If you've forgotten your password, no worries! Click on \"Forgot Password?\" to reset it.",
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.secondaryColor(),
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 5,
|
||||
right: 5,
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.close,
|
||||
color: MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||
size: 35,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void setinvalidCredError() {
|
||||
messageTypes["Invalid Credentials"] = Stack(
|
||||
children: [
|
||||
@@ -347,6 +547,8 @@ class _MyErrorMessageState extends State<MyErrorMessage> {
|
||||
setInputError();
|
||||
setinvalidCredError();
|
||||
setInternetError();
|
||||
setUserExistsError();
|
||||
setPwdMatchError();
|
||||
//print(size);
|
||||
// setState(() {
|
||||
// width = size.width;
|
||||
|
||||
@@ -54,13 +54,16 @@ class _MySuccessMessageState extends State<MySuccessMessage> {
|
||||
const SizedBox(height: 10),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 25.0),
|
||||
child: Text(
|
||||
message,
|
||||
style: TextStyle(
|
||||
color:
|
||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
child: Center(
|
||||
child: Text(
|
||||
message,
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.secondaryColor(),
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:patient_manager/env/env.dart';
|
||||
import 'package:patient_manager/main.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:patient_manager/objects/appUser.dart';
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
|
||||
class PatManAppDrawer extends StatefulWidget {
|
||||
final String userEmail;
|
||||
@@ -33,6 +34,11 @@ class _PatManAppDrawerState extends State<PatManAppDrawer> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> signOut() async {
|
||||
await SuperTokens.signOut();
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
signedInUser = getUserDetails();
|
||||
@@ -203,10 +209,10 @@ class _PatManAppDrawerState extends State<PatManAppDrawer> {
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
client.auth.signOut();
|
||||
Navigator.popAndPushNamed(context, '/');
|
||||
//Navigator.of(context).pushNamed('/');
|
||||
onTap: () async {
|
||||
if (await signOut()) {
|
||||
Navigator.of(context).pushNamed('/');
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
|
||||
@@ -16,6 +16,7 @@ import 'package:patient_manager/objects/appUser.dart';
|
||||
import 'package:patient_manager/objects/files.dart';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
|
||||
import '../objects/patients.dart';
|
||||
|
||||
@@ -56,6 +57,7 @@ class _PatientFilesState extends State<PatientFiles> {
|
||||
late String userEmail = "";
|
||||
late AppUser appUser;
|
||||
late PlatformFile selected;
|
||||
final baseAPI = AppEnviroment.baseApiUrl;
|
||||
|
||||
Future<void> generateMedCert() async {
|
||||
//start loading circle
|
||||
@@ -183,11 +185,12 @@ class _PatientFilesState extends State<PatientFiles> {
|
||||
}
|
||||
|
||||
Future<void> getUserEmail() async {
|
||||
final res = await client.auth.getUser();
|
||||
if (res.user!.email != null) {
|
||||
//print("emai not null");
|
||||
userEmail = res.user!.email!;
|
||||
//print(userEmail);
|
||||
// Add method to get user email
|
||||
var uid = await SuperTokens.getUserId();
|
||||
var response = await http.get(Uri.parse("$baseAPI/user/$uid"));
|
||||
if (response.statusCode == 200) {
|
||||
var user = jsonDecode(response.body);
|
||||
userEmail = user["email"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user