Add login

parent 611fe657
......@@ -88,6 +88,9 @@ class FirebaseAuthMethods {
// restrict access to certain things using provider
// transition to another page instead of home screen
}
else if(user.emailVerified){
Navigator.pushNamed(context, '/dashboard');
}
} on FirebaseAuthException catch (e) {
showSnackBar(context, e.message!); // Displaying the error message
}
......
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'firebase/firebase_auth_methods.dart';
void setPageTitle(String title, BuildContext context) {
SystemChrome.setApplicationSwitcherDescription(ApplicationSwitcherDescription(
......@@ -19,8 +22,18 @@ class _SignInState extends State<SignIn> {
bool _isObscure = true;
final formKey = GlobalKey<FormState>();
final TextEditingController _usernamecontroller = TextEditingController();
final TextEditingController _passwordcontroller = TextEditingController();
// final TextEditingController _usernamecontroller = TextEditingController();
// final TextEditingController _passwordcontroller = TextEditingController();
final TextEditingController emailController = TextEditingController();
final TextEditingController passwordController = TextEditingController();
void loginUser() {
context.read<FirebaseAuthMethods>().loginWithEmail(
email: emailController.text,
password: passwordController.text,
context: context,
);
}
@override
Widget build(BuildContext context) {
......@@ -121,7 +134,7 @@ class _SignInState extends State<SignIn> {
height: 40,
width: screenSize.width * 0.2,
child: TextFormField(
controller: _usernamecontroller,
controller: emailController,
textAlign: TextAlign.start,
decoration: InputDecoration(
labelText: "Enter Your Email",
......@@ -132,7 +145,7 @@ class _SignInState extends State<SignIn> {
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
_usernamecontroller.clear();
emailController.clear();
return "please enter your email address";
} else if (!RegExp(r'\S+@\S+\.\S+')
.hasMatch(value)) {
......@@ -166,7 +179,7 @@ class _SignInState extends State<SignIn> {
height: 40,
width: screenSize.width * 0.2,
child: TextFormField(
controller: _passwordcontroller,
controller: passwordController,
textAlign: TextAlign.start,
obscureText: _isObscure,
decoration: InputDecoration(
......@@ -189,7 +202,7 @@ class _SignInState extends State<SignIn> {
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
_passwordcontroller.clear();
passwordController.clear();
return 'This field is required';
} else if (value.trim().length < 8) {
return 'Password must be at least 8 characters in length';
......@@ -221,63 +234,49 @@ class _SignInState extends State<SignIn> {
width: screenSize.width * 0.08,
child: ElevatedButton(
onPressed: () {
if (_usernamecontroller.value.text == 'admin@admin.com' &&
_passwordcontroller.value.text != 'administrator') {
showDialog<String>(
context: context,
builder: (BuildContext context) =>
AlertDialog(
title: const Text('Gagal login'),
content: const Text(
'Password anda salah!!!'),
actions: <Widget>[
TextButton(
onPressed: () =>
Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
);
} else if (_usernamecontroller.value.text == 'client@client.com' &&
_passwordcontroller.value.text != 'clientpage') {
showDialog<String>(
context: context,
builder: (BuildContext context) =>
AlertDialog(
title: const Text('Gagal login'),
content: const Text(
'Password anda salah!!!'),
actions: <Widget>[
TextButton(
onPressed: () =>
Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
);
} else if (_usernamecontroller.value.text == 'admin@admin.com' &&
_passwordcontroller.value.text == 'administrator') {
Navigator.pushNamed(context, '/dashboard');
} else {
showDialog<String>(
context: context,
builder: (BuildContext context) =>
AlertDialog(
title: const Text('Gagal login'),
content: const Text(
'Akun Belum terdaftar, Silahkan Registrasi'),
actions: <Widget>[
TextButton(
onPressed: () =>
Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
);
}
loginUser();
// if (emailController.value.text == emailController &&
// passwordController.value.text != passwordController) {
// showDialog<String>(
// context: context,
// builder: (BuildContext context) =>
// AlertDialog(
// title: const Text('Gagal login'),
// content: const Text(
// 'Password anda salah!!!'),
// actions: <Widget>[
// TextButton(
// onPressed: () =>
// Navigator.pop(context, 'OK'),
// child: const Text('OK'),
// ),
// ],
// ),
// );
// } else if (emailController.value.text == emailController &&
// passwordController.value.text == passwordController) {
// loginUser();
// Navigator.pushNamed(context, '/dashboard');
// } else {
// loginUser();
// Navigator.pushNamed(context, '/dashboard');
// // showDialog<String>(
// // context: context,
// // builder: (BuildContext context) =>
// // AlertDialog(
// // title: const Text('Gagal login'),
// // content: const Text(
// // 'Akun Belum terdaftar, Silahkan Registrasi'),
// // actions: <Widget>[
// // TextButton(
// // onPressed: () =>
// // Navigator.pop(context, 'OK'),
// // child: const Text('OK'),
// // ),
// // ],
// // ),
// // );
// }
},
child: const Text("LOGIN"),
),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment