3030
3131namespace OCA \Social \Controller ;
3232
33+ use OCA \Social \Entity \Account ;
34+ use OCA \Social \Entity \Instance ;
35+ use OCA \Social \Repository \InstanceRepository ;
3336use OCA \Social \Tools \Traits \TNCDataResponse ;
3437use Exception ;
35- use OCA \Social \AppInfo \Application ;
38+ use OCA \Social \Entity \Application ;
3639use OCA \Social \Exceptions \ClientException ;
3740use OCA \Social \Exceptions \ClientNotFoundException ;
38- use OCA \Social \Exceptions \InstanceDoesNotExistException ;
39- use OCA \Social \Model \Client \SocialClient ;
4041use OCA \Social \Service \AccountService ;
4142use OCA \Social \Service \CacheActorService ;
42- use OCA \Social \Service \ClientService ;
43+ use OCA \Social \Service \ApplicationService ;
4344use OCA \Social \Service \ConfigService ;
4445use OCA \Social \Service \InstanceService ;
4546use OCA \Social \Service \MiscService ;
4647use OCP \AppFramework \Controller ;
4748use OCP \AppFramework \Http ;
4849use OCP \AppFramework \Http \DataResponse ;
49- use OCP \AppFramework \ Http \ Response ;
50+ use OCP \DB \ ORM \ IEntityManager ;
5051use OCP \IRequest ;
5152use OCP \IURLGenerator ;
5253use OCP \IUserSession ;
@@ -59,17 +60,24 @@ class OAuthController extends Controller {
5960 private InstanceService $ instanceService ;
6061 private AccountService $ accountService ;
6162 private CacheActorService $ cacheActorService ;
62- private ClientService $ clientService ;
63+ private ApplicationService $ clientService ;
6364 private ConfigService $ configService ;
6465 private MiscService $ miscService ;
66+ private IEntityManager $ entityManager ;
6567
6668 public function __construct (
67- IRequest $ request , IUserSession $ userSession , IURLGenerator $ urlGenerator ,
68- InstanceService $ instanceService , AccountService $ accountService ,
69- CacheActorService $ cacheActorService , ClientService $ clientService , ConfigService $ configService ,
70- MiscService $ miscService
69+ IRequest $ request ,
70+ IUserSession $ userSession ,
71+ IURLGenerator $ urlGenerator ,
72+ InstanceService $ instanceService ,
73+ AccountService $ accountService ,
74+ CacheActorService $ cacheActorService ,
75+ ApplicationService $ clientService ,
76+ ConfigService $ configService ,
77+ MiscService $ miscService ,
78+ IEntityManager $ entityManager
7179 ) {
72- parent ::__construct (Application:: APP_NAME , $ request );
80+ parent ::__construct (' social ' , $ request );
7381
7482 $ this ->userSession = $ userSession ;
7583 $ this ->urlGenerator = $ urlGenerator ;
@@ -79,21 +87,19 @@ public function __construct(
7987 $ this ->clientService = $ clientService ;
8088 $ this ->configService = $ configService ;
8189 $ this ->miscService = $ miscService ;
82-
83- $ body = file_get_contents ('php://input ' );
84- $ this ->miscService ->log ('[OAuthController] input: ' . $ body , 0 );
90+ $ this ->entityManager = $ entityManager ;
8591 }
8692
8793
8894 /**
8995 * @NoCSRFRequired
9096 * @PublicPage
9197 */
92- public function nodeinfo (): DataResponse {
98+ public function index (): DataResponse {
9399 $ nodeInfo = [
94100 'links ' => [
95101 'rel ' => 'http://nodeinfo.diaspora.software/ns/schema/2.0 ' ,
96- 'href ' => $ this ->urlGenerator ->linkToRouteAbsolute ('social.OAuth.nodeinfo2 ' )
102+ 'href ' => $ this ->urlGenerator ->linkToRouteAbsolute ('social.OAuth.show ' )
97103 ]
98104 ];
99105
@@ -105,32 +111,24 @@ public function nodeinfo(): DataResponse {
105111 * @NoCSRFRequired
106112 * @PublicPage
107113 */
108- public function nodeinfo2 (): Response {
109- try {
110- $ local = $ this ->instanceService ->getLocal ();
111- $ name = $ local ->getTitle ();
112-
113- $ version = $ local ->getVersion ();
114- $ usage = $ local ->getUsage ();
115- $ openReg = $ local ->isRegistrations ();
116- } catch (InstanceDoesNotExistException $ e ) {
117- $ name = 'Nextcloud Social ' ;
118- $ version = $ this ->configService ->getAppValue ('installed_version ' );
119- $ usage = [];
120- $ openReg = false ;
121- }
114+ public function show (): DataResponse {
115+ $ query = $ this ->entityManager ->createQuery ('SELECT COUNT(a) FROM \OCA\Social\Entity\Account a ' );
116+ $ query ->setCacheable (true );
117+ $ countUser = $ query ->getSingleScalarResult ();
122118
123119 $ nodeInfo = [
124120 "version " => "2.0 " ,
125121 "software " => [
126- "name " => $ name ,
127- "version " => $ version
122+ "name " => ' Nextcloud Social ' ,
123+ "version " => $ this -> configService -> getAppValue ( ' installed_version ' ),
128124 ],
129125 "protocols " => [
130126 "activitypub "
131127 ],
132- "usage " => $ usage ,
133- "openRegistrations " => $ openReg
128+ "usage " => [
129+ "total " => (int )$ countUser ,
130+ ],
131+ "openRegistrations " => false ,
134132 ];
135133
136134 return new DataResponse ($ nodeInfo , Http::STATUS_OK );
@@ -151,10 +149,10 @@ public function apps(
151149 $ redirect_uris = [$ redirect_uris ];
152150 }
153151
154- $ client = new SocialClient ();
152+ $ client = new Application ();
155153 $ client ->setAppWebsite ($ website );
156154 $ client ->setAppRedirectUris ($ redirect_uris );
157- $ client ->setAppScopes ($ client -> getScopesFromString ($ scopes ));
155+ $ client ->setAppScopes (Application:: getScopesFromString ($ scopes ));
158156 $ client ->setAppName ($ client_name );
159157
160158 $ this ->clientService ->createApp ($ client );
@@ -181,6 +179,11 @@ public function authorize(
181179 ): DataResponse {
182180 try {
183181 $ user = $ this ->userSession ->getUser ();
182+ $ accountRepository = $ this ->entityManager ->getRepository (Account::class);
183+ $ accountRepository ->findBy ([
184+ ''
185+ ]);
186+
184187 $ account = $ this ->accountService ->getActorFromUserId ($ user ->getUID ());
185188
186189 if ($ response_type !== 'code ' ) {
0 commit comments