[#114] Account confirmation email, registration as unconfirmed (config-based), auth...
[akkoma] / lib / pleroma / web / router.ex
1 defmodule Pleroma.Web.Router do
2 use Pleroma.Web, :router
3
4 pipeline :api do
5 plug(:accepts, ["json"])
6 plug(:fetch_session)
7 plug(Pleroma.Plugs.OAuthPlug)
8 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
9 plug(Pleroma.Plugs.UserFetcherPlug)
10 plug(Pleroma.Plugs.SessionAuthenticationPlug)
11 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
12 plug(Pleroma.Plugs.AuthenticationPlug)
13 plug(Pleroma.Plugs.UserEnabledPlug)
14 plug(Pleroma.Plugs.SetUserSessionIdPlug)
15 plug(Pleroma.Plugs.EnsureUserKeyPlug)
16 end
17
18 pipeline :authenticated_api do
19 plug(:accepts, ["json"])
20 plug(:fetch_session)
21 plug(Pleroma.Plugs.OAuthPlug)
22 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
23 plug(Pleroma.Plugs.UserFetcherPlug)
24 plug(Pleroma.Plugs.SessionAuthenticationPlug)
25 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
26 plug(Pleroma.Plugs.AuthenticationPlug)
27 plug(Pleroma.Plugs.UserEnabledPlug)
28 plug(Pleroma.Plugs.SetUserSessionIdPlug)
29 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
30 end
31
32 pipeline :admin_api do
33 plug(:accepts, ["json"])
34 plug(:fetch_session)
35 plug(Pleroma.Plugs.OAuthPlug)
36 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
37 plug(Pleroma.Plugs.UserFetcherPlug)
38 plug(Pleroma.Plugs.SessionAuthenticationPlug)
39 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
40 plug(Pleroma.Plugs.AuthenticationPlug)
41 plug(Pleroma.Plugs.UserEnabledPlug)
42 plug(Pleroma.Plugs.SetUserSessionIdPlug)
43 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
44 plug(Pleroma.Plugs.UserIsAdminPlug)
45 end
46
47 pipeline :mastodon_html do
48 plug(:accepts, ["html"])
49 plug(:fetch_session)
50 plug(Pleroma.Plugs.OAuthPlug)
51 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
52 plug(Pleroma.Plugs.UserFetcherPlug)
53 plug(Pleroma.Plugs.SessionAuthenticationPlug)
54 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
55 plug(Pleroma.Plugs.AuthenticationPlug)
56 plug(Pleroma.Plugs.UserEnabledPlug)
57 plug(Pleroma.Plugs.SetUserSessionIdPlug)
58 plug(Pleroma.Plugs.EnsureUserKeyPlug)
59 end
60
61 pipeline :pleroma_html do
62 plug(:accepts, ["html"])
63 plug(:fetch_session)
64 plug(Pleroma.Plugs.OAuthPlug)
65 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
66 plug(Pleroma.Plugs.UserFetcherPlug)
67 plug(Pleroma.Plugs.SessionAuthenticationPlug)
68 plug(Pleroma.Plugs.AuthenticationPlug)
69 plug(Pleroma.Plugs.EnsureUserKeyPlug)
70 end
71
72 pipeline :well_known do
73 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
74 end
75
76 pipeline :config do
77 plug(:accepts, ["json", "xml"])
78 end
79
80 pipeline :oauth do
81 plug(:accepts, ["html", "json"])
82 end
83
84 pipeline :pleroma_api do
85 plug(:accepts, ["html", "json"])
86 end
87
88 pipeline :mailbox_preview do
89 plug(:accepts, ["html"])
90
91 plug(:put_secure_browser_headers, %{
92 "content-security-policy" =>
93 "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'"
94 })
95 end
96
97 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
98 pipe_through(:pleroma_api)
99 get("/password_reset/:token", UtilController, :show_password_reset)
100 post("/password_reset", UtilController, :password_reset)
101 get("/emoji", UtilController, :emoji)
102 get("/captcha", UtilController, :captcha)
103 end
104
105 scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
106 pipe_through(:admin_api)
107 delete("/user", AdminAPIController, :user_delete)
108 post("/user", AdminAPIController, :user_create)
109 put("/users/tag", AdminAPIController, :tag_users)
110 delete("/users/tag", AdminAPIController, :untag_users)
111
112 get("/permission_group/:nickname", AdminAPIController, :right_get)
113 get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
114 post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add)
115 delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete)
116
117 post("/relay", AdminAPIController, :relay_follow)
118 delete("/relay", AdminAPIController, :relay_unfollow)
119
120 get("/invite_token", AdminAPIController, :get_invite_token)
121 post("/email_invite", AdminAPIController, :email_invite)
122
123 get("/password_reset", AdminAPIController, :get_password_reset)
124 end
125
126 scope "/", Pleroma.Web.TwitterAPI do
127 pipe_through(:pleroma_html)
128 get("/ostatus_subscribe", UtilController, :remote_follow)
129 post("/ostatus_subscribe", UtilController, :do_remote_follow)
130 post("/main/ostatus", UtilController, :remote_subscribe)
131 end
132
133 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
134 pipe_through(:authenticated_api)
135 post("/follow_import", UtilController, :follow_import)
136 post("/change_password", UtilController, :change_password)
137 post("/delete_account", UtilController, :delete_account)
138 end
139
140 scope "/oauth", Pleroma.Web.OAuth do
141 get("/authorize", OAuthController, :authorize)
142 post("/authorize", OAuthController, :create_authorization)
143 post("/token", OAuthController, :token_exchange)
144 post("/revoke", OAuthController, :token_revoke)
145 end
146
147 scope "/api/v1", Pleroma.Web.MastodonAPI do
148 pipe_through(:authenticated_api)
149
150 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
151 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
152 get("/accounts/relationships", MastodonAPIController, :relationships)
153 get("/accounts/search", MastodonAPIController, :account_search)
154 post("/accounts/:id/follow", MastodonAPIController, :follow)
155 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
156 post("/accounts/:id/block", MastodonAPIController, :block)
157 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
158 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
159 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
160 get("/accounts/:id/lists", MastodonAPIController, :account_lists)
161
162 get("/follow_requests", MastodonAPIController, :follow_requests)
163 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
164 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
165
166 post("/follows", MastodonAPIController, :follow)
167
168 get("/blocks", MastodonAPIController, :blocks)
169
170 get("/mutes", MastodonAPIController, :empty_array)
171
172 get("/timelines/home", MastodonAPIController, :home_timeline)
173
174 get("/timelines/direct", MastodonAPIController, :dm_timeline)
175
176 get("/favourites", MastodonAPIController, :favourites)
177
178 post("/statuses", MastodonAPIController, :post_status)
179 delete("/statuses/:id", MastodonAPIController, :delete_status)
180
181 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
182 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
183 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
184 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
185
186 post("/notifications/clear", MastodonAPIController, :clear_notifications)
187 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
188 get("/notifications", MastodonAPIController, :notifications)
189 get("/notifications/:id", MastodonAPIController, :get_notification)
190
191 post("/media", MastodonAPIController, :upload)
192 put("/media/:id", MastodonAPIController, :update_media)
193
194 get("/lists", MastodonAPIController, :get_lists)
195 get("/lists/:id", MastodonAPIController, :get_list)
196 delete("/lists/:id", MastodonAPIController, :delete_list)
197 post("/lists", MastodonAPIController, :create_list)
198 put("/lists/:id", MastodonAPIController, :rename_list)
199 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
200 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
201 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
202
203 get("/domain_blocks", MastodonAPIController, :domain_blocks)
204 post("/domain_blocks", MastodonAPIController, :block_domain)
205 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
206
207 get("/filters", MastodonAPIController, :get_filters)
208 post("/filters", MastodonAPIController, :create_filter)
209 get("/filters/:id", MastodonAPIController, :get_filter)
210 put("/filters/:id", MastodonAPIController, :update_filter)
211 delete("/filters/:id", MastodonAPIController, :delete_filter)
212
213 post("/push/subscription", MastodonAPIController, :create_push_subscription)
214 get("/push/subscription", MastodonAPIController, :get_push_subscription)
215 put("/push/subscription", MastodonAPIController, :update_push_subscription)
216 delete("/push/subscription", MastodonAPIController, :delete_push_subscription)
217
218 get("/suggestions", MastodonAPIController, :suggestions)
219
220 get("/endorsements", MastodonAPIController, :empty_array)
221 end
222
223 scope "/api/web", Pleroma.Web.MastodonAPI do
224 pipe_through(:authenticated_api)
225
226 put("/settings", MastodonAPIController, :put_settings)
227 end
228
229 scope "/api/v1", Pleroma.Web.MastodonAPI do
230 pipe_through(:api)
231 get("/instance", MastodonAPIController, :masto_instance)
232 get("/instance/peers", MastodonAPIController, :peers)
233 post("/apps", MastodonAPIController, :create_app)
234 get("/custom_emojis", MastodonAPIController, :custom_emojis)
235
236 get("/timelines/public", MastodonAPIController, :public_timeline)
237 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
238 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
239
240 get("/statuses/:id", MastodonAPIController, :get_status)
241 get("/statuses/:id/context", MastodonAPIController, :get_context)
242 get("/statuses/:id/card", MastodonAPIController, :empty_object)
243 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
244 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
245
246 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
247 get("/accounts/:id/followers", MastodonAPIController, :followers)
248 get("/accounts/:id/following", MastodonAPIController, :following)
249 get("/accounts/:id", MastodonAPIController, :user)
250
251 get("/trends", MastodonAPIController, :empty_array)
252
253 get("/search", MastodonAPIController, :search)
254 end
255
256 scope "/api/v2", Pleroma.Web.MastodonAPI do
257 pipe_through(:api)
258 get("/search", MastodonAPIController, :search2)
259 end
260
261 scope "/api", Pleroma.Web do
262 pipe_through(:config)
263
264 get("/help/test", TwitterAPI.UtilController, :help_test)
265 post("/help/test", TwitterAPI.UtilController, :help_test)
266 get("/statusnet/config", TwitterAPI.UtilController, :config)
267 get("/statusnet/version", TwitterAPI.UtilController, :version)
268 end
269
270 scope "/api", Pleroma.Web do
271 pipe_through(:api)
272
273 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
274 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
275 get("/users/show", TwitterAPI.Controller, :show_user)
276
277 get("/statuses/followers", TwitterAPI.Controller, :followers)
278 get("/statuses/friends", TwitterAPI.Controller, :friends)
279 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
280 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
281
282 post("/account/register", TwitterAPI.Controller, :register)
283 post("/account/password_reset", TwitterAPI.Controller, :password_reset)
284
285 get("/account/confirm_email/:token", TwitterAPI.Controller, :confirm_email, as: :confirm_email)
286
287 get("/search", TwitterAPI.Controller, :search)
288 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
289 end
290
291 scope "/api", Pleroma.Web do
292 pipe_through(:api)
293
294 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
295
296 get(
297 "/statuses/public_and_external_timeline",
298 TwitterAPI.Controller,
299 :public_and_external_timeline
300 )
301
302 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
303 end
304
305 scope "/api", Pleroma.Web, as: :twitter_api_search do
306 pipe_through(:api)
307 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
308 end
309
310 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
311 pipe_through(:authenticated_api)
312
313 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
314 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
315
316 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
317 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
318 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
319
320 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
321 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
322 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
323 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
324 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
325 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
326
327 # XXX: this is really a pleroma API, but we want to keep the pleroma namespace clean
328 # for now.
329 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
330
331 post("/statuses/update", TwitterAPI.Controller, :status_update)
332 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
333 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
334 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
335
336 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
337 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
338 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
339
340 post("/friendships/create", TwitterAPI.Controller, :follow)
341 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
342 post("/blocks/create", TwitterAPI.Controller, :block)
343 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
344
345 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
346 post("/media/upload", TwitterAPI.Controller, :upload_json)
347 post("/media/metadata/create", TwitterAPI.Controller, :update_media)
348
349 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
350 post("/favorites/create", TwitterAPI.Controller, :favorite)
351 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
352
353 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
354
355 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
356 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
357
358 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
359 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
360
361 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
362 end
363
364 pipeline :ap_relay do
365 plug(:accepts, ["activity+json"])
366 end
367
368 pipeline :ostatus do
369 plug(:accepts, ["xml", "atom", "html", "activity+json"])
370 end
371
372 scope "/", Pleroma.Web do
373 pipe_through(:ostatus)
374
375 get("/objects/:uuid", OStatus.OStatusController, :object)
376 get("/activities/:uuid", OStatus.OStatusController, :activity)
377 get("/notice/:id", OStatus.OStatusController, :notice)
378 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
379 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
380
381 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
382 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
383 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
384 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
385 end
386
387 pipeline :activitypub do
388 plug(:accepts, ["activity+json"])
389 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
390 end
391
392 scope "/", Pleroma.Web.ActivityPub do
393 # XXX: not really ostatus
394 pipe_through(:ostatus)
395
396 get("/users/:nickname/followers", ActivityPubController, :followers)
397 get("/users/:nickname/following", ActivityPubController, :following)
398 get("/users/:nickname/outbox", ActivityPubController, :outbox)
399 end
400
401 scope "/relay", Pleroma.Web.ActivityPub do
402 pipe_through(:ap_relay)
403 get("/", ActivityPubController, :relay)
404 end
405
406 scope "/", Pleroma.Web.ActivityPub do
407 pipe_through(:activitypub)
408 post("/users/:nickname/inbox", ActivityPubController, :inbox)
409 post("/inbox", ActivityPubController, :inbox)
410 end
411
412 scope "/.well-known", Pleroma.Web do
413 pipe_through(:well_known)
414
415 get("/host-meta", WebFinger.WebFingerController, :host_meta)
416 get("/webfinger", WebFinger.WebFingerController, :webfinger)
417 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
418 end
419
420 scope "/nodeinfo", Pleroma.Web do
421 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
422 end
423
424 scope "/", Pleroma.Web.MastodonAPI do
425 pipe_through(:mastodon_html)
426
427 get("/web/login", MastodonAPIController, :login)
428 post("/web/login", MastodonAPIController, :login_post)
429 get("/web/*path", MastodonAPIController, :index)
430 delete("/auth/sign_out", MastodonAPIController, :logout)
431 end
432
433 pipeline :remote_media do
434 end
435
436 scope "/proxy/", Pleroma.Web.MediaProxy do
437 pipe_through(:remote_media)
438 get("/:sig/:url", MediaProxyController, :remote)
439 get("/:sig/:url/:filename", MediaProxyController, :remote)
440 end
441
442 if Mix.env() == :dev do
443 scope "/dev" do
444 pipe_through([:mailbox_preview])
445
446 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
447 end
448 end
449
450 scope "/", Fallback do
451 get("/registration/:token", RedirectController, :registration_page)
452 get("/*path", RedirectController, :redirector)
453
454 options("/*path", RedirectController, :empty)
455 end
456 end
457
458 defmodule Fallback.RedirectController do
459 use Pleroma.Web, :controller
460
461 def redirector(conn, _params) do
462 conn
463 |> put_resp_content_type("text/html")
464 |> send_file(200, Pleroma.Plugs.InstanceStatic.file_path("index.html"))
465 end
466
467 def registration_page(conn, params) do
468 redirector(conn, params)
469 end
470
471 def empty(conn, _params) do
472 conn
473 |> put_status(204)
474 |> text("")
475 end
476 end