Skip to content

Commit

Permalink
Merge pull request #8 from TweaXy/Reset_Password
Browse files Browse the repository at this point in the history
Reset password
  • Loading branch information
Menna-Ahmed7 authored Nov 11, 2023
2 parents 57d7d04 + 632e048 commit 49c1d8a
Show file tree
Hide file tree
Showing 26 changed files with 996 additions and 204 deletions.
4 changes: 3 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 33
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion

Expand All @@ -47,7 +48,8 @@ android {
applicationId "com.example.project"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
// minSdkVersion flutter.minSdkVersion
minSdkVersion 22
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
20 changes: 14 additions & 6 deletions lib/Components/custom_text_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ class _CustomTextFieldState extends State<CustomTextField> {
String? _errorText; //should be null if the input is valid or in initial state
bool passwordVisible = false;

bool isPassword({required String label}) {
if (label == "Password" ||
label == "Enter a new password" ||
label == "Confirm your password") {
return true;
} else {
return false;
}
}

void validate({required String inputValue}) {
_errorText = widget.validatorFunc(
inputValue:
Expand All @@ -46,17 +56,15 @@ class _CustomTextFieldState extends State<CustomTextField> {
});
},
icon: passwordVisible
? const Icon(Icons.visibility_off)
: const Icon(Icons.visibility),
? const Icon(Icons.visibility)
: const Icon(Icons.visibility_off),
color: iconColorTheme(context),
));
}

List<Widget> showIcons() {
List<Widget> suffixIcons = [];
if (widget.label == "Password" ||
widget.label == "Enter a new password" ||
widget.label == "Confirm your password") {
if (isPassword(label: widget.label)) {
suffixIcons.add(passwordIcons());
}
if (_isValid != 0) {
Expand Down Expand Up @@ -86,7 +94,7 @@ class _CustomTextFieldState extends State<CustomTextField> {
},
cursorHeight: 30.0,
cursorColor: Colors.lightBlue[700],
obscureText: widget.label == 'Password' ? !passwordVisible : false,
obscureText: isPassword(label: widget.label) ? !passwordVisible : false,
maxLength: widget.label == 'Name' ? 50 : null,
decoration: InputDecoration(
prefix: widget.label == "Username" ? const Text("@") : null,
Expand Down
46 changes: 46 additions & 0 deletions lib/Components/custom_toast.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';

class CustomToast extends StatelessWidget {
const CustomToast({super.key, required this.message, this.screenWidth});
final String message;
final double? screenWidth;

@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
decoration: BoxDecoration(
color: const Color.fromARGB(180, 0, 0, 0),
borderRadius: BorderRadius.circular(20),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
SvgPicture.asset(
'assets/images/logo.svg',
alignment: Alignment.centerLeft,
width: 20,
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.6,
),
child: Text(
message,
textAlign: TextAlign.center,
overflow: TextOverflow.clip,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
),
),
),
),
],
),
);
}
}
33 changes: 33 additions & 0 deletions lib/Components/custom_web_toast.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';

class CustomWebToast extends StatelessWidget {
const CustomWebToast({super.key, required this.message});
final String message;

@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.topCenter,
margin: EdgeInsets.only(
top: MediaQuery.of(context).size.height * 0.88,
left: MediaQuery.of(context).size.width * 0.37,
right: MediaQuery.of(context).size.width * 0.37,
bottom: MediaQuery.of(context).size.height * 0.03,
),
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 10),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(5),
),
child: Text(
textAlign: TextAlign.center,
message,
overflow: TextOverflow.clip,
style: const TextStyle(
color: Colors.white,
fontSize: 15,
),
),
);
}
}
3 changes: 3 additions & 0 deletions lib/Components/sign_choose.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:sign_button/sign_button.dart';
import 'package:tweaxy/components/sign_in_with.dart';
import 'package:tweaxy/components/start_screen_divider.dart';
import 'package:tweaxy/services/sign_in.dart';

