Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
library-app-flutter
Project
Project
Details
Activity
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
Ilham Maulana
library-app-flutter
Commits
1e317d45
Commit
1e317d45
authored
Aug 05, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: invalid username or password handle on login form
parent
e05a1210
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
23 deletions
+19
-23
auth_provider.dart
lib/src/providers/auth_provider.dart
+8
-6
login_form.dart
lib/src/widgets/forms/login_form.dart
+10
-16
search_form.dart
lib/src/widgets/forms/search_form.dart
+1
-1
No files found.
lib/src/providers/auth_provider.dart
View file @
1e317d45
...
@@ -49,6 +49,10 @@ class AuthProvider with ChangeNotifier {
...
@@ -49,6 +49,10 @@ class AuthProvider with ChangeNotifier {
loanBookSuccess
=
value
;
loanBookSuccess
=
value
;
}
}
void
setInvalidUsernameOrPassword
(
bool
value
)
{
invalidUsernameOrPassword
=
value
;
}
Future
<
void
>
signIn
(
Future
<
void
>
signIn
(
BuildContext
context
,
String
username
,
String
password
)
async
{
BuildContext
context
,
String
username
,
String
password
)
async
{
try
{
try
{
...
@@ -65,16 +69,14 @@ class AuthProvider with ChangeNotifier {
...
@@ -65,16 +69,14 @@ class AuthProvider with ChangeNotifier {
await
storeAccessToken
(
token
);
await
storeAccessToken
(
token
);
isAuthenticated
=
true
;
isAuthenticated
=
true
;
invalidUsernameOrPassword
=
false
;
setInvalidUsernameOrPassword
(
false
)
;
debugPrint
(
"Login successful
$token
"
);
debugPrint
(
"Login successful
$token
"
);
}
else
if
(
response
.
statusCode
==
401
)
{
}
else
if
(
response
.
statusCode
==
400
)
{
invalidUsernameOrPassword
=
true
;
setInvalidUsernameOrPassword
(
true
);
debugPrint
(
"Login failed:
${response.statusCode}
${response.body}
"
);
debugPrint
(
"Login failed:
${response.statusCode}
${response.body}
"
);
}
else
{
}
else
{
final
code
=
response
.
statusCode
;
debugPrint
(
"Login failed:
${response.statusCode}
${response.body}
"
);
debugPrint
(
"Login failed
$code
"
);
}
}
setLoading
(
false
);
setLoading
(
false
);
...
...
lib/src/widgets/forms/login_form.dart
View file @
1e317d45
...
@@ -39,7 +39,8 @@ class _LoginForm extends State<LoginForm> {
...
@@ -39,7 +39,8 @@ class _LoginForm extends State<LoginForm> {
const
String
formText
=
"Log In to continue"
;
const
String
formText
=
"Log In to continue"
;
return
Consumer
<
AuthProvider
>(
builder:
(
context
,
authProvider
,
child
)
{
return
Consumer
<
AuthProvider
>(
builder:
(
context
,
authProvider
,
child
)
{
final
isInvalid
=
authProvider
.
invalidUsernameOrPassword
;
final
isInvalidUsernameOrPassword
=
authProvider
.
invalidUsernameOrPassword
;
return
Column
(
return
Column
(
children:
[
children:
[
...
@@ -106,28 +107,21 @@ class _LoginForm extends State<LoginForm> {
...
@@ -106,28 +107,21 @@ class _LoginForm extends State<LoginForm> {
},
},
keyboardType:
TextInputType
.
visiblePassword
,
keyboardType:
TextInputType
.
visiblePassword
,
),
),
Visibility
(
Padding
(
visible:
isInvalid
,
padding:
const
EdgeInsets
.
symmetric
(
vertical:
20.0
),
child:
Container
(
child:
Text
(
decoration:
BoxDecoration
(
isInvalidUsernameOrPassword
borderRadius:
BorderRadius
.
circular
(
10
),
?
"Invalid username or password"
color:
Theme
.
of
(
context
).
highlightColor
,
:
""
,
),
style:
const
TextStyle
(
color:
Colors
.
red
),
margin:
const
EdgeInsets
.
symmetric
(
vertical:
20.0
),
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
10.0
,
vertical:
8.0
),
child:
const
Text
(
"Invalid username or password"
),
),
),
),
),
const
SizedBox
(
height:
20.0
,
),
Column
(
Column
(
children:
[
children:
[
SizedBox
(
SizedBox
(
width:
double
.
infinity
,
width:
double
.
infinity
,
child:
FilledButton
(
child:
FilledButton
(
onPressed:
()
{
onPressed:
()
async
{
if
(
_formKey
.
currentState
!.
validate
())
{}
if
(
_formKey
.
currentState
!.
validate
())
{}
authProvider
.
signIn
(
authProvider
.
signIn
(
context
,
context
,
...
...
lib/src/widgets/forms/search_form.dart
View file @
1e317d45
...
@@ -24,7 +24,7 @@ class _SearchForm extends State<SearchForm> {
...
@@ -24,7 +24,7 @@ class _SearchForm extends State<SearchForm> {
width:
queryData
.
size
.
width
*
0.8
,
width:
queryData
.
size
.
width
*
0.8
,
padding:
const
EdgeInsets
.
symmetric
(
vertical:
8.0
),
padding:
const
EdgeInsets
.
symmetric
(
vertical:
8.0
),
child:
SearchBar
(
child:
SearchBar
(
hintText:
"Enter
keywords
..."
,
hintText:
"Enter
book title
..."
,
elevation:
WidgetStateProperty
.
all
(
0
),
elevation:
WidgetStateProperty
.
all
(
0
),
onChanged:
(
value
)
{
onChanged:
(
value
)
{
if
(
value
.
length
>=
3
)
{
if
(
value
.
length
>=
3
)
{
...
...
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