Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
medapp_eksad
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qorri_di
medapp_eksad
Commits
8a8832bf
Commit
8a8832bf
authored
Sep 20, 2022
by
Jaenudin Surya Darmatin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add login
parent
611fe657
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
63 deletions
+65
-63
firebase_auth_methods.dart
lib/firebase/firebase_auth_methods.dart
+3
-0
login.dart
lib/login.dart
+62
-63
No files found.
lib/firebase/firebase_auth_methods.dart
View file @
8a8832bf
...
@@ -88,6 +88,9 @@ class FirebaseAuthMethods {
...
@@ -88,6 +88,9 @@ class FirebaseAuthMethods {
// restrict access to certain things using provider
// restrict access to certain things using provider
// transition to another page instead of home screen
// transition to another page instead of home screen
}
}
else
if
(
user
.
emailVerified
){
Navigator
.
pushNamed
(
context
,
'/dashboard'
);
}
}
on
FirebaseAuthException
catch
(
e
)
{
}
on
FirebaseAuthException
catch
(
e
)
{
showSnackBar
(
context
,
e
.
message
!);
// Displaying the error message
showSnackBar
(
context
,
e
.
message
!);
// Displaying the error message
}
}
...
...
lib/login.dart
View file @
8a8832bf
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/services.dart'
;
import
'package:provider/provider.dart'
;
import
'firebase/firebase_auth_methods.dart'
;
void
setPageTitle
(
String
title
,
BuildContext
context
)
{
void
setPageTitle
(
String
title
,
BuildContext
context
)
{
SystemChrome
.
setApplicationSwitcherDescription
(
ApplicationSwitcherDescription
(
SystemChrome
.
setApplicationSwitcherDescription
(
ApplicationSwitcherDescription
(
...
@@ -19,8 +22,18 @@ class _SignInState extends State<SignIn> {
...
@@ -19,8 +22,18 @@ class _SignInState extends State<SignIn> {
bool
_isObscure
=
true
;
bool
_isObscure
=
true
;
final
formKey
=
GlobalKey
<
FormState
>();
final
formKey
=
GlobalKey
<
FormState
>();
final
TextEditingController
_usernamecontroller
=
TextEditingController
();
// final TextEditingController _usernamecontroller = TextEditingController();
final
TextEditingController
_passwordcontroller
=
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
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
...
@@ -121,7 +134,7 @@ class _SignInState extends State<SignIn> {
...
@@ -121,7 +134,7 @@ class _SignInState extends State<SignIn> {
height:
40
,
height:
40
,
width:
screenSize
.
width
*
0.2
,
width:
screenSize
.
width
*
0.2
,
child:
TextFormField
(
child:
TextFormField
(
controller:
_usernamec
ontroller
,
controller:
emailC
ontroller
,
textAlign:
TextAlign
.
start
,
textAlign:
TextAlign
.
start
,
decoration:
InputDecoration
(
decoration:
InputDecoration
(
labelText:
"Enter Your Email"
,
labelText:
"Enter Your Email"
,
...
@@ -132,7 +145,7 @@ class _SignInState extends State<SignIn> {
...
@@ -132,7 +145,7 @@ class _SignInState extends State<SignIn> {
),
),
validator:
(
value
)
{
validator:
(
value
)
{
if
(
value
==
null
||
value
.
trim
().
isEmpty
)
{
if
(
value
==
null
||
value
.
trim
().
isEmpty
)
{
_usernamec
ontroller
.
clear
();
emailC
ontroller
.
clear
();
return
"please enter your email address"
;
return
"please enter your email address"
;
}
else
if
(!
RegExp
(
r'\S+@\S+\.\S+'
)
}
else
if
(!
RegExp
(
r'\S+@\S+\.\S+'
)
.
hasMatch
(
value
))
{
.
hasMatch
(
value
))
{
...
@@ -166,7 +179,7 @@ class _SignInState extends State<SignIn> {
...
@@ -166,7 +179,7 @@ class _SignInState extends State<SignIn> {
height:
40
,
height:
40
,
width:
screenSize
.
width
*
0.2
,
width:
screenSize
.
width
*
0.2
,
child:
TextFormField
(
child:
TextFormField
(
controller:
_passwordc
ontroller
,
controller:
passwordC
ontroller
,
textAlign:
TextAlign
.
start
,
textAlign:
TextAlign
.
start
,
obscureText:
_isObscure
,
obscureText:
_isObscure
,
decoration:
InputDecoration
(
decoration:
InputDecoration
(
...
@@ -189,7 +202,7 @@ class _SignInState extends State<SignIn> {
...
@@ -189,7 +202,7 @@ class _SignInState extends State<SignIn> {
),
),
validator:
(
value
)
{
validator:
(
value
)
{
if
(
value
==
null
||
value
.
trim
().
isEmpty
)
{
if
(
value
==
null
||
value
.
trim
().
isEmpty
)
{
_passwordc
ontroller
.
clear
();
passwordC
ontroller
.
clear
();
return
'This field is required'
;
return
'This field is required'
;
}
else
if
(
value
.
trim
().
length
<
8
)
{
}
else
if
(
value
.
trim
().
length
<
8
)
{
return
'Password must be at least 8 characters in length'
;
return
'Password must be at least 8 characters in length'
;
...
@@ -221,63 +234,49 @@ class _SignInState extends State<SignIn> {
...
@@ -221,63 +234,49 @@ class _SignInState extends State<SignIn> {
width:
screenSize
.
width
*
0.08
,
width:
screenSize
.
width
*
0.08
,
child:
ElevatedButton
(
child:
ElevatedButton
(
onPressed:
()
{
onPressed:
()
{
if
(
_usernamecontroller
.
value
.
text
==
'admin@admin.com'
&&
loginUser
();
_passwordcontroller
.
value
.
text
!=
'administrator'
)
{
// if (emailController.value.text == emailController &&
showDialog
<
String
>(
// passwordController.value.text != passwordController) {
context:
context
,
// showDialog<String>(
builder:
(
BuildContext
context
)
=>
// context: context,
AlertDialog
(
// builder: (BuildContext context) =>
title:
const
Text
(
'Gagal login'
),
// AlertDialog(
content:
const
Text
(
// title: const Text('Gagal login'),
'Password anda salah!!!'
),
// content: const Text(
actions:
<
Widget
>[
// 'Password anda salah!!!'),
TextButton
(
// actions: <Widget>[
onPressed:
()
=>
// TextButton(
Navigator
.
pop
(
context
,
'OK'
),
// onPressed: () =>
child:
const
Text
(
'OK'
),
// Navigator.pop(context, 'OK'),
),
// child: const Text('OK'),
],
// ),
),
// ],
);
// ),
}
else
if
(
_usernamecontroller
.
value
.
text
==
'client@client.com'
&&
// );
_passwordcontroller
.
value
.
text
!=
'clientpage'
)
{
// } else if (emailController.value.text == emailController &&
showDialog
<
String
>(
// passwordController.value.text == passwordController) {
context:
context
,
// loginUser();
builder:
(
BuildContext
context
)
=>
// Navigator.pushNamed(context, '/dashboard');
AlertDialog
(
// } else {
title:
const
Text
(
'Gagal login'
),
// loginUser();
content:
const
Text
(
// Navigator.pushNamed(context, '/dashboard');
'Password anda salah!!!'
),
// // showDialog<String>(
actions:
<
Widget
>[
// // context: context,
TextButton
(
// // builder: (BuildContext context) =>
onPressed:
()
=>
// // AlertDialog(
Navigator
.
pop
(
context
,
'OK'
),
// // title: const Text('Gagal login'),
child:
const
Text
(
'OK'
),
// // content: const Text(
),
// // 'Akun Belum terdaftar, Silahkan Registrasi'),
],
// // actions: <Widget>[
),
// // TextButton(
);
// // onPressed: () =>
}
else
if
(
_usernamecontroller
.
value
.
text
==
'admin@admin.com'
&&
// // Navigator.pop(context, 'OK'),
_passwordcontroller
.
value
.
text
==
'administrator'
)
{
// // child: const Text('OK'),
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'
),
),
],
),
);
}
},
},
child:
const
Text
(
"LOGIN"
),
child:
const
Text
(
"LOGIN"
),
),
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment