From 19c452e837f01f1029f658a0a57884fc7e00144a Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Sat, 22 Aug 2009 12:31:06 +0200 Subject: [PATCH] introducing protected mode: if active, people will need the server password to register on private servers. fixes #16 --- pyweb/mumble/forms.py | 36 +++++++++++++++++++ pyweb/mumble/locale/de/LC_MESSAGES/django.mo | Bin 7602 -> 7911 bytes pyweb/mumble/locale/de/LC_MESSAGES/django.po | 7 ++++ pyweb/mumble/locale/la/LC_MESSAGES/django.mo | Bin 7706 -> 8032 bytes pyweb/mumble/locale/la/LC_MESSAGES/django.po | 8 ++++- pyweb/mumble/views.py | 21 ++++++++--- pyweb/settings.py | 4 +++ 7 files changed, 70 insertions(+), 6 deletions(-) diff --git a/pyweb/mumble/forms.py b/pyweb/mumble/forms.py index c19122e..5d901dc 100644 --- a/pyweb/mumble/forms.py +++ b/pyweb/mumble/forms.py @@ -45,11 +45,47 @@ class MumbleForm( ModelForm ): class MumbleUserForm( ModelForm ): """The user registration form used to register an account.""" + + def clean_name( self ): + name = self.cleaned_data['name']; + if not self.instance.id and len( self.server.ctl.getRegisteredPlayers( self.server.srvid, name ) ) > 0: + raise forms.ValidationError( _( "Another player already registered that name." ) ); + return name; + + def clean_password( self ): + pw = self.cleaned_data['password']; + if not pw: + raise forms.ValidationError( _( "Cannot register player without a password!" ) ); + return pw; + class Meta: model = MumbleUser; fields = ( 'name', 'password' ); +class MumbleUserPasswordForm( MumbleUserForm ): + """The user registration form used to register an account on a private server in protected mode.""" + + serverpw = forms.CharField( + label=_('Server Password'), + help_text=_('This server is private and protected mode is active. Please enter the server password.'), + widget=forms.PasswordInput(render_value=False) + ); + + def clean_serverpw( self ): + # Validate the password + serverpw = self.cleaned_data['serverpw']; + if self.server.passwd != serverpw: + raise forms.ValidationError( _( "The password you entered is incorrect." ) ); + return serverpw; + + def clean( self ): + # prevent save() from trying to store the password in the Model instance + # clean() will be called after clean_serverpw(), so it has already been validated here. + if 'serverpw' in self.cleaned_data: + del( self.cleaned_data['serverpw'] ); + return self.cleaned_data; + class MumbleTextureForm( Form ): """The form used to upload a new image to be set as texture.""" texturefile = forms.ImageField(); diff --git a/pyweb/mumble/locale/de/LC_MESSAGES/django.mo b/pyweb/mumble/locale/de/LC_MESSAGES/django.mo index 3ee68be4b20e894bf9740714a719f771c64e4ecc..b9a160437791bf49efb955bdc02a49c738d1e32d 100644 GIT binary patch delta 2012 zcmYk+TWl0n9LMoL1*>3fX~DMEQicMh*0Pm)!L}B#RH)ZBwHgv5bT5bPgtCjfvsH}E z#)rme;){hC6NvI)jEOPCnn(k0yws=<-Z1(gzKFy~NQ@8K7~=Q0dp7Z8|MQtSGjlHg zb7nso_-(NGbHl2WMj0hqi4#?3N3iB54wQ4%X2lg|i&%?&x0s!#eq^=TZFmLs=wEm{ zF5{iJb`8&CH+JIys{JXf!#TW_rtKsrT~wUGoAFEJXWwy92bXajUc&}l!CQK6J+8%8 zY{%``hGVD>vUnVeco6?V#%2d<%py!+E&baMoa~_DN~yxEnO-%3ZKw` z@HCPvTSQ*93*OJMpX*CV(yX2|)MGP_V;A<~ELPLMo#jLweTHgi2{nW7Q8WD&`PnrN zn!&%wWUQKpWCQB?Hh&#MEk(btA49c2iOS>)sP^Wts18qXqST(jo%kts;2*dP*YWnV zIF76EL)3d8d(R`2wIx&smrw)$9W}r|k*4g1x0ZCQ%u;cDUc*PMwQodyC7V&t$Ncpms=X0Zdk0YioA&ju z`1-eyffemNPPF;X;Shd-nrSWhOkpo3@NHCvmQfw9c5&2~ph70ChZrSzq?At0RB3#I@PC-4ovi`f zLug>yfd4NVw2CIJ{!3-RE0orqL_481-b5(neZ-SQjChDpxsTA7qrEaj>?X8KDw@5D zCbgZ=KGI&Rlr5YTm9lQ)USHeg?etb4>-I3Qty19)P+tIFYUvZ(hyBD3;t@ir*ZOZH z^l9%U*!(s^u*^d?$jM`bN^hCc`mhabKk=ZiyC1bo`h$6#c#2SIT9~WuTfM~v$Kv_? zi`iT%IG!y8E)%(&O9f#*2s6oSF6WX_Z2o-Ro{5Pm>hdl(<8r!tEEmqiBNxOoDbBMI z&+*#PY|80wJQ;;EE*6YUyLjG}TMeQqS82fax$t*gSkoTQ2QJK{UD_pF#sy>L@kF!} z1&8C)`Q+66q1MCk;n2~2@N{Jeksm`)UIr2qf` delta 1709 zcmYk+TS!zv9LMp0n^|64HO(yZZklGMUA(52-IXL1dI%A+8yF=RR1d9!P-5VN6d6V@ zl_Z3fDMVR46p@7COAt|12nm`Gy$Dv)_jmRL4f{Wznc1^5XZ|y1zn4BN_I-{FxMGxQ zVinQuF*}CS0bD4T0?m92%sMa}gO-@xpg%UqEDVQn5x&G|9L1IR1;g<-W@AXOfBXVm zO1ln27}}0dSxZMVF2-KuW4E|yf&q-e5sbuf)O{1^#c52&Ke!qb8C4UM;W^xo_4o#P z7Rv}VYr#AWXMXFWvVo3ar^9R#8Ovr-6L@%vLX5%$tVXTyB$6!aKyJ0mu02>p`wo&c z`-%}bi3e~F^RSxq1Tw$1Qqe>gQ3G8=t>89lr9;TaM!0ANZ;{2=d)IHM`)AztJZdX~ z=~RCr7mc5b%47v{i`Ah|6E;#&YMXHjw&PZOiaG|rQ1@vR8HOyv;!p!-pdPdY^zXYW!<+4+g%B&~Y zTH8r%C)N-;7b@D%N`kF*{y~-2WI|;(k>J$)C%uTevQ|zM651kdhcmy@s@HH6p*<$U zwvkXtB=m2kl1=O-l=gHYiO?45-?NxdVNadya2oDK=O^R84tBsP`TnEee^qqqwLdmE Z6j&J49qlb0yz4z0+MOTY*gY5j<1az&i_-uA diff --git a/pyweb/mumble/locale/de/LC_MESSAGES/django.po b/pyweb/mumble/locale/de/LC_MESSAGES/django.po index 851005f..849bbf4 100644 --- a/pyweb/mumble/locale/de/LC_MESSAGES/django.po +++ b/pyweb/mumble/locale/de/LC_MESSAGES/django.po @@ -363,3 +363,10 @@ msgstr "Registrierung" msgid "Administration" msgstr "Administration" + +msgid "This server is private and protected mode is active. Please enter the server password." +msgstr "Dieser Server ist privat und der Registrierungsschutz ist aktiv. Bitte gib das Serverpasswort ein." + +msgid "The password you entered is incorrect." +msgstr "Das eingegebene Passwort ist falsch" + diff --git a/pyweb/mumble/locale/la/LC_MESSAGES/django.mo b/pyweb/mumble/locale/la/LC_MESSAGES/django.mo index bfbf3cf3a666d6ec41e392593bea7c036451a775..5e6c5eedc608657cb9d7d05b6fedce4cfe7c9fb9 100644 GIT binary patch delta 2052 zcmYk+Uu+ar6vy!cmLgjFk3X$a$`p~7vaC|kvMp8=7K?vqfogbA(`p~c zyjY%mF$GD8fIRv_N=kyHnrJixBQGWjF(zV6Ai+o?$O9N-{QhR{syBP)Gk@=%>c2Lq;1QT8M*l&ECYCd2DE(RGUR}%+6vhX6`mS%K82UX7}M$)UCI0G5(25 zvHl+J#}uZp7uA0O>u?h9rE5FHPA4Z$;C#G*{Omh68sIW6#Ov6Ib9hSkEy8+i!4@4!Aed_!gdpN#`6wMkaLjyMBPVB@k+>h0aZ`15(pfjkB&ZB1VJ!+;`ke^*=qZ#~# zOvb9YNj9SHZ*|9M)Kc`g^Mk1VUqe;$EmVJ#7-_(R?5MOSup3X~D*O%ma3N2>ggdbc zKSn)w(m9Jv*3P2_xQI&pS5$&Gk*@4-XD#Kpi{sV?>fgrB3QnxXEvS->;woOYF+7DI zl3hP;U&NqXKg{&FWLuXc9q&dhNdX_gcagE|IBvjccl{dbxp_^=b4^Xu|1nOqb3&zk z1vRtRQ8$Lj&knF@#$%}a&fxv{1*%d%;xe4eO{##0@8f#R<2h7?*6`4Km_a3YE@Ec` zJC{%|T|Mb5fu*P=>A=m{iylVE&pu+KrIZO>^N2-}GLCv%Sl}HzAEwiWrcc9jE4{FANJ3fHS#XfN7r&0ZXg-YZH zRDU;+ej=-)ZY+x}#w?~Vg#qrs(j1RNtN=+AAlV9zH~92~_^AgkG?9gqBllulIza z#>=OdnUBHxi3gSQ6YM-osC6a8f2+J7_6(t~LrtIQ8bWKSH+(yx)-*F&omsHb_e!~P z`R!tm_a=&CouPQ|92xi1-r!z8SN4-$y|Ca{I&fpo+^)M&lN#c@%b}E;NYWq&QsIcs zk}OCkH<6zDvSnAatsEA(6z5V-?unBr1so_Lmri_4M*AxF_~b<=UY4Xvd*d#WQIy)h Z-TjwK+OokIBRIV5JKhoWvOXjX4+@5gfl5 zV`(>FBtzQ~Dy!&d!FhNc`Pf~)G(kVc<1ohI80xyu=*DSWhJP>_QyEngRAL+M!h<-9 zti>{;%v!MkW0>C_P|2rbD9~Xxg^XoCP!qUVMG3}Z3i?oY*o-90x{yn)+p!NzY2QbZ zW*>0@PGLR%!~*n@o-pRO4l0`H9BQCm)E(SI-RU6mv0=V+2k(%Zv2n*wsOx8(_FvRi zM9``JRK7HR9x9Vn$R*Z*eofd&MX7DUBJ9Ks_!4ytexa_@C^8zk2}?u`n2B0wIci}w z$X{%?;~|_w`#7dyD`w#pH~CkJUeS@k;d+BlafW==;w?sh!tY-e22^EoX*9x<1qtQ zV-oH`W#9x}!n4?jUjD2Mox*OsfLfrJL5eX8b;b_+sb~Sss4Zy6YP^W4IEK2z@2IVa zrlEo29Mf?J?Ly?qv<_qq)`dFtx3LtJF8yAHB-3h8XTZOoic)kGm6CSULOM}>T!{m?7T=>%9?MIDqZN2pXnw1rp*>OI{8%}m z2~>OptF)bJQ1n!2F7JFZzM_xZKbv+Fu(Rg zsn?^S6tNRlNT{R|1*%YTi0y>7M^8Z-p)JTK$_SNBg!X@S(E-n#)xk~#3frPJ2lsD1 f>Lp?WgJC7%JqhlLfrswVsGgfi^#cczLqq-nx%Y_F diff --git a/pyweb/mumble/locale/la/LC_MESSAGES/django.po b/pyweb/mumble/locale/la/LC_MESSAGES/django.po index 90f6620..836f1d2 100644 --- a/pyweb/mumble/locale/la/LC_MESSAGES/django.po +++ b/pyweb/mumble/locale/la/LC_MESSAGES/django.po @@ -1,4 +1,4 @@ -# German translation file for Mumble-Django. +# (Iggypay) Latin translation file for Mumble-Django. # # Copyright (C) 2009, Michael "Svedrin" Ziegler # @@ -359,3 +359,9 @@ msgstr "Egistrationray" msgid "Administration" msgstr "Inistrationadmay" + +msgid "This server is private and protected mode is active. Please enter the server password." +msgstr "Isthay erversay is ivatepray and otectedpray odemay is iveactay. Easeplay erentay the erversay asswordpay." + +msgid "The password you entered is incorrect." +msgstr "The asswordpay you eredentay is orrectincay." diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index 828db83..6fb8d21 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -21,6 +21,7 @@ from django.template import RequestContext from django.http import Http404, HttpResponse, HttpResponseRedirect from django.core.urlresolvers import reverse from django.contrib.auth.decorators import login_required +from django.conf import settings from models import Mumble, MumbleUser from forms import * @@ -61,12 +62,11 @@ def show( request, server ): if isAdmin: if request.method == 'POST' and "mode" in request.POST and request.POST['mode'] == 'admin': adminform = MumbleForm( request.POST, instance=srv ); - # In case we redisplay the page, it was displayed with errors on the admin form, so tell - # Ext to show the admin form tab first. - displayTab = 1; if adminform.is_valid(): adminform.save(); return HttpResponseRedirect( '/mumble/%d' % int(server) ); + else: + displayTab = 2; else: adminform = MumbleForm( instance=srv ); else: @@ -76,11 +76,18 @@ def show( request, server ): user = None; if request.user.is_authenticated(): + # Unregistered users may or may not need a password to register. + if settings.PROTECTED_MODE and srv.passwd: + unregged_user_form = MumbleUserPasswordForm; + else: + unregged_user_form = MumbleUserForm; + if request.method == 'POST' and 'mode' in request.POST and request.POST['mode'] == 'reg': try: user = MumbleUser.objects.get( server=srv, owner=request.user ); except MumbleUser.DoesNotExist: - regform = MumbleUserForm( request.POST ); + regform = unregged_user_form( request.POST ); + regform.server = srv; if regform.is_valid(): model = regform.save( commit=False ); model.isAdmin = False; @@ -88,16 +95,20 @@ def show( request, server ): model.owner = request.user; model.save(); return HttpResponseRedirect( '/mumble/%d' % int(server) ); + else: + displayTab = 1; else: regform = MumbleUserForm( request.POST, instance=user ); if regform.is_valid(): regform.save(); return HttpResponseRedirect( '/mumble/%d' % int(server) ); + else: + displayTab = 1; else: try: user = MumbleUser.objects.get( server=srv, owner=request.user ); except MumbleUser.DoesNotExist: - regform = MumbleUserForm(); + regform = unregged_user_form(); else: regform = MumbleUserForm( instance=user ); registered = True; diff --git a/pyweb/settings.py b/pyweb/settings.py index 7c4c190..7d6a0e1 100644 --- a/pyweb/settings.py +++ b/pyweb/settings.py @@ -71,6 +71,10 @@ ACCOUNT_ACTIVATION_DAYS = 30 # Default mumble port. If your server runs under this port, it will not be included in the links in the Channel Viewer. MUMBLE_DEFAULT_PORT = 64738 +# Protect the registration form for private servers? +# If set to True, people will need to enter the server password in order to create accounts. +PROTECTED_MODE = False + # Database settings for Mumble-Django's database. These do NOT need to point to Murmur's database, # Mumble-Django should use its own! DATABASE_ENGINE = 'sqlite3'