##// END OF EJS Templates
Added login and logout for moderators
neko259 -
r729:d56cc46f 2.0-dev
parent child Browse files
Show More
@@ -0,0 +1,33 b''
1 from django.shortcuts import render, redirect
2
3 from boards.abstracts.settingsmanager import SettingsManager, \
4 PERMISSION_MODERATE
5 from boards.forms import LoginForm, PlainErrorList
6 from boards.views.base import BaseBoardView, CONTEXT_FORM
7
8
9 __author__ = 'neko259'
10
11
12 class LoginView(BaseBoardView):
13
14 def get(self, request, form=None):
15 context = self.get_context_data(request=request)
16
17 if not form:
18 form = LoginForm()
19 context[CONTEXT_FORM] = form
20
21 return render(request, 'boards/login.html', context)
22
23 def post(self, request):
24 form = LoginForm(request.POST, request.FILES,
25 error_class=PlainErrorList)
26 form.session = request.session
27
28 if form.is_valid():
29 settings_manager = SettingsManager(request.session)
30 settings_manager.add_permission(PERMISSION_MODERATE)
31 return redirect('index')
32 else:
33 return self.get(request, form)
@@ -0,0 +1,24 b''
1 from django.shortcuts import render
2
3 from boards.abstracts.settingsmanager import SettingsManager, \
4 PERMISSION_MODERATE
5 from boards.forms import LoginForm
6 from boards.views.base import BaseBoardView, CONTEXT_FORM
7
8
9 __author__ = 'neko259'
10
11
12 class LogoutView(BaseBoardView):
13
14 def get(self, request, form=None):
15 settings_manager = SettingsManager(request.session)
16 settings_manager.del_permission(PERMISSION_MODERATE)
17
18 context = self.get_context_data(request=request)
19
20 if not form:
21 form = LoginForm()
22 context[CONTEXT_FORM] = form
23
24 return render(request, 'boards/login.html', context) No newline at end of file
@@ -52,7 +52,15 b' class SettingsManager:'
52 52 if not permissions:
53 53 permissions = [permission]
54 54 else:
55 permissions += permission
55 permissions.append(permission)
56 self.set_setting(SETTING_PERMISSIONS, permissions)
57
58 def del_permission(self, permission):
59 permissions = self.get_setting(SETTING_PERMISSIONS)
60 if not permissions:
61 permissions = []
62 else:
63 permissions.remove(permission)
56 64 self.set_setting(SETTING_PERMISSIONS, permissions)
57 65
58 66 def get_fav_tags(self):
@@ -278,12 +278,6 b' class SettingsForm(NeboardForm):'
278 278 label=_('Theme'))
279 279
280 280
281 class ModeratorSettingsForm(SettingsForm):
282
283 moderate = forms.BooleanField(required=False, label=_('Enable moderation '
284 'panel'))
285
286
287 281 class AddTagForm(NeboardForm):
288 282
289 283 tag = forms.CharField(max_length=TAG_MAX_LENGTH, label=LABEL_TAG)
@@ -305,4 +299,44 b' class AddTagForm(NeboardForm):'
305 299
306 300
307 301 class SearchForm(NeboardForm):
308 query = forms.CharField(max_length=500, label=LABEL_SEARCH, required=False) No newline at end of file
302 query = forms.CharField(max_length=500, label=LABEL_SEARCH, required=False)
303
304
305 class LoginForm(NeboardForm):
306
307 password = forms.CharField()
308
309 session = None
310
311 def clean_password(self):
312 password = self.cleaned_data['password']
313 if board_settings.MASTER_PASSWORD != password:
314 raise forms.ValidationError(_('Invalid master password'))
315
316 return password
317
318 def _validate_login_speed(self):
319 can_post = True
320
321 if LAST_LOGIN_TIME in self.session:
322 now = time.time()
323 last_login_time = self.session[LAST_LOGIN_TIME]
324
325 current_delay = int(now - last_login_time)
326
327 if current_delay < board_settings.LOGIN_TIMEOUT:
328 error_message = _('Wait %s minutes after last login') % str(
329 (board_settings.LOGIN_TIMEOUT - current_delay) / 60)
330 self._errors['password'] = self.error_class([error_message])
331
332 can_post = False
333
334 if can_post:
335 self.session[LAST_LOGIN_TIME] = time.time()
336
337 def clean(self):
338 self._validate_login_speed()
339
340 cleaned_data = super(LoginForm, self).clean()
341
342 return cleaned_data
1 NO CONTENT: modified file, binary diff hidden
@@ -7,7 +7,7 b' msgid ""'
7 7 msgstr ""
8 8 "Project-Id-Version: PACKAGE VERSION\n"
9 9 "Report-Msgid-Bugs-To: \n"
10 "POT-Creation-Date: 2014-06-29 13:46+0300\n"
10 "POT-Creation-Date: 2014-07-05 18:10+0300\n"
11 11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12 12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 13 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -18,19 +18,19 b' msgstr ""'
18 18 "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
19 19 "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
20 20
21 #: authors.py:5
21 #: authors.py:9
22 22 msgid "author"
23 23 msgstr "Π°Π²Ρ‚ΠΎΡ€"
24 24
25 #: authors.py:6
25 #: authors.py:10
26 26 msgid "developer"
27 27 msgstr "Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊ"
28 28
29 #: authors.py:7
29 #: authors.py:11
30 30 msgid "javascript developer"
31 31 msgstr "Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊ javascript"
32 32
33 #: authors.py:8
33 #: authors.py:12
34 34 msgid "designer"
35 35 msgstr "Π΄ΠΈΠ·Π°ΠΉΠ½Π΅Ρ€"
36 36
@@ -62,7 +62,7 b' msgstr "\xd0\xa2\xd0\xb5\xd0\xba\xd1\x81\xd1\x82"'
62 62 msgid "Tag"
63 63 msgstr "Π’Π΅Π³"
64 64
65 #: forms.py:32 templates/boards/base.html:50 templates/search/search.html:9
65 #: forms.py:32 templates/boards/base.html:54 templates/search/search.html:9
66 66 #: templates/search/search.html.py:13
67 67 msgid "Search"
68 68 msgstr "Поиск"
@@ -71,59 +71,55 b' msgstr "\xd0\x9f\xd0\xbe\xd0\xb8\xd1\x81\xd0\xba"'
71 71 msgid "Image"
72 72 msgstr "Π˜Π·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅"
73 73
74 #: forms.py:113
74 #: forms.py:114
75 75 msgid "e-mail"
76 76 msgstr ""
77 77
78 #: forms.py:124
78 #: forms.py:125
79 79 #, python-format
80 80 msgid "Title must have less than %s characters"
81 81 msgstr "Π—Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΠΊ Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠ΅Ρ‚ΡŒ мСньшС %s символов"
82 82
83 #: forms.py:133
83 #: forms.py:134
84 84 #, python-format
85 85 msgid "Text must have less than %s characters"
86 86 msgstr "ВСкст Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ ΠΊΠΎΡ€ΠΎΡ‡Π΅ %s символов"
87 87
88 #: forms.py:144
88 #: forms.py:145
89 89 #, python-format
90 90 msgid "Image must be less than %s bytes"
91 91 msgstr "Π˜Π·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ Π΄ΠΎΠ»ΠΆΠ½ΠΎ Π±Ρ‹Ρ‚ΡŒ ΠΌΠ΅Π½Π΅Π΅ %s Π±Π°ΠΉΡ‚"
92 92
93 #: forms.py:179
93 #: forms.py:180
94 94 msgid "Either text or image must be entered."
95 95 msgstr "ВСкст ΠΈΠ»ΠΈ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ Π²Π²Π΅Π΄Π΅Π½Ρ‹."
96 96
97 #: forms.py:202
97 #: forms.py:200
98 98 #, python-format
99 99 msgid "Wait %s seconds after last posting"
100 100 msgstr "ΠŸΠΎΠ΄ΠΎΠΆΠ΄ΠΈΡ‚Π΅ %s сСкунд послС послСднСго постинга"
101 101
102 #: forms.py:218 templates/boards/tags.html:7 templates/boards/rss/post.html:10
102 #: forms.py:216 templates/boards/tags.html:7 templates/boards/rss/post.html:10
103 103 msgid "Tags"
104 104 msgstr "Π’Π΅Π³ΠΈ"
105 105
106 #: forms.py:225 forms.py:344
106 #: forms.py:223 forms.py:291
107 107 msgid "Inappropriate characters in tags."
108 108 msgstr "НСдопустимыС символы Π² Ρ‚Π΅Π³Π°Ρ…."
109 109
110 #: forms.py:253 forms.py:274
110 #: forms.py:251 forms.py:272
111 111 msgid "Captcha validation failed"
112 112 msgstr "ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° ΠΊΠ°ΠΏΡ‡ΠΈ ΠΏΡ€ΠΎΠ²Π°Π»Π΅Π½Π°"
113 113
114 #: forms.py:280
114 #: forms.py:278
115 115 msgid "Theme"
116 116 msgstr "Π’Π΅ΠΌΠ°"
117 117
118 #: forms.py:285
119 msgid "Enable moderation panel"
120 msgstr "Π’ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒ панСль ΠΌΠΎΠ΄Π΅Ρ€Π°Ρ†ΠΈΠΈ"
118 #: forms.py:314
119 msgid "Invalid master password"
120 msgstr "НСвСрный мастСр-ΠΏΠ°Ρ€ΠΎΠ»ΡŒ"
121 121
122 #: forms.py:300
123 msgid "No such user found"
124 msgstr "Π”Π°Π½Π½Ρ‹ΠΉ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒ Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½"
125
126 #: forms.py:314
122 #: forms.py:328
127 123 #, python-format
128 124 msgid "Wait %s minutes after last login"
129 125 msgstr "ΠŸΠΎΠ΄ΠΎΠΆΠ΄ΠΈΡ‚Π΅ %s ΠΌΠΈΠ½ΡƒΡ‚ послС послСднСго Π²Ρ…ΠΎΠ΄Π°"
@@ -168,17 +164,21 b' msgstr "\xd0\xa3\xd0\xbf\xd1\x80\xd0\xb0\xd0\xb2\xd0\xbb\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5 \xd1\x82\xd0\xb5\xd0\xb3\xd0\xb0\xd0\xbc\xd0\xb8"'
168 164 msgid "Settings"
169 165 msgstr "Настройки"
170 166
171 #: templates/boards/base.html:49 templates/boards/login.html:6
167 #: templates/boards/base.html:50
168 msgid "Logout"
169 msgstr "Π’Ρ‹Ρ…ΠΎΠ΄"
170
171 #: templates/boards/base.html:52 templates/boards/login.html:6
172 172 #: templates/boards/login.html.py:16
173 173 msgid "Login"
174 174 msgstr "Π’Ρ…ΠΎΠ΄"
175 175
176 #: templates/boards/base.html:52
176 #: templates/boards/base.html:56
177 177 #, python-format
178 178 msgid "Speed: %(ppd)s posts per day"
179 179 msgstr "Π‘ΠΊΠΎΡ€ΠΎΡΡ‚ΡŒ: %(ppd)s сообщСний Π² дСнь"
180 180
181 #: templates/boards/base.html:54
181 #: templates/boards/base.html:58
182 182 msgid "Up"
183 183 msgstr "Π’Π²Π΅Ρ€Ρ…"
184 184
@@ -249,7 +249,7 b' msgstr "\xd0\x9f\xd1\x80\xd0\xb5\xd0\xb4\xd1\x8b\xd0\xb4\xd1\x83\xd1\x89\xd0\xb0\xd1\x8f \xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x86\xd0\xb0"'
249 249 msgid "Skipped %(count)s replies. Open thread to see all replies."
250 250 msgstr "ΠŸΡ€ΠΎΠΏΡƒΡ‰Π΅Π½ΠΎ %(count)s ΠΎΡ‚Π²Π΅Ρ‚ΠΎΠ². ΠžΡ‚ΠΊΡ€ΠΎΠΉΡ‚Π΅ Ρ‚Ρ€Π΅Π΄, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΡƒΠ²ΠΈΠ΄Π΅Ρ‚ΡŒ всС ΠΎΡ‚Π²Π΅Ρ‚Ρ‹."
251 251
252 #: templates/boards/posting_general.html:121 templates/search/search.html:35
252 #: templates/boards/posting_general.html:121 templates/search/search.html:33
253 253 msgid "Next page"
254 254 msgstr "Π‘Π»Π΅Π΄ΡƒΡŽΡ‰Π°Ρ страница"
255 255
@@ -278,35 +278,15 b' msgstr "\xd0\xa1\xd0\xb8\xd0\xbd\xd1\x82\xd0\xb0\xd0\xba\xd1\x81\xd0\xb8\xd1\x81 \xd1\x82\xd0\xb5\xd0\xba\xd1\x81\xd1\x82\xd0\xb0"'
278 278 msgid "Pages:"
279 279 msgstr "Π‘Ρ‚Ρ€Π°Π½ΠΈΡ†Ρ‹: "
280 280
281 #: templates/boards/settings.html:14
282 msgid "User:"
283 msgstr "ΠŸΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒ:"
284
285 #: templates/boards/settings.html:16
281 #: templates/boards/settings.html:15
286 282 msgid "You are moderator."
287 283 msgstr "Π’Ρ‹ ΠΌΠΎΠ΄Π΅Ρ€Π°Ρ‚ΠΎΡ€."
288 284
289 #: templates/boards/settings.html:19
290 msgid "You are veteran."
291 msgstr "Π’Ρ‹ Π²Π΅Ρ‚Π΅Ρ€Π°Π½."
292
293 #: templates/boards/settings.html:22
294 msgid "Posts:"
295 msgstr "Π‘ΠΎΠΎΠ±Ρ‰Π΅Π½ΠΈΠΉ:"
296
297 #: templates/boards/settings.html:23
298 msgid "First access:"
299 msgstr "ΠŸΠ΅Ρ€Π²Ρ‹ΠΉ доступ:"
300
301 #: templates/boards/settings.html:25
302 msgid "Last access:"
303 msgstr "ПослСдний доступ: "
304
305 #: templates/boards/settings.html:29
285 #: templates/boards/settings.html:20
306 286 msgid "Hidden tags:"
307 287 msgstr "Π‘ΠΊΡ€Ρ‹Ρ‚Ρ‹Π΅ Ρ‚Π΅Π³ΠΈ:"
308 288
309 #: templates/boards/settings.html:44
289 #: templates/boards/settings.html:35
310 290 msgid "Save"
311 291 msgstr "Π‘ΠΎΡ…Ρ€Π°Π½ΠΈΡ‚ΡŒ"
312 292
@@ -385,8 +365,4 b' msgstr "\xd0\x9f\xd0\xb5\xd1\x80\xd0\xb5\xd0\xb4 \xd1\x8d\xd1\x82\xd0\xb8\xd0\xbc\xd0\xb8 \xd1\x82\xd0\xb5\xd0\xb3\xd0\xb0\xd0\xbc\xd0\xb8 \xd0\xbd\xd1\x83\xd0\xb6\xd0\xbd\xd0\xb0 \xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x8f \xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0:"'
385 365
386 366 #: templates/boards/staticpages/help.html:18
387 367 msgid "Comment"
388 msgstr "ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ"
389
390 #: templates/search/search.html:30
391 msgid "No results found."
392 msgstr "Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Ρ‹ Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½Ρ‹."
368 msgstr "ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ" No newline at end of file
@@ -17,4 +17,7 b' LAST_REPLIES_COUNT = 3'
17 17 # Enable archiving threads instead of deletion when the thread limit is reached
18 18 ARCHIVE_THREADS = True
19 19 # Limit posting speed
20 LIMIT_POSTING_SPEED = False No newline at end of file
20 LIMIT_POSTING_SPEED = False
21
22 # This password is used to add admin permissions to the user
23 MASTER_PASSWORD = u'password' No newline at end of file
@@ -46,6 +46,11 b''
46 46
47 47 <div class="navigation_panel">
48 48 {% block metapanel %}{% endblock %}
49 {% if moderator %}
50 [<a href="{% url "logout" %}">{% trans 'Logout' %}</a>]
51 {% else %}
52 [<a href="{% url "login" %}">{% trans 'Login' %}</a>]
53 {% endif %}
49 54 [<a href="{% url "search" %}">{% trans 'Search' %}</a>]
50 55 {% with ppd=posts_per_day|floatformat:2 %}
51 56 {% blocktrans %}Speed: {{ ppd }} posts per day{% endblocktrans %}
@@ -2,7 +2,7 b' from django.conf.urls import patterns, u'
2 2 from boards import views
3 3 from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed
4 4 from boards.views import api, tag_threads, all_threads, \
5 settings, all_tags
5 login, settings, all_tags, logout
6 6 from boards.views.authors import AuthorsView
7 7 from boards.views.delete_post import DeletePostView
8 8 from boards.views.ban import BanUserView
@@ -22,6 +22,10 b" urlpatterns = patterns('',"
22 22 url(r'^page/(?P<page>\w+)/$', all_threads.AllThreadsView.as_view(),
23 23 name='index'),
24 24
25 # login page
26 url(r'^login/$', login.LoginView.as_view(), name='login'),
27 url(r'^logout/$', logout.LogoutView.as_view(), name='logout'),
28
25 29 # /boards/tag/tag_name/
26 30 url(r'^tag/(?P<tag_name>\w+)/$', tag_threads.TagView.as_view(),
27 31 name='tag'),
@@ -1,12 +1,9 b''
1 1 from django.db import transaction
2 2 from django.shortcuts import render, redirect
3 from boards import utils
4 from boards.abstracts.settingsmanager import SettingsManager, \
5 PERMISSION_MODERATE
3 from boards.abstracts.settingsmanager import SettingsManager
6 4
7 5 from boards.views.base import BaseBoardView, CONTEXT_FORM
8 from boards.forms import SettingsForm, ModeratorSettingsForm, PlainErrorList
9 from boards.models.post import SETTING_MODERATE
6 from boards.forms import SettingsForm, PlainErrorList
10 7
11 8
12 9 class SettingsView(BaseBoardView):
@@ -14,16 +11,9 b' class SettingsView(BaseBoardView):'
14 11 def get(self, request):
15 12 context = self.get_context_data(request=request)
16 13 settings_manager = SettingsManager(request.session)
17 is_moderator = settings_manager.has_permission(PERMISSION_MODERATE)
18 14
19 15 selected_theme = settings_manager.get_theme()
20 16
21 if is_moderator:
22 form = ModeratorSettingsForm(initial={
23 'theme': selected_theme,
24 'moderate': settings_manager.has_permission(PERMISSION_MODERATE)
25 }, error_class=PlainErrorList)
26 else:
27 17 form = SettingsForm(initial={'theme': selected_theme},
28 18 error_class=PlainErrorList)
29 19
@@ -33,13 +23,8 b' class SettingsView(BaseBoardView):'
33 23
34 24 def post(self, request):
35 25 settings_manager = SettingsManager(request.session)
36 is_moderator = settings_manager.has_permission(PERMISSION_MODERATE)
37 26
38 27 with transaction.atomic():
39 if is_moderator:
40 form = ModeratorSettingsForm(request.POST,
41 error_class=PlainErrorList)
42 else:
43 28 form = SettingsForm(request.POST, error_class=PlainErrorList)
44 29
45 30 if form.is_valid():
@@ -47,9 +32,4 b' class SettingsView(BaseBoardView):'
47 32
48 33 settings_manager.set_theme(selected_theme)
49 34
50 if is_moderator:
51 moderate = form.cleaned_data['moderate']
52 if moderate == 'True':
53 settings_manager.add_permission(PERMISSION_MODERATE)
54
55 35 return redirect('settings')
General Comments 0
You need to be logged in to leave comments. Login now