##// END OF EJS Templates
pyramid: if possible fetch csrf tokens from pyramid session....
marcink -
r1918:de4c5093 default
parent child Browse files
Show More
@@ -1906,13 +1906,18 b' def secure_form(url, method="POST", mult'
1906 1906 """
1907 1907 from webhelpers.pylonslib.secure_form import insecure_form
1908 1908 form = insecure_form(url, method, multipart, **attrs)
1909 token = csrf_input()
1909
1910 session = None
1911 # TODO(marcink): after pyramid migration require request variable ALWAYS
1912 if 'request' in attrs:
1913 session = attrs['request'].session
1914
1915 token = literal(
1916 '<input type="hidden" id="{}" name="{}" value="{}">'.format(
1917 csrf_token_key, csrf_token_key, get_csrf_token(session)))
1918
1910 1919 return literal("%s\n%s" % (form, token))
1911 1920
1912 def csrf_input():
1913 return literal(
1914 '<input type="hidden" id="{}" name="{}" value="{}">'.format(
1915 csrf_token_key, csrf_token_key, get_csrf_token()))
1916 1921
1917 1922 def dropdownmenu(name, selected, options, enable_filter=False, **attrs):
1918 1923 select_html = select(name, selected, options, **attrs)
@@ -49,6 +49,7 b' from pkg_resources import resource_filen'
49 49 from formencode import All, Pipe
50 50
51 51 from pylons.i18n.translation import _
52 from pyramid.threadlocal import get_current_request
52 53
53 54 from rhodecode import BACKENDS
54 55 from rhodecode.lib import helpers
@@ -66,6 +67,7 b' class RhodecodeFormZPTRendererFactory(de'
66 67 """ Subclass of ZPTRendererFactory to add rhodecode context variables """
67 68 def __call__(self, template_name, **kw):
68 69 kw['h'] = helpers
70 kw['request'] = get_current_request()
69 71 return self.load(template_name)(**kw)
70 72
71 73
@@ -38,7 +38,7 b''
38 38 </div>
39 39
40 40 <div class="main-content-full-width">
41 ${h.secure_form(request.resource_path(resource, route_name='auth_home'))}
41 ${h.secure_form(request.resource_path(resource, route_name='auth_home'), request=request)}
42 42 <div class="form">
43 43
44 44 <div class="panel panel-default">
@@ -47,7 +47,7 b''
47 47 <div class="panel-body">
48 48 <div class="plugin_form">
49 49 <div class="fields">
50 ${h.secure_form(request.resource_path(resource, route_name='auth_home'))}
50 ${h.secure_form(request.resource_path(resource, route_name='auth_home'), request=request)}
51 51 <div class="form">
52 52
53 53 %for node in plugin.get_settings_schema():
@@ -26,7 +26,7 b''
26 26 <div class="table">
27 27
28 28 <div id="files_data">
29 ${h.secure_form(h.route_path('gist_update', gist_id=c.gist.gist_access_id), id='eform', method='POST')}
29 ${h.secure_form(h.route_path('gist_update', gist_id=c.gist.gist_access_id), id='eform', method='POST', request=request)}
30 30 <div>
31 31 <input type="hidden" value="${c.file_last_commit.raw_id}" name="parent_hash">
32 32 <textarea id="description" name="description"
@@ -25,7 +25,7 b''
25 25
26 26 <div class="table">
27 27 <div id="files_data">
28 ${h.secure_form(h.route_path('gists_create'), id='eform', method='POST')}
28 ${h.secure_form(h.route_path('gists_create'), id='eform', method='POST', request=request)}
29 29 <div>
30 30 <textarea id="description" name="description" placeholder="${_('Gist description ...')}"></textarea>
31 31
@@ -45,7 +45,7 b''
45 45 <div class="stats">
46 46 %if h.HasPermissionAny('hg.admin')() or c.gist.gist_owner == c.rhodecode_user.user_id:
47 47 <div class="remove_gist">
48 ${h.secure_form(h.route_path('gist_delete', gist_id=c.gist.gist_access_id), method='POST')}
48 ${h.secure_form(h.route_path('gist_delete', gist_id=c.gist.gist_access_id), method='POST', request=request)}
49 49 ${h.submit('remove_gist', _('Delete'),class_="btn btn-mini btn-danger",onclick="return confirm('"+_('Confirm to delete this Gist')+"');")}
50 50 ${h.end_form()}
51 51 </div>
@@ -42,7 +42,7 b''
42 42 %endif
43 43 </td>
44 44 <td class="td-action">
45 ${h.secure_form(h.route_path('my_account_auth_tokens_delete'), method='post')}
45 ${h.secure_form(h.route_path('my_account_auth_tokens_delete'), method='POST', request=request)}
46 46 ${h.hidden('del_auth_token', auth_token.user_api_key_id)}
47 47 <button class="btn btn-link btn-danger" type="submit"
48 48 onclick="return confirm('${_('Confirm to remove this auth token: %s') % auth_token.token_obfuscated}');">
@@ -59,7 +59,7 b''
59 59 </div>
60 60
61 61 <div class="user_auth_tokens">
62 ${h.secure_form(h.route_path('my_account_auth_tokens_add'), method='post')}
62 ${h.secure_form(h.route_path('my_account_auth_tokens_add'), method='POST', request=request)}
63 63 <div class="form form-vertical">
64 64 <!-- fields -->
65 65 <div class="fields">
@@ -25,7 +25,7 b''
25 25 <span class="user email">${em.email}</span>
26 26 </td>
27 27 <td class="td-action">
28 ${h.secure_form(h.route_path('my_account_emails_delete'), method='POST')}
28 ${h.secure_form(h.route_path('my_account_emails_delete'), method='POST', request=request)}
29 29 ${h.hidden('del_email_id',em.email_id)}
30 30 <button class="btn btn-link btn-danger" type="submit" id="${'remove_email_%s'.format(em.email_id)}"
31 31 onclick="return confirm('${_('Confirm to delete this email: {}').format(em.email)}');">
@@ -48,7 +48,7 b''
48 48 </div>
49 49
50 50 <div>
51 ${h.secure_form(h.route_path('my_account_emails_add'), method='POST')}
51 ${h.secure_form(h.route_path('my_account_emails_add'), method='POST', request=request)}
52 52 <div class="form">
53 53 <!-- fields -->
54 54 <div class="fields">
@@ -6,7 +6,7 b''
6 6 </div>
7 7
8 8 <div class="panel-body">
9 ${h.secure_form(h.route_path('my_account_update'), class_='form', method='POST')}
9 ${h.secure_form(h.route_path('my_account_update'), class_='form', method='POST', request=request)}
10 10 <% readonly = None %>
11 11 <% disabled = "" %>
12 12
@@ -20,7 +20,7 b''
20 20 <td class="td-iprange"><div class="ip">${h.ip_range(ip.ip_addr)}</div></td>
21 21 <td class="td-description"><div class="ip">${ip.description}</div></td>
22 22 <td class="td-action">
23 ${h.secure_form(h.route_path('edit_user_ips_delete', user_id=c.user.user_id), method='POST')}
23 ${h.secure_form(h.route_path('edit_user_ips_delete', user_id=c.user.user_id), method='POST', request=request)}
24 24 ${h.hidden('del_ip_id',ip.ip_id)}
25 25 ${h.hidden('default_user', 'True')}
26 26 ${h.submit('remove_',_('Delete'),id="remove_ip_%s" % ip.ip_id,
@@ -40,7 +40,7 b''
40 40 </table>
41 41 </div>
42 42
43 ${h.secure_form(h.route_path('edit_user_ips_add', user_id=c.user.user_id), method='POST')}
43 ${h.secure_form(h.route_path('edit_user_ips_add', user_id=c.user.user_id), method='POST', request=request)}
44 44 <div class="form">
45 45 <!-- fields -->
46 46 <div class="fields">
@@ -24,7 +24,7 b''
24 24 <h3 class="panel-title">${_('Fork Reference')} <a class="permalink" href="#advanced-fork"></a></h3>
25 25 </div>
26 26 <div class="panel-body">
27 ${h.secure_form(h.route_path('edit_repo_advanced_fork', repo_name=c.repo_info.repo_name), method='POST')}
27 ${h.secure_form(h.route_path('edit_repo_advanced_fork', repo_name=c.repo_info.repo_name), method='POST', request=request)}
28 28
29 29 % if c.repo_info.fork:
30 30 <div class="panel-body-title-text">${h.literal(_('This repository is a fork of %(repo_link)s') % {'repo_link': h.link_to_if(c.has_origin_repo_read_perm,c.repo_info.fork.repo_name, h.route_path('repo_summary', repo_name=c.repo_info.fork.repo_name))})}
@@ -48,7 +48,7 b''
48 48 <h3 class="panel-title">${_('Public Journal Visibility')} <a class="permalink" href="#advanced-journal"></a></h3>
49 49 </div>
50 50 <div class="panel-body">
51 ${h.secure_form(h.route_path('edit_repo_advanced_journal', repo_name=c.repo_info.repo_name), method='POST')}
51 ${h.secure_form(h.route_path('edit_repo_advanced_journal', repo_name=c.repo_info.repo_name), method='POST', request=request)}
52 52 <div class="field">
53 53 %if c.in_public_journal:
54 54 <button class="btn btn-small" type="submit">
@@ -73,7 +73,7 b''
73 73 <h3 class="panel-title">${_('Locking state')} <a class="permalink" href="#advanced-locking"></a></h3>
74 74 </div>
75 75 <div class="panel-body">
76 ${h.secure_form(h.route_path('edit_repo_advanced_locking', repo_name=c.repo_info.repo_name), method='POST')}
76 ${h.secure_form(h.route_path('edit_repo_advanced_locking', repo_name=c.repo_info.repo_name), method='POST', request=request)}
77 77
78 78 %if c.repo_info.locked[0]:
79 79 <div class="panel-body-title-text">${'Locked by %s on %s. Lock reason: %s' % (h.person_by_id(c.repo_info.locked[0]),
@@ -113,7 +113,7 b''
113 113 <h3 class="panel-title">${_('Delete repository')} <a class="permalink" href="#advanced-delete"></a></h3>
114 114 </div>
115 115 <div class="panel-body">
116 ${h.secure_form(h.route_path('edit_repo_advanced_delete', repo_name=c.repo_name), method='POST')}
116 ${h.secure_form(h.route_path('edit_repo_advanced_delete', repo_name=c.repo_name), method='POST', request=request)}
117 117 <table class="display">
118 118 <tr>
119 119 <td>
@@ -14,7 +14,7 b''
14 14 </code>
15 15 </p>
16 16
17 ${h.secure_form(h.route_path('edit_repo_caches', repo_name=c.repo_name), method='POST')}
17 ${h.secure_form(h.route_path('edit_repo_caches', repo_name=c.repo_name), method='POST', request=request)}
18 18 <div class="form">
19 19 <div class="fields">
20 20 ${h.submit('reset_cache_%s' % c.repo_info.repo_name,_('Invalidate repository cache'),class_="btn btn-small",onclick="return confirm('"+_('Confirm to invalidate repository cache')+"');")}
@@ -5,7 +5,7 b''
5 5 <h3 class="panel-title">${_('Repository Permissions')}</h3>
6 6 </div>
7 7 <div class="panel-body">
8 ${h.secure_form(h.route_path('edit_repo_perms', repo_name=c.repo_name), method='POST')}
8 ${h.secure_form(h.route_path('edit_repo_perms', repo_name=c.repo_name), method='POST', request=request)}
9 9 <table id="permissions_manage" class="rctable permissions">
10 10 <tr>
11 11 <th class="td-radio">${_('None')}</th>
@@ -6,7 +6,7 b''
6 6 <h3 class="panel-title">${_('Settings for Repository: %s') % c.rhodecode_db_repo.repo_name}</h3>
7 7 </div>
8 8 <div class="panel-body">
9 ${h.secure_form(h.route_path('edit_repo', repo_name=c.rhodecode_db_repo.repo_name), method='POST')}
9 ${h.secure_form(h.route_path('edit_repo', repo_name=c.rhodecode_db_repo.repo_name), method='POST', request=request)}
10 10 <div class="form">
11 11 <!-- fields -->
12 12 <div class="fields">
@@ -9,7 +9,7 b''
9 9 ${_('In the first step commits will be verified for existance in the repository')}. </br>
10 10 ${_('In the second step, correct commits will be available for stripping')}.
11 11 </p>
12 ${h.secure_form(h.route_path('strip_check', repo_name=c.repo_info.repo_name), method='post')}
12 ${h.secure_form(h.route_path('strip_check', repo_name=c.repo_info.repo_name), method='POST', request=request)}
13 13 <div id="change_body" class="field">
14 14 <div id="box-1" class="inputx locked_input">
15 15 <input class="text" id="changeset_id-1" name="changeset_id-1" size="59"
@@ -28,7 +28,7 b''
28 28 <h3 class="panel-title">${_('Cleanup Old Sessions')}</h3>
29 29 </div>
30 30 <div class="panel-body">
31 ${h.secure_form(h.route_path('admin_settings_sessions_cleanup'), method='post')}
31 ${h.secure_form(h.route_path('admin_settings_sessions_cleanup'), method='POST', request=request)}
32 32
33 33 <p>
34 34 ${_('Cleanup user sessions that were not active during chosen time frame.')} <br/>
@@ -38,7 +38,7 b''
38 38 %endif
39 39 </td>
40 40 <td class="td-action">
41 ${h.secure_form(h.route_path('edit_user_auth_tokens_delete', user_id=c.user.user_id), method='POST')}
41 ${h.secure_form(h.route_path('edit_user_auth_tokens_delete', user_id=c.user.user_id), method='POST', request=request)}
42 42 ${h.hidden('del_auth_token', auth_token.user_api_key_id)}
43 43 <button class="btn btn-link btn-danger" type="submit"
44 44 onclick="return confirm('${_('Confirm to remove this auth token: %s') % auth_token.token_obfuscated}');">
@@ -55,7 +55,7 b''
55 55 </div>
56 56
57 57 <div class="user_auth_tokens">
58 ${h.secure_form(h.route_path('edit_user_auth_tokens_add', user_id=c.user.user_id), method='POST')}
58 ${h.secure_form(h.route_path('edit_user_auth_tokens_add', user_id=c.user.user_id), method='POST', request=request)}
59 59 <div class="form form-vertical">
60 60 <!-- fields -->
61 61 <div class="fields">
@@ -24,7 +24,7 b''
24 24 <span class="user email">${em.email}</span>
25 25 </td>
26 26 <td class="td-action">
27 ${h.secure_form(h.route_path('edit_user_emails_delete', user_id=c.user.user_id), method='POST')}
27 ${h.secure_form(h.route_path('edit_user_emails_delete', user_id=c.user.user_id), method='POST', request=request)}
28 28 ${h.hidden('del_email_id', em.email_id)}
29 29 <button class="btn btn-link btn-danger" type="submit"
30 30 onclick="return confirm('${_('Confirm to delete this email: %s') % em.email}');">
@@ -46,7 +46,7 b''
46 46 </table>
47 47 </div>
48 48
49 ${h.secure_form(h.route_path('edit_user_emails_add', user_id=c.user.user_id), method='POST')}
49 ${h.secure_form(h.route_path('edit_user_emails_add', user_id=c.user.user_id), method='POST', request=request)}
50 50 <div class="form">
51 51 <!-- fields -->
52 52 <div class="fields">
@@ -19,7 +19,7 b''
19 19 </div>
20 20
21 21 <div class="groups_management">
22 ${h.secure_form(h.route_path('edit_user_groups_management_updates', user_id=c.user.user_id), method='post')}
22 ${h.secure_form(h.route_path('edit_user_groups_management_updates', user_id=c.user.user_id), method='POST', request=request)}
23 23 <div id="repos_list_wrap">
24 24 <table id="user_group_list_table" class="display"></table>
25 25 </div>
@@ -30,7 +30,7 b''
30 30 <td class="td-iprange"><div class="ip">${h.ip_range(ip.ip_addr)}</div></td>
31 31 <td class="td-description"><div class="ip">${ip.description}</div></td>
32 32 <td class="td-action">
33 ${h.secure_form(h.route_path('edit_user_ips_delete', user_id=c.user.user_id), method='POST')}
33 ${h.secure_form(h.route_path('edit_user_ips_delete', user_id=c.user.user_id), method='POST', request=request)}
34 34 ${h.hidden('del_ip_id', ip.ip_id)}
35 35 ${h.submit('remove_', _('Delete'),id="remove_ip_%s" % ip.ip_id,
36 36 class_="btn btn-link btn-danger", onclick="return confirm('"+_('Confirm to delete this ip: %s') % ip.ip_addr+"');")}
@@ -51,7 +51,7 b''
51 51 </div>
52 52
53 53 <div>
54 ${h.secure_form(h.route_path('edit_user_ips_add', user_id=c.user.user_id), method='POST')}
54 ${h.secure_form(h.route_path('edit_user_ips_add', user_id=c.user.user_id), method='POST', request=request)}
55 55 <div class="form">
56 56 <!-- fields -->
57 57 <div class="fields">
@@ -348,7 +348,7 b''
348 348 <li>${h.link_to(_(u'My personal group'), h.route_path('repo_group_home', repo_group_name=c.rhodecode_user.personal_repo_group.group_name))}</li>
349 349 % endif
350 350 <li class="logout">
351 ${h.secure_form(h.route_path('logout'))}
351 ${h.secure_form(h.route_path('logout'), request=request)}
352 352 ${h.submit('log_out', _(u'Sign Out'),class_="btn btn-primary")}
353 353 ${h.end_form()}
354 354 </li>
@@ -119,7 +119,7 b''
119 119 <i class="icon-pencil"></i>Edit</a>
120 120 </div>
121 121 <div class="grid_delete">
122 ${h.secure_form(h.route_path('edit_repo_advanced_delete', repo_name=repo_name), method='POST')}
122 ${h.secure_form(h.route_path('edit_repo_advanced_delete', repo_name=repo_name), method='POST', request=request)}
123 123 ${h.submit('remove_%s' % repo_name,_('Delete'),class_="btn btn-link btn-danger",
124 124 onclick="return confirm('"+_('Confirm to delete this repository: %s') % repo_name+"');")}
125 125 ${h.end_form()}
@@ -27,7 +27,7 b''
27 27
28 28 <legend tal:condition="title">${title}</legend>
29 29
30 <input type="hidden" name="${h.csrf_token_key}" value="${h.get_csrf_token()}" />
30 <input type="hidden" name="${h.csrf_token_key}" value="${h.get_csrf_token(request.session)}" />
31 31 <input type="hidden" name="_charset_" />
32 32 <input type="hidden" name="__formid__" value="${formid}"/>
33 33
General Comments 0
You need to be logged in to leave comments. Login now