@@ -881,7 +881,87 @@ public function toggle_campaign_active()
881881 }
882882
883883 $ this ->campaign_model ->set_active_status ($ id , $ is_active );
884- redirect ('admin/campagnes ' );
885- }
886- }
884+ redirect ('admin/campagnes ' );
885+ }
886+
887+ // API KEYS MANAGEMENT (admin only)
888+
889+ public function api_keys ()
890+ {
891+ $ data = $ this ->data ;
892+
893+ if ($ data ['usernameType ' ] != 'admin ' ) {
894+ show_404 ();
895+ }
896+
897+ $ this ->load ->model ('api_key_model ' );
898+ $ this ->load ->model ('user_model ' );
899+
900+ $ data ['title ' ] = 'Gestion des clés API ' ;
901+ $ data ['keys ' ] = $ this ->api_key_model ->get_all_keys ();
902+
903+ // Meta
904+ $ data ['title_meta ' ] = $ data ['title ' ] . ' - Dashboard | Datan ' ;
905+
906+ // Views
907+ $ this ->load ->view ('dashboard/header ' , $ data );
908+ $ this ->load ->view ('dashboard/api-keys/list ' , $ data );
909+ $ this ->load ->view ('dashboard/footer ' );
910+ }
911+
912+ public function api_keys_create ()
913+ {
914+ $ data = $ this ->data ;
915+
916+ if ($ data ['usernameType ' ] != 'admin ' ) {
917+ show_404 ();
918+ }
919+
920+ $ this ->load ->model ('api_key_model ' );
921+ $ this ->load ->model ('user_model ' );
922+
923+ $ data ['title ' ] = 'Créer une clé API ' ;
924+ $ data ['users ' ] = $ this ->user_model ->get_team_users ();
925+
926+ // Available endpoints and methods
927+ $ data ['endpoints ' ] = $ this ->api_key_model ->get_available_endpoints ();
928+
929+ // Form validation
930+ $ this ->form_validation ->set_rules ('name ' , 'Nom ' , 'required ' );
931+ $ this ->form_validation ->set_rules ('user_id ' , 'Utilisateur ' , 'required ' );
932+
933+ if ($ this ->form_validation ->run () === FALSE ) {
934+ $ data ['title_meta ' ] = $ data ['title ' ] . ' - Dashboard | Datan ' ;
935+ $ this ->load ->view ('dashboard/header ' , $ data );
936+ $ this ->load ->view ('dashboard/api-keys/create ' , $ data );
937+ $ this ->load ->view ('dashboard/footer ' );
938+ } else {
939+ $ permissions = $ this ->input ->post ('all_permissions ' ) ? null : $ this ->input ->post ('permissions ' );
940+ $ result = $ this ->api_key_model ->create_key (
941+ $ this ->input ->post ('user_id ' ),
942+ $ this ->input ->post ('name ' ),
943+ $ permissions
944+ );
945+
946+ // Store the key in flash data to show it once
947+ $ this ->session ->set_flashdata ('new_api_key ' , $ result ['key ' ]);
948+ redirect ('admin/api-keys ' );
949+ }
950+ }
951+
952+ public function api_keys_revoke ($ id )
953+ {
954+ $ data = $ this ->data ;
955+
956+ if ($ data ['usernameType ' ] != 'admin ' ) {
957+ show_404 ();
958+ }
959+
960+ $ this ->load ->model ('api_key_model ' );
961+ $ this ->api_key_model ->revoke_key ($ id );
962+
963+ $ this ->session ->set_flashdata ('success ' , 'Clé API révoquée avec succès ' );
964+ redirect ('admin/api-keys ' );
965+ }
966+ }
887967?>
0 commit comments