##// END OF EJS Templates
Added login functionality.
neko259 -
r144:7af95110 1.1
parent child Browse files
Show More
@@ -2,7 +2,7 b' import re'
2 from captcha.fields import CaptchaField
2 from captcha.fields import CaptchaField
3 from django import forms
3 from django import forms
4 from django.forms.util import ErrorList
4 from django.forms.util import ErrorList
5 from boards.models import TITLE_MAX_LENGTH
5 from boards.models import TITLE_MAX_LENGTH, User
6 from neboard import settings
6 from neboard import settings
7 from boards import utils
7 from boards import utils
8
8
@@ -131,3 +131,21 b' class ThreadCaptchaForm(ThreadForm):'
131
131
132 class SettingsForm(forms.Form):
132 class SettingsForm(forms.Form):
133 theme = forms.ChoiceField(choices=settings.THEMES, widget=forms.RadioSelect)
133 theme = forms.ChoiceField(choices=settings.THEMES, widget=forms.RadioSelect)
134
135
136 class LoginForm(forms.Form):
137 user_id = forms.CharField()
138
139 def clean_user_id(self):
140 user_id = self.cleaned_data['user_id']
141 if user_id:
142 users = User.objects.filter(user_id=user_id)
143 if len(users) == 0:
144 raise forms.ValidationError('No such user found')
145
146 return user_id
147
148 def clean(self):
149 cleaned_data = super(LoginForm, self).clean()
150
151 return cleaned_data No newline at end of file
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -7,7 +7,7 b' msgid ""'
7 msgstr ""
7 msgstr ""
8 "Project-Id-Version: PACKAGE VERSION\n"
8 "Project-Id-Version: PACKAGE VERSION\n"
9 "Report-Msgid-Bugs-To: \n"
9 "Report-Msgid-Bugs-To: \n"
10 "POT-Creation-Date: 2013-09-06 21:15+0300\n"
10 "POT-Creation-Date: 2013-09-06 21:49+0300\n"
11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 "Language-Team: LANGUAGE <LL@li.org>\n"
13 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -62,10 +62,23 b' msgstr "\xd0\x92\xd1\x81\xd0\xb5 \xd1\x82\xd0\xb5\xd0\xbc\xd1\x8b"'
62 msgid "Settings"
62 msgid "Settings"
63 msgstr "Настройки"
63 msgstr "Настройки"
64
64
65 #: templates/boards/base.html:42 templates/boards/login.html:6
66 #: templates/boards/login.html.py:21
67 msgid "Login"
68 msgstr "Π’Ρ…ΠΎΠ΄"
69
65 #: templates/boards/base.html:43
70 #: templates/boards/base.html:43
66 msgid "Up"
71 msgid "Up"
67 msgstr "Π’Π²Π΅Ρ€Ρ…"
72 msgstr "Π’Π²Π΅Ρ€Ρ…"
68
73
74 #: templates/boards/login.html:15
75 msgid "User ID"
76 msgstr "ID ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ"
77
78 #: templates/boards/login.html:24
79 msgid "Insert your user id above"
80 msgstr "Π’ΡΡ‚Π°Π²ΡŒΡ‚Π΅ свой ID ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ Π²Ρ‹ΡˆΠ΅"
81
69 #: templates/boards/posting_general.html:18
82 #: templates/boards/posting_general.html:18
70 msgid "Tag: "
83 msgid "Tag: "
71 msgstr "Π’Π΅Π³: "
84 msgstr "Π’Π΅Π³: "
@@ -285,8 +285,9 b' class User(models.Model):'
285 registration_time = models.DateTimeField()
285 registration_time = models.DateTimeField()
286 last_access_time = models.DateTimeField()
286 last_access_time = models.DateTimeField()
287
287
288 fav_tags = models.ManyToManyField(Tag)
288 fav_tags = models.ManyToManyField(Tag, null=True, blank=True)
289 fav_threads = models.ManyToManyField(Post, related_name='+')
289 fav_threads = models.ManyToManyField(Post, related_name='+', null=True,
290 blank=True)
290
291
291 def save_setting(self, name, value):
292 def save_setting(self, name, value):
292 setting, created = Setting.objects.get_or_create(name=name, user=self)
293 setting, created = Setting.objects.get_or_create(name=name, user=self)
@@ -322,6 +323,7 b' class Setting(models.Model):'
322 value = models.CharField(max_length=50)
323 value = models.CharField(max_length=50)
323 user = models.ForeignKey(User)
324 user = models.ForeignKey(User)
324
325
326
325 class Ban(models.Model):
327 class Ban(models.Model):
326 ip = models.GenericIPAddressField()
328 ip = models.GenericIPAddressField()
327
329
@@ -128,7 +128,7 b' p {'
128 .form-errors {
128 .form-errors {
129 padding-left: 1ex;
129 padding-left: 1ex;
130 font-weight: bold;
130 font-weight: bold;
131 vertical-align: top;
131 vertical-align: middle;
132 }
132 }
133
133
134 .post-form input, .post-form textarea {
134 .post-form input, .post-form textarea {
@@ -39,7 +39,7 b''
39
39
40 <div class="navigation_panel">
40 <div class="navigation_panel">
41 {% block metapanel %}{% endblock %}
41 {% block metapanel %}{% endblock %}
42 [<a href="rss/">RSS</a>]
42 [<a href="{% url "login" %}">{% trans 'Login' %}</a>]
43 <a class="link" href="#top">{% trans 'Up' %}</a>
43 <a class="link" href="#top">{% trans 'Up' %}</a>
44 </div>
44 </div>
45
45
@@ -1,22 +1,29 b''
1 <!DOCTYPE html>
1 {% extends "boards/base.html" %}
2 <html>
2
3 <head>
3 {% load i18n %}
4 <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/md/login.css" media="all"/>
4
5 <title>Login page</title>
5 {% block head %}
6 </head>
6 <title>{% trans 'Login' %}</title>
7 {% endblock %}
8
9 {% block content %}
7
10
8 <body>
11 <form enctype="multipart/form-data" method="post">
9 {% if error != none%}
12 <div class="post-form-w">
10 <span id="error_message">
13 <div class="post-form">
11 {{ error }}
14 <div class="form-row">
12 </span>
15 <div class="form-label">{% trans 'User ID' %}</div>
13 {% endif %}
16 <div class="form-input">{{ form.user_id }}</div>
17 <div class="form-errors">{{ form.user_id.errors }}</div>
18 </div>
19 </div>
20 <div class="form-submit">
21 <input type="submit" value="{% trans "Login" %}"/>
22 </div>
23 <div>
24 {% trans 'Insert your user id above' %}
25 </div>
26 </div>
27 </form>
14
28
15 <form action="login" method="POST">{% csrf_token %}
29 {% endblock %} No newline at end of file
16
17 Login: <input type="text" name="name"><br />
18 Password: <input type="password" name="password"><br />
19 <input type="submit">
20 </form>
21 </body>
22 </html> No newline at end of file
@@ -171,6 +171,7 b''
171 {% endif %}
171 {% endif %}
172 ">{{ page }}</a>]
172 ">{{ page }}</a>]
173 {% endfor %}
173 {% endfor %}
174 [<a href="rss/">RSS</a>]
174 </span>
175 </span>
175
176
176 {% endblock %}
177 {% endblock %}
@@ -113,6 +113,7 b''
113 {{ posts.0.get_reply_count }} {% trans 'replies' %},
113 {{ posts.0.get_reply_count }} {% trans 'replies' %},
114 {{ posts.0.get_images_count }} {% trans 'images' %}.
114 {{ posts.0.get_images_count }} {% trans 'images' %}.
115 {% trans 'Last update: ' %}{{ posts.0.last_edit_time }}
115 {% trans 'Last update: ' %}{{ posts.0.last_edit_time }}
116 [<a href="rss/">RSS</a>]
116 </span>
117 </span>
117
118
118 {% endblock %}
119 {% endblock %}
@@ -14,9 +14,7 b" urlpatterns = patterns('',"
14 url(r'^page/(?P<page>\w+)/$', views.index, name='index'),
14 url(r'^page/(?P<page>\w+)/$', views.index, name='index'),
15
15
16 # login page
16 # login page
17 url(r'^login$', views.login, name='login'),
17 url(r'^login/$', views.login, name='login'),
18 # logout page
19 url(r'^logout$', views.logout, name='logout'),
20
18
21 # /boards/tag/tag_name/
19 # /boards/tag/tag_name/
22 url(r'^tag/(?P<tag_name>\w+)/$', views.tag, name='tag'),
20 url(r'^tag/(?P<tag_name>\w+)/$', views.tag, name='tag'),
@@ -25,8 +23,8 b" urlpatterns = patterns('',"
25 # /boards/thread/
23 # /boards/thread/
26 url(r'^thread/(?P<post_id>\w+)/$', views.thread, name='thread'),
24 url(r'^thread/(?P<post_id>\w+)/$', views.thread, name='thread'),
27 # /boards/theme/theme_name/
25 # /boards/theme/theme_name/
28 url(r'^settings$', views.settings, name='settings'),
26 url(r'^settings/$', views.settings, name='settings'),
29 url(r'^tags$', views.all_tags, name='tags'),
27 url(r'^tags/$', views.all_tags, name='tags'),
30 url(r'^captcha/', include('captcha.urls')),
28 url(r'^captcha/', include('captcha.urls')),
31 url(r'^jump/(?P<post_id>\w+)/$', views.jump_to_post, name='jumper'),
29 url(r'^jump/(?P<post_id>\w+)/$', views.jump_to_post, name='jumper'),
32 url(r'^authors/$', views.authors, name='authors'),
30 url(r'^authors/$', views.authors, name='authors'),
@@ -9,7 +9,7 b' from boards import forms'
9 import boards
9 import boards
10 from boards import utils
10 from boards import utils
11 from boards.forms import ThreadForm, PostForm, SettingsForm, PlainErrorList, \
11 from boards.forms import ThreadForm, PostForm, SettingsForm, PlainErrorList, \
12 ThreadCaptchaForm, PostCaptchaForm
12 ThreadCaptchaForm, PostCaptchaForm, LoginForm
13
13
14 from boards.models import Post, Tag, Ban, User, RANK_USER, RANK_MODERATOR, NO_PARENT
14 from boards.models import Post, Tag, Ban, User, RANK_USER, RANK_MODERATOR, NO_PARENT
15 from boards import authors
15 from boards import authors
@@ -150,31 +150,23 b' def thread(request, post_id):'
150
150
151
151
152 def login(request):
152 def login(request):
153 """Log in as admin"""
153 """Log in with user id"""
154
155 if 'name' in request.POST and 'password' in request.POST:
156 request.session['admin'] = False
157
154
158 isAdmin = len(Admin.objects.filter(name=request.POST['name'],
155 context = _init_default_context(request)
159 password=request.POST[
160 'password'])) > 0
161
162 if isAdmin:
163 request.session['admin'] = True
164
156
165 response = HttpResponseRedirect('/')
157 if request.method == 'POST':
166
158 form = LoginForm(request.POST, request.FILES, error_class=PlainErrorList)
167 else:
159 if form.is_valid():
168 response = render(request, 'boards/login.html', {'error': 'Login error'})
160 user = User.objects.get(user_id=form.cleaned_data['user_id'])
169 else:
161 request.session['user_id'] = user.id
170 response = render(request, 'boards/login.html', {})
162 return redirect(index)
171
163
172 return response
164 else:
173
165 form = LoginForm()
174
166
175 def logout(request):
167 context['form'] = form
176 request.session['admin'] = False
168
177 return HttpResponseRedirect('/')
169 return render(request, 'boards/login.html', context)
178
170
179
171
180 def settings(request):
172 def settings(request):
General Comments 0
You need to be logged in to leave comments. Login now