Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from prakharb10:dev
Browse files Browse the repository at this point in the history
Authentication added
  • Loading branch information
prakharb10 authored Jun 24, 2020
2 parents 4e13bd6 + bac3d60 commit 9b05459
Show file tree
Hide file tree
Showing 8 changed files with 1,143 additions and 62 deletions.
222 changes: 222 additions & 0 deletions lib/ForgotPass.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'SharedAxisPR.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'dart:async';

class ForgotPass extends StatefulWidget {
@override
_ForgotPassState createState() => _ForgotPassState();
}

final FirebaseAuth _auth = FirebaseAuth.instance;

class _ForgotPassState extends State<ForgotPass> {
final _forgotemailController = TextEditingController();
bool _isEmpty2 = true;
FocusNode _focusNodeEmail2 = FocusNode();
String _email;
final _formKey2 = GlobalKey<FormState>();
String errorMsg = '';
bool _isLoading = false;

Widget _sufIC() {
if (_focusNodeEmail2.hasFocus) {
return _isEmpty2
? null
: IconButton(
icon: Icon(
Icons.clear,
color: const Color(0xfff23b5f),
),
onPressed: () {
_forgotemailController.clear();
setState(() {
_isEmpty2 = true;
});
},
);
} else {
return null;
}
}

@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.white,
leading: IconButton(
iconSize: 30,
color: const Color(0xfff23b5f),
icon: Icon(Icons.arrow_back_ios),
onPressed: () => Navigator.of(context).pop(SharedAxisPageRoute()),
),
),
body: Center(
heightFactor: 0.75,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Can\'t remember your password? ',
style: GoogleFonts.openSans(
color: const Color(0xff253a4b),
fontSize: 30,
fontWeight: FontWeight.w700,
),
textAlign: TextAlign.left,
),
Padding(
padding: const EdgeInsets.only(
top: 15,
bottom: 15,
),
child: Form(
autovalidate: true,
key: _formKey2,
child: TextFormField(
validator: validateEmail,
focusNode: _focusNodeEmail2,
controller: _forgotemailController,
obscureText: false,
maxLines: 1,
autovalidate: false,
enableSuggestions: true,
toolbarOptions:
ToolbarOptions(paste: true, selectAll: true),
textCapitalization: TextCapitalization.none,
cursorColor: const Color(0xff253a4b),
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
filled: true,
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(25.0),
),
fillColor: const Color(0x25253a4b),
hintText: 'Email',
prefixIcon: Icon(
Icons.email,
color: const Color(0xfff23b5f),
),
suffixIcon: _sufIC(),
),
textInputAction: TextInputAction.done,
onChanged: (value) {
setState(() {
_forgotemailController.text.isEmpty
? _isEmpty2 = true
: _isEmpty2 = false;
});
},
onTap: () {
setState(() {
_forgotemailController.text.isEmpty
? _isEmpty2 = true
: _isEmpty2 = false;
});
},
onEditingComplete: () {
setState(() {
_forgotemailController.text.isEmpty
? _isEmpty2 = true
: _isEmpty2 = false;
});
},
onSaved: (newValue) => _email = newValue,
),
),
),
_isLoading
? CircularProgressIndicator()
: RaisedButton(
padding: EdgeInsets.symmetric(
horizontal: 25.0,
vertical: 10.0,
),
elevation: 5.0,
onPressed: () async {
if (_formKey2.currentState.validate()) {
setState(() {
_isLoading = true;
});
_formKey2.currentState.save();
try {
await _auth
.sendPasswordResetEmail(email: _email)
.timeout(Duration(seconds: 10));
} on PlatformException catch (error) {
switch (error.code) {
case 'ERROR_INVALID_EMAIL':
errorMsg = 'Enter a proper email';
break;
case 'ERROR_USER_NOT_FOUND':
errorMsg = 'User does not exist!';
break;
default:
errorMsg = 'Unknown error occurred';
break;
}
} on TimeoutException catch (f) {
errorMsg = f.message;
}
setState(() {
_isLoading = false;
});
if (errorMsg == '') {
errorMsg = 'Email sent successfully';
Fluttertoast.showToast(
fontSize: 15,
msg: errorMsg,
textColor: const Color(0xff253a4b),
);
} else {
Fluttertoast.showToast(
fontSize: 15.0,
msg: errorMsg,
textColor: const Color(0xff253a4b),
);
errorMsg = '';
}
}
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
color: const Color(0xfff23b5f),
child: Text(
'Reset Password',
style: GoogleFonts.roboto(
color: Colors.white,
fontSize: 25.0,
),
),
),
],
),
),
),
),
);
}
}

String validateEmail(String value) {
String pattern =
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
RegExp regExp = new RegExp(pattern);
if (value.length == 0) {
return "Email is required";
} else if (!regExp.hasMatch(value)) {
return "Invalid Email";
} else {
return null;
}
}
Loading

0 comments on commit 9b05459

Please sign in to comment.