1+ <?php
2+
3+ namespace YogstationPermissions \Api \Controller ;
4+
5+ use XF \Api \Controller \AbstractController ;
6+ use XF \Mvc \ParameterBag ;
7+
8+ /**
9+ * @api-group Linking
10+ */
11+ class Linking extends AbstractController
12+ {
13+ /**
14+ * @api-desc Generates a new linking key for a external account.
15+ *
16+ * @api-in <req> str $account_type The type of account (Byond or Discord)
17+ * @api-in <req> str $account_id The external ID of the account being linked
18+ * @api-in str $limit_ip The IP that should be considered to be making the request. If provided, this will be used to prevent brute force attempts.
19+ *
20+ * @api-out str $key the linking key generated.
21+ * @api-out str $url the url the end user needs to access to link.
22+ */
23+ public function actionPost (ParameterBag $ params )
24+ {
25+ $ this ->assertSuperUserKey ();
26+ $ this ->assertApiScope ('linking ' );
27+
28+ $ key = $ this ->service ('YogstationPermissions:Linking\Generate ' , $ params ->account_type , $ params ->account_type )->generateKey ();
29+
30+ return $ this ->apiSuccess ([
31+ 'key ' => $ key ,
32+ 'url ' => \XF ::app ()->router ('public ' )->buildLink ('canonical:linking/link ' , $ key , ["key " => $ key ]),
33+ ]);
34+ }
35+
36+ public function actionGet (ParameterBag $ params )
37+ {
38+ $ this ->assertSuperUserKey ();
39+ $ this ->assertApiScope ('linking ' );
40+
41+ $ finder = \XF ::finder ('YogstationPermissions:LinkedAccount ' );
42+
43+ $ user = $ finder ->where ('account_id ' , $ params ->account_type )
44+ ->where ('account_type ' , $ params ->account_type )
45+ ->with ('User ' )->fetchOne ();
46+
47+ if (!$ user )
48+ {
49+ return $ this ->error (\XF ::phrase ('yg_no_linked_account ' ));
50+ }
51+
52+ return $ this ->apiSuccess ([
53+ 'user ' => $ user
54+ ]);
55+ }
56+ }
0 commit comments