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
98efa012
Commit
98efa012
authored
Aug 02, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: sifting change password with confirm email to without confirm email
parent
6f1ee35e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
219 additions
and
7 deletions
+219
-7
main.dart
lib/main.dart
+4
-0
auth_provider.dart
lib/src/providers/auth_provider.dart
+40
-0
form_screen.dart
lib/src/screens/form_screen.dart
+16
-0
change_password_form.dart
lib/src/widgets/forms/change_password_form.dart
+157
-0
profile_edit_form.dart
lib/src/widgets/forms/profile_edit_form.dart
+2
-7
No files found.
lib/main.dart
View file @
98efa012
...
...
@@ -51,6 +51,10 @@ class _LibraryApp extends State<LibraryApp> {
path:
'/confirm-reset-password'
,
builder:
(
context
,
state
)
=>
const
ConfirmResetPasswordScreen
(),
),
GoRoute
(
path:
"/change-password"
,
builder:
(
context
,
state
)
=>
const
ChangePasswordScreen
(),
)
],
);
...
...
lib/src/providers/auth_provider.dart
View file @
98efa012
...
...
@@ -23,6 +23,7 @@ class AuthProvider with ChangeNotifier {
bool
isLoading
=
false
;
bool
resetPasswordTokenSended
=
false
;
bool
resetPasswordSucced
=
false
;
bool
changePasswordSucced
=
false
;
bool
loanBookSuccess
=
false
;
List
<
dynamic
>?
loans
;
...
...
@@ -231,6 +232,45 @@ class AuthProvider with ChangeNotifier {
}
}
Future
<
void
>
changePassword
(
BuildContext
context
,
int
accountId
,
String
oldPassword
,
String
newPassword
,
)
async
{
final
token
=
await
getAccessToken
();
try
{
setLoading
(
true
);
final
response
=
await
http
.
post
(
Uri
.
parse
(
'
$baseUrl
/members/
$accountId
/change-password'
),
body:
jsonEncode
({
"old_password"
:
oldPassword
,
"new_password"
:
newPassword
,
}),
headers:
{
'Content-Type'
:
'application/json'
,
'Authorization'
:
'Bearer
$token
'
},
);
if
(
response
.
statusCode
==
200
)
{
if
(
context
.
mounted
)
{
context
.
go
(
"/"
);
}
changePasswordSucced
=
true
;
}
else
{
debugPrint
(
'Change password failed:
${response.statusCode}
,
${response.body}
'
);
}
setLoading
(
false
);
notifyListeners
();
}
catch
(
error
)
{
debugPrint
(
"Change password failed:
$error
"
);
}
}
Future
<
void
>
resetPassword
(
String
email
)
async
{
try
{
setLoading
(
true
);
...
...
lib/src/screens/form_screen.dart
View file @
98efa012
import
'package:flutter/material.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:library_app/src/widgets/forms/change_password_form.dart'
;
import
'package:library_app/src/widgets/forms/login_form.dart'
;
import
'package:library_app/src/widgets/forms/reset_password_form.dart'
;
...
...
@@ -89,6 +90,21 @@ class SignUpScreen extends StatelessWidget {
}
}
class
ChangePasswordScreen
extends
StatelessWidget
{
const
ChangePasswordScreen
({
super
.
key
});
@override
Widget
build
(
BuildContext
context
)
{
String
title
=
"Change Password"
;
return
FormScreen
(
title:
title
,
backRoute:
"/"
,
body:
const
ChangePasswordForm
(),
);
}
}
class
ResetPasswordScreen
extends
StatelessWidget
{
const
ResetPasswordScreen
({
super
.
key
});
...
...
lib/src/widgets/forms/change_password_form.dart
0 → 100644
View file @
98efa012
import
'package:flutter/material.dart'
;
import
'package:flutter_svg/svg.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
import
'package:library_app/src/widgets/loading.dart'
;
import
'package:provider/provider.dart'
;
class
ChangePasswordForm
extends
StatefulWidget
{
const
ChangePasswordForm
({
super
.
key
});
@override
State
<
ChangePasswordForm
>
createState
()
=>
_ChangePasswordForm
();
}
class
_ChangePasswordForm
extends
State
<
ChangePasswordForm
>
{
final
GlobalKey
<
FormState
>
_formKey
=
GlobalKey
<
FormState
>();
final
oldPasswordController
=
TextEditingController
();
final
newPasswordController
=
TextEditingController
();
bool
passwordVisible
=
false
;
@override
void
initState
()
{
super
.
initState
();
passwordVisible
=
true
;
}
@override
void
dispose
()
{
oldPasswordController
.
dispose
();
newPasswordController
.
dispose
();
super
.
dispose
();
}
@override
Widget
build
(
BuildContext
context
)
{
Size
screenSize
=
MediaQuery
.
of
(
context
).
size
;
return
Consumer
<
AuthProvider
>(
builder:
(
context
,
authProvider
,
child
)
{
return
Column
(
children:
[
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
20.0
,
vertical:
10.0
),
child:
SvgPicture
.
asset
(
"assets/images/reset_password_image.svg"
,
semanticsLabel:
"change password"
,
height:
screenSize
.
height
*
0.2
,
),
),
const
Text
(
"Change Password"
,
style:
TextStyle
(
fontSize:
18
,
fontWeight:
FontWeight
.
bold
),
),
Container
(
padding:
const
EdgeInsets
.
symmetric
(
vertical:
20
,
horizontal:
20.0
),
child:
Form
(
key:
_formKey
,
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
TextFormField
(
controller:
oldPasswordController
,
obscureText:
passwordVisible
,
decoration:
InputDecoration
(
hintText:
"Enter your Old Password"
,
labelText:
"Old Password"
,
suffixIcon:
IconButton
(
icon:
Icon
(
passwordVisible
?
Icons
.
visibility
:
Icons
.
visibility_off
),
onPressed:
()
{
setState
(
()
{
passwordVisible
=
!
passwordVisible
;
},
);
},
),
),
validator:
(
String
?
value
)
{
if
(
value
==
null
||
value
.
isEmpty
)
{
return
"Please enter your old password"
;
}
else
{
return
null
;
}
},
keyboardType:
TextInputType
.
visiblePassword
,
),
TextFormField
(
controller:
newPasswordController
,
obscureText:
passwordVisible
,
decoration:
InputDecoration
(
hintText:
"Enter your New Password"
,
labelText:
"New Password"
,
suffixIcon:
IconButton
(
icon:
Icon
(
passwordVisible
?
Icons
.
visibility
:
Icons
.
visibility_off
),
onPressed:
()
{
setState
(
()
{
passwordVisible
=
!
passwordVisible
;
},
);
},
),
),
validator:
(
String
?
value
)
{
if
(
value
==
null
||
value
.
isEmpty
)
{
return
"Please enter your new password"
;
}
else
{
return
null
;
}
},
keyboardType:
TextInputType
.
visiblePassword
,
),
const
SizedBox
(
height:
20.0
,
),
Column
(
children:
[
SizedBox
(
width:
double
.
infinity
,
child:
FilledButton
(
onPressed:
()
async
{
if
(
_formKey
.
currentState
!.
validate
())
{}
authProvider
.
changePassword
(
context
,
authProvider
.
user
!.
accountId
,
oldPasswordController
.
text
,
newPasswordController
.
text
,
);
},
child:
authProvider
.
isLoading
?
const
Loading
()
:
const
Text
(
"Submit"
),
),
),
SizedBox
(
width:
double
.
infinity
,
child:
TextButton
(
child:
const
Text
(
"Cancel"
),
onPressed:
()
=>
context
.
pop
(
"/"
),
),
),
],
),
],
),
),
)
],
);
});
}
}
lib/src/widgets/forms/profile_edit_form.dart
View file @
98efa012
import
'package:flutter/material.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
import
'package:library_app/src/models/user.dart'
;
...
...
@@ -121,13 +122,7 @@ class _ProfileEditForm extends State<ProfileEditForm> {
child:
SizedBox
(
width:
double
.
infinity
,
child:
ElevatedButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
(
builder:
(
context
)
=>
const
ResetPasswordScreen
(),
),
);
},
onPressed:
()
=>
context
.
go
(
"/change-password"
),
child:
const
Text
(
"Change Password"
),
),
),
...
...
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