def register(request): if (request.method=='POST'): form = RegisterForm(data=request.POST) if(form.is_valid()): #check captcha first session = UserSession.objects.get(session_key=request.session.session_key) print("session captcha: "+session.captcha) print("form captcha: "+form.cleaned_data["captcha"]) if(session.captcha != form.cleaned_data["captcha"]): messages.add_message(request, messages.ERROR, _('The captcha was entered wrong.')) else: referer = request.META.get('HTTP_REFERER') user = form.save() user.groups.add(Group.objects.get(name='User')) user.is_active = False user.set_password(user.password) user.save() import uuid lv_uuid = str(uuid.uuid1())[0:30] message = """<html> <body> <h3>Registration at """+get_current_site(request).name+"""</h3><br/> <p> Please click the following link to end your registration. </p> <p> <a href='https://"""+get_current_site(request).domain+""""/user/activate/"""+lv_uuid+"""/'>Activation Link</a> </p> </html> """ send_mail('Registration at '+get_current_site(request).name, 'Hello '+user.username+ '\n\nPlease click the following the link to end your registration.\n\n'+ 'Activation Link: https://'+get_current_site(request).domain+'/user/activate/'+lv_uuid+'/', settings.SYSTEMMAIL, [user.email], fail_silently=False,html_message=message) profile = UserProfile() profile.user = user profile.posts = 0 profile.threads = 0 profile.activate = lv_uuid profile.theme = Theme.objects.get(default=True) profile.banned = False profile.save() messages.add_message(request, messages.INFO, _('User successful registrated.')) #return redirect(urlresolvers.reverse('board.views.index')) return redirect(referer) else: form = RegisterForm() f_profile = ProfileForm() return render_to_response('user/register.html',{'form':form},context_instance=RequestContext(request))
def test_rank(self): user = User.objects.create(username="******",is_active=True,password="******",email="*****@*****.**",is_staff=False) user.groups.add(Group.objects.get(name='User')) profile = UserProfile() profile.user = user profile.posts = 0 profile.threads = 0 profile.activate = "FALSE" profile.theme = Theme.objects.get(default=True) profile.banned = False profile.save() rank = profile.get_rank() self.failIf(profile.posts < rank.posts)
def test_show_valid(self): user = User.objects.create(username="******",is_active=True,password="******",email="*****@*****.**",is_staff=False) user.groups.add(Group.objects.get(name='User')) profile = UserProfile() profile.user = user profile.posts = 0 profile.threads = 0 profile.activate = "FALSE" profile.theme = Theme.objects.get(default=True) profile.banned = False profile.save() c = Client() response = c.get('/user/show/'+str(user.pk)+'/') self.assertEqual(response.status_code,200)
def login_view(request): if (request.method=='POST'): request.session.set_test_cookie() form = forms.AuthenticationForm(request,data=request.POST) if form.is_valid(): user = form.get_user() sessions = UserSession.objects.filter(session_key = request.session.session_key) if sessions is not None: sessions.delete() login(request, user) referer = request.META.get('HTTP_REFERER') ## create empty profile if missing try: profile = UserProfile.objects.get(user=request.user) except: if (user.is_staff): user.groups.add(Group.objects.get(name='Administrator')) profile = UserProfile() profile.user = request.user profile.posts = 0 profile.threads = 0 profile.activate = 'T' profile.banned = False profile.theme = Theme.objects.filter(default=True)[0] profile.save() user.save() messages.add_message(request, messages.INFO, _('Login successfull!')) #return redirect(urlresolvers.reverse('board.views.index')) return redirect(referer) return render_to_response('user/login_error.html',{'form':form},context_instance=RequestContext(request)) else: form = forms.AuthenticationForm(request) return render_to_response('user/login.html', {'form':form}, context_instance= RequestContext(request))