class SignChoose extends StatelessWidget {
const SignChoose({
Expand Down Expand Up @@ -41,6 +42,8 @@ class SignChoose extends StatelessWidget {
type: !isDarkMode ? ButtonType.github : ButtonType.githubDark,
onPressed: () {
//TODO: implement continue with github logic
var res = SignInServices.signInGithub();
// print("sign in" + res.toString());
},
size: ButtonSize.medium,
),
Expand Down
1 change: 1 addition & 0 deletions lib/Components/start_screen_signup_button.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:tweaxy/Views/login/reset_password/reset_password_web.dart';
import 'package:tweaxy/views/signup/create_account_web_view.dart';
import 'package:tweaxy/constants.dart';

Expand Down
38 changes: 22 additions & 16 deletions lib/Views/login/forget_passwoed_web_1.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';
import 'package:tweaxy/Views/login/forget_passwoed_web_3.dart';
import 'package:tweaxy/components/custom_button.dart';
import 'package:tweaxy/components/custom_dialog_app_bar.dart';
import 'package:tweaxy/components/custom_text_form_field.dart';
import 'package:tweaxy/components/custom_web_toast.dart';
import 'package:tweaxy/components/sign_choose.dart';
import 'package:tweaxy/components/text_and_link.dart';
import 'package:tweaxy/constants.dart';
import 'package:tweaxy/services/sign_in.dart';
import 'package:tweaxy/utilities/custom_text_form_validations.dart';
import 'package:tweaxy/utilities/theme_validations.dart';
import 'package:tweaxy/views/login/forget_passwoed_web_2.dart';

// ignore: must_be_immutable
class ForgetPasswordWeb1 extends StatefulWidget {
const ForgetPasswordWeb1({super.key});
ForgetPasswordWeb1({super.key});

@override
State<ForgetPasswordWeb1> createState() => _ForgetPasswordWeb1State();
State<ForgetPasswordWeb1> createState() => _WebDialogSignInPage2State();
}

class _ForgetPasswordWeb1State extends State<ForgetPasswordWeb1> {
class _WebDialogSignInPage2State extends State<ForgetPasswordWeb1> {
TextEditingController myController = TextEditingController();
bool isButtonEnabled = false;
bool isSnackBarShown = false; // Added flag to track SnackBar visibility

@override
void initState() {
super.initState();
Expand All @@ -45,7 +49,7 @@ class _ForgetPasswordWeb1State extends State<ForgetPasswordWeb1> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomDialogAppBar(isDarkMode: isDarkMode),
Padding(
const Padding(
padding: const EdgeInsets.only(left: 50),
child: Row(
children: [
Expand Down Expand Up @@ -95,22 +99,23 @@ class _ForgetPasswordWeb1State extends State<ForgetPasswordWeb1> {
padding: const EdgeInsets.only(top: 12.0),
child: SizedBox(
width: 500,
height: 50,
height: 40,
child: CustomButton(
color: forgroundColorTheme(context),
text: 'Login',
onPressedCallback: () async {
SignInServices forgetPass = SignInServices(Dio());
String res = await forgetPass.forgetPasswordEmail(
email: myController.text);
SignInServices.setEmail(email: myController.text);
String res =
await SignInServices.forgetPassword();

print(res);
if (res != 'success') {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('$res'),
backgroundColor: Colors.blue,
),
);
showToastWidget(
CustomWebToast(
message: res,
),
position: ToastPosition.bottom,
duration: const Duration(seconds: 2));
} else {
Navigator.pop(context);

Expand All @@ -127,6 +132,7 @@ class _ForgetPasswordWeb1State extends State<ForgetPasswordWeb1> {
},
initialEnabled: isButtonEnabled)),
),
Container(height: 30)
],
),
),
Expand Down
5 changes: 1 addition & 4 deletions lib/Views/login/forget_passwoed_web_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ class ForgetPasswordWeb2 extends StatelessWidget {
color: forgroundColorTheme(context),
text: 'Next',
onPressedCallback: () async {
SignInServices forgetPass =
await SignInServices(Dio());
String res = SignInServices.forgetPassword();

Future<String> res =
forgetPass.forgetPasswordEmail(email: email);
if (res != 'sucess') {
ScaffoldMessenger.of(scaffoldContext)
.showSnackBar(
Expand Down
69 changes: 54 additions & 15 deletions lib/Views/login/forget_passwoed_web_3.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
import 'package:flutter/material.dart';
import 'package:tweaxy/Views/login/reset_password/reset_password_web.dart';
import 'package:tweaxy/components/custom_button.dart';
import 'package:tweaxy/components/custom_dialog_app_bar.dart';
import 'package:tweaxy/components/custom_text_form_field.dart';
import 'package:tweaxy/utilities/custom_text_form_validations.dart';
import 'package:tweaxy/utilities/theme_validations.dart';
import 'package:tweaxy/views/login/forget_passwoed_web_1.dart';

class ForgetPasswordWeb3 extends StatelessWidget {
import '../../services/sign_in.dart';

class ForgetPasswordWeb3 extends StatefulWidget {
const ForgetPasswordWeb3({super.key});

@override
State<ForgetPasswordWeb3> createState() => _ForgetPasswordWeb3State();
}

class _ForgetPasswordWeb3State extends State<ForgetPasswordWeb3> {
bool isButtonEnabled = false;
TextEditingController myController = TextEditingController();

@override
void initState() {
super.initState();
myController.addListener(_updateButtonState);
}

void _updateButtonState() {
setState(() {
isButtonEnabled = myController.text.isNotEmpty;
});
}

@override
Widget build(BuildContext context) {
TextEditingController myController = TextEditingController();
bool isDarkMode =
MediaQuery.of(context).platformBrightness == Brightness.dark;
return SizedBox(
Expand Down Expand Up @@ -55,7 +78,7 @@ class ForgetPasswordWeb3 extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 15.0),
child: CustomTextField(
key: const ValueKey("forgetPassView3TextField"),
validatorFunc: emailValidation,
validatorFunc: codeValidation,
label: 'Enter your code',
controller: myController,
),
Expand All @@ -67,18 +90,34 @@ class ForgetPasswordWeb3 extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.end,
children: [
SizedBox(
height: 50,
width: 350,
child: CustomButton(
key: const ValueKey("forgetPassView3BackButton"),
color: backgroundColorTheme(context),
text: 'Back',
initialEnabled: true,
onPressedCallback: () {
Navigator.pop(context);
},
),
),
height: 50,
width: 350,
child: CustomButton(
key: const ValueKey("forgetPassView3BackButton"),
color: isButtonEnabled
? forgroundColorTheme(context)
: backgroundColorTheme(context),
text: isButtonEnabled ? 'Next' : 'Back',
initialEnabled: true,
onPressedCallback: () {
if (isButtonEnabled)
SignInServices.setToken(
token: myController.text);

Navigator.pop(context);
showDialog(
context: context,
builder: (context) => AlertDialog(
content: isButtonEnabled
? ResetPasswordWeb()
: ForgetPasswordWeb1(),
),
barrierColor:
const Color.fromARGB(100, 97, 119, 129),
barrierDismissible: false,
);
},
)),
]),
),
)
Expand Down
Loading

0 comments on commit 49c1d8a

Please sign in to comment.