Skip to content

Commit

Permalink
Merge pull request #4 from petrichor-hl/lam
Browse files Browse the repository at this point in the history
change password + delete account
  • Loading branch information
petrichor-hl authored Dec 11, 2023
2 parents f87bf33 + f131c15 commit a71497e
Show file tree
Hide file tree
Showing 9 changed files with 436 additions and 59 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ SE121.011
<img src="demo/review_film.png" width="45%"/>
</p>

- Search Film
<p align="center">
<img src="demo/search_film_by_genre.png" width="45%"/>
<img src="demo/search_film_by_keyword.png" width="45%"/>
</p>

- Person deital

<p align="center">
Expand Down
Binary file added demo/search_film_by_genre.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/search_film_by_keyword.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion lib/data/profile_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Future<void> fetchProfileData() async {
final userId = supabase.auth.currentUser!.id;
final data = await supabase
.from('profile')
.select('full_name, dob, avatar_url, my_list')
.select('password, full_name, dob, avatar_url, my_list')
.eq('id', userId)
.single();

Expand All @@ -15,6 +15,7 @@ Future<void> fetchProfileData() async {

profileData.addAll(
{
'password': data['password'],
'full_name': data['full_name'],
'dob': data['dob'],
'avatar_url': data['avatar_url'],
Expand Down
3 changes: 1 addition & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ void main() async {
]);
await Supabase.initialize(
url: 'https://kpaxjjmelbqpllxenpxz.supabase.co',
anonKey:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImtwYXhqam1lbGJxcGxseGVucHh6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTMwNDY0OTQsImV4cCI6MjAwODYyMjQ5NH0.MRzIQjr-s1pvy_PL_SM-ahW71ry63H5aNLRUSjMYFiw',
anonKey: 'service_role_key',
authFlowType: AuthFlowType.pkce,
);
runApp(MultiBlocProvider(
Expand Down
210 changes: 210 additions & 0 deletions lib/screens/change_password.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:movie_app/data/profile_data.dart';
import 'package:movie_app/main.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

class ChangePasswordScreen extends StatefulWidget {
const ChangePasswordScreen({super.key});

@override
State<ChangePasswordScreen> createState() => _ChangePasswordScreenState();
}

class _ChangePasswordScreenState extends State<ChangePasswordScreen> {
final _formKey = GlobalKey<FormState>();
bool _isProcessing = false;

final _oldPasswordController = TextEditingController();
final _newPasswordController = TextEditingController();
final _confirmPasswordController = TextEditingController();

void _changePassword() async {
// print("Old Password: " + profileData['password']);
final isValid = _formKey.currentState!.validate();

if (!isValid) {
return;
}

setState(() {
_isProcessing = true;
});

try {
await supabase.auth.updateUser(
UserAttributes(
password: _newPasswordController.text,
),
);
} on AuthException catch (e) {
print(e.message);
}

await supabase.from('profile').update(
{
'password': _newPasswordController.text,
},
).eq('id', supabase.auth.currentUser!.id);

profileData['password'] = _newPasswordController.text;

if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Đổi mật khẩu thành công.'),
behavior: SnackBarBehavior.floating,
duration: Duration(seconds: 3),
),
);
Navigator.of(context).pop();
}

setState(() {
_isProcessing = false;
});

// final verifyOldPassword = profileData['password'] == _oldPasswordController.text;
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.black,
foregroundColor: Colors.white,
),
body: Form(
key: _formKey,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 14),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextFormField(
controller: _oldPasswordController,
decoration: const InputDecoration(
filled: true,
fillColor: Color.fromARGB(255, 51, 51, 51),
hintText: 'Mật khẩu cũ',
hintStyle: TextStyle(color: Color(0xFFACACAC)),
suffixIconColor: Color(0xFFACACAC),
border: OutlineInputBorder(
borderSide: BorderSide.none,
),
contentPadding: EdgeInsets.fromLTRB(16, 20, 16, 12),
errorStyle: TextStyle(fontSize: 14),
),
obscureText: /*!_isShowPassword*/ true,
style: const TextStyle(color: Colors.white),
autocorrect: false,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Bạn chưa nhập Mật khẩu cũ';
}
if (value != profileData['password']) {
return 'Mật khẩu cũ không đúng.';
}
return null;
},
),
const Gap(30),
TextFormField(
controller: _newPasswordController,
decoration: const InputDecoration(
filled: true,
fillColor: Color.fromARGB(255, 51, 51, 51),
hintText: 'Mật khẩu mới',
hintStyle: TextStyle(color: Color(0xFFACACAC)),
suffixIconColor: Color(0xFFACACAC),
border: OutlineInputBorder(
borderSide: BorderSide.none,
),
contentPadding: EdgeInsets.fromLTRB(16, 20, 16, 12),
errorStyle: TextStyle(fontSize: 14),
),
obscureText: /*!_isShowPassword*/ true,
style: const TextStyle(color: Colors.white),
autocorrect: false,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Bạn chưa nhập Mật khẩu mới';
}
if (value.length < 6) {
return 'Mật khẩu gồm 6 ký tự trở lên.';
}
if (_oldPasswordController.text == profileData['password'] &&
value == profileData['password']) {
return 'Mật khẩu mới không được trùng với mật khẩu cũ.';
}
return null;
},
// onChanged: (value) {
// if (value.isEmpty) {
// _isShowPassword = false;
// }
// if (value.length <= 1) setState(() {});
// },
),
const Gap(10),
TextFormField(
controller: _confirmPasswordController,
decoration: const InputDecoration(
filled: true,
fillColor: Color.fromARGB(255, 51, 51, 51),
hintText: 'Xác nhận Mật khẩu mới',
hintStyle: TextStyle(color: Color(0xFFACACAC)),
suffixIconColor: Color(0xFFACACAC),
border: OutlineInputBorder(
borderSide: BorderSide.none,
),
contentPadding: EdgeInsets.fromLTRB(16, 20, 16, 12),
errorStyle: TextStyle(fontSize: 14),
),
obscureText: /*!_isShowPassword*/ true,
style: const TextStyle(color: Colors.white),
autocorrect: false,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Bạn chưa xác nhận Mật khẩu mới';
}
if (value != _newPasswordController.text) {
return 'Mật khẩu xác nhận không khớp';
}
return null;
},
),
const Gap(40),
SizedBox(
width: double.infinity,
child: FilledButton(
onPressed: _changePassword,
style: FilledButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
),
child: _isProcessing
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
color: Colors.white,
strokeWidth: 3,
strokeCap: StrokeCap.round,
),
)
: const Text(
'ĐỔI MẬT KHẨU',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
),
Gap(MediaQuery.sizeOf(context).height * 0.15),
],
),
),
),
);
}
}
Loading

0 comments on commit a71497e

Please sign in to comment.