-
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.
feat(oauth): added pages to link our account with microsoft, spotify …
…google and discord oauth (only microsoft fonctional)
- Loading branch information
1 parent
647ea2f
commit 18a059a
Showing
9 changed files
with
232 additions
and
53 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,70 +1,44 @@ | ||
import 'package:client_mobile/data/action.dart'; | ||
import 'package:client_mobile/services/login/auth_service.dart'; | ||
import 'package:client_mobile/widgets/action_button.dart'; | ||
import 'package:client_mobile/widgets/reaction_button.dart'; | ||
import 'package:client_mobile/pages/dashboard/service_connection.dart'; | ||
import 'package:client_mobile/pages/dashboard/workflow.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
class DashboardPage extends StatefulWidget { | ||
const DashboardPage({super.key}); | ||
|
||
@override | ||
State<DashboardPage> createState() => _DashboardPageState(); | ||
_DashboardPageState createState() => _DashboardPageState(); | ||
} | ||
|
||
class _DashboardPageState extends State<DashboardPage> { | ||
WorkflowActionReaction? action; | ||
WorkflowActionReaction? reaction; | ||
int _currentIndex = 0; // Pour suivre l'index actuel | ||
|
||
void onActionSelected(WorkflowActionReaction selected, String serviceName) { | ||
setState(() { | ||
action = selected; | ||
action!.serviceName = serviceName; | ||
}); | ||
} | ||
final List<Widget> _pages = [ | ||
WorkflowPage(), // Votre page actuelle avec les boutons Action et Réaction | ||
ServiceConnectionPage(), // Une nouvelle page pour la connexion des services | ||
]; | ||
|
||
void onReactionSelected(WorkflowActionReaction selected, String serviceName) { | ||
void _onTabTapped(int index) { | ||
setState(() { | ||
reaction = selected; | ||
reaction!.serviceName = serviceName; | ||
_currentIndex = index; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Column( | ||
children: [ | ||
const SizedBox(height: 50), | ||
ActionButton(onActionSelected: onActionSelected, action: action), | ||
const SizedBox(height: 30), | ||
ReactionButton( | ||
onActionSelected: onReactionSelected, reaction: reaction), | ||
const SizedBox(height: 50), | ||
ElevatedButton( | ||
onPressed: () async { | ||
if (action == null || reaction == null) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar( | ||
content: Text("Please refer an action and a reaction"), | ||
backgroundColor: Colors.red, | ||
), | ||
); | ||
} else { | ||
print("create workflow"); | ||
} | ||
}, | ||
child: const Text("Create")) | ||
body: _pages[_currentIndex], | ||
bottomNavigationBar: BottomNavigationBar( | ||
currentIndex: _currentIndex, | ||
onTap: _onTabTapped, | ||
items: const [ | ||
BottomNavigationBarItem( | ||
icon: Icon(Icons.home), | ||
label: 'Home', | ||
), | ||
BottomNavigationBarItem( | ||
icon: Icon(Icons.settings), | ||
label: 'Services', | ||
), | ||
], | ||
), | ||
floatingActionButton: FloatingActionButton( | ||
onPressed: () async { | ||
bool hasLogout = await AuthService.logout(); | ||
if (hasLogout) context.pushReplacement("/login"); | ||
}, | ||
tooltip: 'Logout', | ||
child: const Icon(Icons.login), | ||
), | ||
); | ||
} | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
client_mobile/lib/pages/dashboard/service_connection.dart
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,100 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:client_mobile/services/microsoft/microsoft_auth_service.dart'; | ||
import 'package:client_mobile/widgets/sign_in_button.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | ||
|
||
class ServiceConnectionPage extends StatefulWidget { | ||
const ServiceConnectionPage({super.key}); | ||
|
||
@override | ||
State<ServiceConnectionPage> createState() => _ServiceConnectionPageState(); | ||
} | ||
|
||
class _ServiceConnectionPageState extends State<ServiceConnectionPage> { | ||
FlutterSecureStorage secureStorage = const FlutterSecureStorage(); | ||
|
||
String? microsoftToken; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_loadMicrosoftToken(); | ||
} | ||
|
||
Future<void> _loadMicrosoftToken() async { | ||
String? token = await secureStorage.read(key: "microsoft_access_token"); | ||
print("token microsoft : $token"); | ||
setState(() { | ||
microsoftToken = token; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.spaceAround, | ||
children: [ | ||
if (microsoftToken == null) | ||
SignInButton( | ||
onPressed: () async { | ||
MicrosoftAuthService.auth(context); | ||
await _loadMicrosoftToken(); | ||
}, | ||
label: "Link with Microsoft", | ||
image: Image.asset( | ||
"assets/images/microsoft.png", | ||
width: 40, | ||
height: 30, | ||
), | ||
) | ||
else | ||
GestureDetector( | ||
onTap: () async { | ||
await secureStorage.delete(key: "microsoft_access_token"); | ||
setState(() { | ||
microsoftToken = null; | ||
}); | ||
}, | ||
child: const Text( | ||
"✅ Microsoft is already linked", | ||
style: TextStyle( | ||
fontSize: 16, | ||
fontWeight: FontWeight.bold, | ||
color: Colors.green), | ||
), | ||
), | ||
SignInButton( | ||
onPressed: () {}, | ||
label: "Link with Spotify", | ||
image: Image.asset( | ||
"assets/images/spotify_green.png", | ||
width: 40, | ||
height: 30, | ||
), | ||
), | ||
SignInButton( | ||
onPressed: () {}, | ||
label: "Link with Google", | ||
image: Image.asset( | ||
"assets/images/google.png", | ||
width: 40, | ||
height: 30, | ||
), | ||
), | ||
SignInButton( | ||
onPressed: () {}, | ||
label: "Link with Discord", | ||
image: Image.asset( | ||
"assets/images/discord.png", | ||
width: 40, | ||
height: 30, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
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,70 @@ | ||
import 'package:client_mobile/data/action.dart'; | ||
import 'package:client_mobile/services/login/auth_service.dart'; | ||
import 'package:client_mobile/widgets/action_button.dart'; | ||
import 'package:client_mobile/widgets/reaction_button.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
class WorkflowPage extends StatefulWidget { | ||
const WorkflowPage({super.key}); | ||
|
||
@override | ||
State<WorkflowPage> createState() => _WorkflowPageState(); | ||
} | ||
|
||
class _WorkflowPageState extends State<WorkflowPage> { | ||
WorkflowActionReaction? action; | ||
WorkflowActionReaction? reaction; | ||
|
||
void onActionSelected(WorkflowActionReaction selected, String serviceName) { | ||
setState(() { | ||
action = selected; | ||
action!.serviceName = serviceName; | ||
}); | ||
} | ||
|
||
void onReactionSelected(WorkflowActionReaction selected, String serviceName) { | ||
setState(() { | ||
reaction = selected; | ||
reaction!.serviceName = serviceName; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Column( | ||
children: [ | ||
const SizedBox(height: 50), | ||
ActionButton(onActionSelected: onActionSelected, action: action), | ||
const SizedBox(height: 30), | ||
ReactionButton( | ||
onActionSelected: onReactionSelected, reaction: reaction), | ||
const SizedBox(height: 50), | ||
ElevatedButton( | ||
onPressed: () async { | ||
if (action == null || reaction == null) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar( | ||
content: Text("Please refer an action and a reaction"), | ||
backgroundColor: Colors.red, | ||
), | ||
); | ||
} else { | ||
print("create workflow"); | ||
} | ||
}, | ||
child: const Text("Create")) | ||
], | ||
), | ||
floatingActionButton: FloatingActionButton( | ||
onPressed: () async { | ||
bool hasLogout = await AuthService.logout(); | ||
if (hasLogout) context.pushReplacement("/login"); | ||
}, | ||
tooltip: 'Logout', | ||
child: const Icon(Icons.login), | ||
), | ||
); | ||
} | ||
} |
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