-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Mockin-2024/25-logout
logout
- Loading branch information
Showing
6 changed files
with
142 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:mockin/login/login.dart'; | ||
import 'package:mockin/storage/jwt_token.dart'; | ||
import 'package:mockin/storage/user_email.dart'; | ||
|
||
class SettingService { | ||
static void logout({ | ||
required BuildContext context, | ||
}) async { | ||
await JwtToken().delete('lastEmail'); | ||
await JwtToken().delete(UserEmail().getEmail()!); | ||
if (!context.mounted) return; | ||
Navigator.pushReplacement( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => const Login(), | ||
), | ||
); | ||
} | ||
|
||
static Future<bool> getAutoLogin() async { | ||
var rst = await JwtToken().read('autoLogin') ?? ''; | ||
if (rst == '') { | ||
await JwtToken().save('autoLogin', 'false'); | ||
return false; | ||
} | ||
if (rst == 'false') { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
static Future<void> setAutoLogin() async { | ||
var rst = await JwtToken().read('autoLogin'); | ||
if (rst == 'false') { | ||
await JwtToken().save('autoLogin', 'true'); | ||
} else { | ||
await JwtToken().save('autoLogin', 'false'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:mockin/service/setting_service.dart'; | ||
import 'package:mockin/widgets/signup/signup_button.dart'; | ||
|
||
class Logout extends StatelessWidget { | ||
const Logout({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SignupButton( | ||
tt: '로그아웃', | ||
signUpFunction: () async { | ||
SettingService.logout(context: context); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:mockin/service/setting_service.dart'; | ||
import 'package:mockin/widgets/text/category_text.dart'; | ||
|
||
class SetAutoLogin extends StatefulWidget { | ||
const SetAutoLogin({super.key}); | ||
|
||
@override | ||
State<SetAutoLogin> createState() => _SetAutoLoginState(); | ||
} | ||
|
||
class _SetAutoLoginState extends State<SetAutoLogin> { | ||
var auto = false; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
curAutoLogin(); | ||
} | ||
|
||
void curAutoLogin() async { | ||
final rst = await SettingService.getAutoLogin(); | ||
setState(() { | ||
auto = rst; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
const CategoryText(tt: '자동로그인'), | ||
IconButton( | ||
onPressed: () async { | ||
SettingService.setAutoLogin(); | ||
setState(() { | ||
auto = !auto; | ||
}); | ||
}, | ||
icon: auto | ||
? const Icon(Icons.check_box_outlined) | ||
: const Icon(Icons.check_box_outline_blank_outlined)), | ||
], | ||
); | ||
} | ||
} |