diff --git a/boards/forms.py b/boards/forms.py --- a/boards/forms.py +++ b/boards/forms.py @@ -2,7 +2,7 @@ import re from captcha.fields import CaptchaField from django import forms from django.forms.util import ErrorList -from boards.models import TITLE_MAX_LENGTH +from boards.models import TITLE_MAX_LENGTH, User from neboard import settings from boards import utils @@ -131,3 +131,21 @@ class ThreadCaptchaForm(ThreadForm): class SettingsForm(forms.Form): theme = forms.ChoiceField(choices=settings.THEMES, widget=forms.RadioSelect) + + +class LoginForm(forms.Form): + user_id = forms.CharField() + + def clean_user_id(self): + user_id = self.cleaned_data['user_id'] + if user_id: + users = User.objects.filter(user_id=user_id) + if len(users) == 0: + raise forms.ValidationError('No such user found') + + return user_id + + def clean(self): + cleaned_data = super(LoginForm, self).clean() + + return cleaned_data \ No newline at end of file diff --git a/boards/locale/ru/LC_MESSAGES/django.mo b/boards/locale/ru/LC_MESSAGES/django.mo index 5a4428249dfa5b008dea0907cb684098535b55b6..915cea286c32770ce2337292b6874e6a3cbee1b4 GIT binary patch literal 3309 zc$|$@Yi|@)7(NQEuq}AO8(vSnpop{X7Gh*+(bX>4xV_kJHJJEe+Bs}TcW2g_S)j^? z76L+At%^pCctMOYCTiKXcH7coOiVOUb0)^<2Q|j{L4SbJ#AtlpbEXuMYMgZDIdjf? zdEV!JXZyoN%U@u)ZpD2S?!D(QwgvdzxlCQ3E@P|?_!;m#;Mc%f;P=2wfj-A&QH0c-*`M(=KP9^i2~@bT#V2p%NG%Qd?G zqtX6bcw7X07nlOhMRES9(R}}kaCxovtBY_=t+u-oI0dbFt>*nL4(oxxoTu~u2HZe( zfc$m96mT{0;T2k+LiGOp3SIB<6}lhq1Gkc1!1a_LB0dO=uhcpm1RB6m;2Pq+Qr8hi z`14Bb_d9Squpy@7+c7;KK}_d)Hm2?0iEuWi<9`|9H^76yA0z*Ko!<9=8-Y*MX}=HZ z^!dkix}RUv>G}AzPV2A?qC7&g3A`BiWWCORv|j5qUa#YPRIl~;s$R$Y33!ekVP#L( zwM_SpuFI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Team: LANGUAGE \n" @@ -62,10 +62,23 @@ msgstr "Все темы" msgid "Settings" msgstr "Настройки" +#: templates/boards/base.html:42 templates/boards/login.html:6 +#: templates/boards/login.html.py:21 +msgid "Login" +msgstr "Вход" + #: templates/boards/base.html:43 msgid "Up" msgstr "Вверх" +#: templates/boards/login.html:15 +msgid "User ID" +msgstr "ID пользователя" + +#: templates/boards/login.html:24 +msgid "Insert your user id above" +msgstr "Вставьте свой ID пользователя выше" + #: templates/boards/posting_general.html:18 msgid "Tag: " msgstr "Тег: " diff --git a/boards/models.py b/boards/models.py --- a/boards/models.py +++ b/boards/models.py @@ -285,8 +285,9 @@ class User(models.Model): registration_time = models.DateTimeField() last_access_time = models.DateTimeField() - fav_tags = models.ManyToManyField(Tag) - fav_threads = models.ManyToManyField(Post, related_name='+') + fav_tags = models.ManyToManyField(Tag, null=True, blank=True) + fav_threads = models.ManyToManyField(Post, related_name='+', null=True, + blank=True) def save_setting(self, name, value): setting, created = Setting.objects.get_or_create(name=name, user=self) @@ -322,6 +323,7 @@ class Setting(models.Model): value = models.CharField(max_length=50) user = models.ForeignKey(User) + class Ban(models.Model): ip = models.GenericIPAddressField() diff --git a/boards/static/css/md/base_page.css b/boards/static/css/md/base_page.css --- a/boards/static/css/md/base_page.css +++ b/boards/static/css/md/base_page.css @@ -128,7 +128,7 @@ p { .form-errors { padding-left: 1ex; font-weight: bold; - vertical-align: top; + vertical-align: middle; } .post-form input, .post-form textarea { diff --git a/boards/templates/boards/base.html b/boards/templates/boards/base.html --- a/boards/templates/boards/base.html +++ b/boards/templates/boards/base.html @@ -39,7 +39,7 @@ diff --git a/boards/templates/boards/login.html b/boards/templates/boards/login.html --- a/boards/templates/boards/login.html +++ b/boards/templates/boards/login.html @@ -1,22 +1,29 @@ - - - - - Login page - +{% extends "boards/base.html" %} + +{% load i18n %} + +{% block head %} + {% trans 'Login' %} +{% endblock %} + +{% block content %} - - {% if error != none%} - - {{ error }} - - {% endif %} +
+
+
+
+
{% trans 'User ID' %}
+
{{ form.user_id }}
+
{{ form.user_id.errors }}
+
+
+
+ +
+
+ {% trans 'Insert your user id above' %} +
+
+
-
{% csrf_token %} - - Login:
- Password:
- -
- - \ No newline at end of file +{% endblock %} \ No newline at end of file diff --git a/boards/templates/boards/posting_general.html b/boards/templates/boards/posting_general.html --- a/boards/templates/boards/posting_general.html +++ b/boards/templates/boards/posting_general.html @@ -171,6 +171,7 @@ {% endif %} ">{{ page }}] {% endfor %} + [RSS] {% endblock %} diff --git a/boards/templates/boards/thread.html b/boards/templates/boards/thread.html --- a/boards/templates/boards/thread.html +++ b/boards/templates/boards/thread.html @@ -113,6 +113,7 @@ {{ posts.0.get_reply_count }} {% trans 'replies' %}, {{ posts.0.get_images_count }} {% trans 'images' %}. {% trans 'Last update: ' %}{{ posts.0.last_edit_time }} + [RSS] {% endblock %} diff --git a/boards/urls.py b/boards/urls.py --- a/boards/urls.py +++ b/boards/urls.py @@ -14,9 +14,7 @@ urlpatterns = patterns('', url(r'^page/(?P\w+)/$', views.index, name='index'), # login page - url(r'^login$', views.login, name='login'), - # logout page - url(r'^logout$', views.logout, name='logout'), + url(r'^login/$', views.login, name='login'), # /boards/tag/tag_name/ url(r'^tag/(?P\w+)/$', views.tag, name='tag'), @@ -25,8 +23,8 @@ urlpatterns = patterns('', # /boards/thread/ url(r'^thread/(?P\w+)/$', views.thread, name='thread'), # /boards/theme/theme_name/ - url(r'^settings$', views.settings, name='settings'), - url(r'^tags$', views.all_tags, name='tags'), + url(r'^settings/$', views.settings, name='settings'), + url(r'^tags/$', views.all_tags, name='tags'), url(r'^captcha/', include('captcha.urls')), url(r'^jump/(?P\w+)/$', views.jump_to_post, name='jumper'), url(r'^authors/$', views.authors, name='authors'), diff --git a/boards/views.py b/boards/views.py --- a/boards/views.py +++ b/boards/views.py @@ -9,7 +9,7 @@ from boards import forms import boards from boards import utils from boards.forms import ThreadForm, PostForm, SettingsForm, PlainErrorList, \ - ThreadCaptchaForm, PostCaptchaForm + ThreadCaptchaForm, PostCaptchaForm, LoginForm from boards.models import Post, Tag, Ban, User, RANK_USER, RANK_MODERATOR, NO_PARENT from boards import authors @@ -150,31 +150,23 @@ def thread(request, post_id): def login(request): - """Log in as admin""" - - if 'name' in request.POST and 'password' in request.POST: - request.session['admin'] = False + """Log in with user id""" - isAdmin = len(Admin.objects.filter(name=request.POST['name'], - password=request.POST[ - 'password'])) > 0 - - if isAdmin: - request.session['admin'] = True + context = _init_default_context(request) - response = HttpResponseRedirect('/') - - else: - response = render(request, 'boards/login.html', {'error': 'Login error'}) - else: - response = render(request, 'boards/login.html', {}) + if request.method == 'POST': + form = LoginForm(request.POST, request.FILES, error_class=PlainErrorList) + if form.is_valid(): + user = User.objects.get(user_id=form.cleaned_data['user_id']) + request.session['user_id'] = user.id + return redirect(index) - return response - + else: + form = LoginForm() -def logout(request): - request.session['admin'] = False - return HttpResponseRedirect('/') + context['form'] = form + + return render(request, 'boards/login.html', context) def settings(request):