6198ec6e498b8ff34fca9e70f19d143542348fe7
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2013 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 from werkzeug
.exceptions
import MethodNotAllowed
20 from werkzeug
.wrappers
import BaseResponse
22 from mediagoblin
.meddleware
.csrf
import csrf_exempt
23 from mediagoblin
.tools
.response
import render_404
24 from .tools
import CmdTable
, PwgNamedArray
, response_xml
27 _log
= logging
.getLogger(__name__
)
30 @CmdTable("pwg.session.login", True)
31 def pwg_login(request
):
32 username
= request
.form
.get("username")
33 password
= request
.form
.get("password")
34 _log
.info("Login for %r/%r...", username
, password
)
38 @CmdTable("pwg.session.logout")
39 def pwg_logout(request
):
44 @CmdTable("pwg.getVersion")
45 def pwg_getversion(request
):
46 return "piwigo 2.5.0 (MediaGoblin)"
49 @CmdTable("pwg.session.getStatus")
50 def pwg_session_getStatus(request
):
51 return {'username': "fake_user"}
54 @CmdTable("pwg.categories.getList")
55 def pwg_categories_getList(request
):
56 catlist
= ({'id': -29711,
57 'uppercats': "-29711",
58 'name': "All my images"},)
60 'categories': PwgNamedArray(
76 def possibly_add_cookie(request
, response
):
77 # TODO: We should only add a *real* cookie, if
78 # authenticated. And if there is no cookie already.
83 path
=request
.environ
['SCRIPT_NAME'],
84 domain
=mg_globals
.app_config
.get('csrf_cookie_domain'),
85 secure
=(request
.scheme
.lower() == 'https'),
91 if request
.method
not in ("GET", "POST"):
92 _log
.error("Method %r not supported", request
.method
)
93 raise MethodNotAllowed()
95 func
= CmdTable
.find_func(request
)
97 _log
.warn("wsphp: Unhandled %s %r %r", request
.method
,
98 request
.args
, request
.form
)
99 return render_404(request
)
101 result
= func(request
)
103 if isinstance(result
, BaseResponse
):
106 response
= response_xml(result
)
108 possibly_add_cookie(request
, response
)