Beispiel #1
0
def changepwd(request):
    if request.session:
        error = {}
        user = User.objects.get(id=request.session['userid'])
        friendlist = user.friend.all()
        if request.method == 'POST':
            if encrypt.encodeMD5(request.POST['oldpassword']) != user.userpwd:
                error['wrong'] = u'原始密码错误!'
            if len(request.POST['newpassword']) < 6:
                error['short'] = u'新密码少于6位'
            if request.POST['newpassword'] != request.POST['checkpassword']:
                error['nomatch'] = u'密码不一致!'
            if not error:
                user.userpwd = encrypt.encodeMD5(request.POST['newpassword'])
                user.save()
                error['no'] = u'修改成功!'
        return render_to_response(
            'microblog/changepwd.html', {
                'session': request.session,
                'friendlist': friendlist,
                'error': error,
                'userinfo': user
            })
    else:
        return HttpResponseRedirect('/')
Beispiel #2
0
 def clean_password(self):
     username=self.cleaned_data.get('username','')
     password=encrypt.encodeMD5(self.cleaned_data['password'])
     if User.objects.filter(username=username):
         if password != User.objects.get(username=username).userpwd:
             raise forms.ValidationError(u'密码错误!')
     return ""
Beispiel #3
0
 def clean_password(self):
     username = self.cleaned_data.get('username', '')
     password = encrypt.encodeMD5(self.cleaned_data['password'])
     if User.objects.filter(username=username):
         if password != User.objects.get(username=username).userpwd:
             raise forms.ValidationError(u'密码错误!')
     return ""
Beispiel #4
0
def changepwd(request):
    if request.session:
        error={}
        user=User.objects.get(id=request.session['userid'])
        friendlist=user.friend.all()
        if request.method=='POST':
            if encrypt.encodeMD5(request.POST['oldpassword']) != user.userpwd:
                error['wrong']=u'原始密码错误!'
            if len(request.POST['newpassword']) <6:
                error['short']=u'新密码少于6位'
            if request.POST['newpassword'] != request.POST['checkpassword']:
                error['nomatch']=u'密码不一致!'
            if not error:
                user.userpwd=encrypt.encodeMD5(request.POST['newpassword'])
                user.save()
                error['no']=u'修改成功!'
        return render_to_response('microblog/changepwd.html',{
            'session':request.session,
            'friendlist':friendlist,
            'error':error,'userinfo':user})
    else:
        return HttpResponseRedirect('/')
Beispiel #5
0
def sendpwd(request):
    if request.method=='POST':
        form=ResetForm(request.POST)
        if form.is_valid():
            email=form.clean_email()
            userinfo=User.objects.get(email=email)
            newpwd=''.join(random.sample(string.ascii_letters+string.digits,8))
            userinfo.userpwd=encrypt.encodeMD5(newpwd)
            userinfo.save()
            mail.send_mail_password(userinfo,newpwd)
            return HttpResponseRedirect('/reset/success/')
    else:
        form=ResetForm()
    variables=RequestContext(request,{'form':form})
    return render_to_response('login/reset.html',variables)
Beispiel #6
0
def sendpwd(request):
    if request.method == 'POST':
        form = ResetForm(request.POST)
        if form.is_valid():
            email = form.clean_email()
            userinfo = User.objects.get(email=email)
            newpwd = ''.join(
                random.sample(string.ascii_letters + string.digits, 8))
            userinfo.userpwd = encrypt.encodeMD5(newpwd)
            userinfo.save()
            mail.send_mail_password(userinfo, newpwd)
            return HttpResponseRedirect('/reset/success/')
    else:
        form = ResetForm()
    variables = RequestContext(request, {'form': form})
    return render_to_response('login/reset.html', variables)
Beispiel #7
0
def signup(request):
    if request.method == 'POST':
        form = RegistForm(request.POST)
        if form.is_valid():
            user = User(username=form.clean_username(),
                        email=form.clean_email(),
                        realname=form.cleaned_data['realname'],
                        userpwd=encrypt.encodeMD5(form.clean_checkpassword()),
                        photo="",
                        url="",
                        aboutme="",
                        regtime=datetime.now())
            user.save()
            #mailer.sendRegistSuccessMail(user)
            return HttpResponseRedirect('/register/success/')
    else:
        form = RegistForm()
    variables = RequestContext(request, {'form': form})
    return render_to_response('login/signup.html', variables)
Beispiel #8
0
def signup(request):
    if request.method=='POST':
        form= RegistForm(request.POST)
        if form.is_valid():
            user=User(
                username=form.clean_username(),
                email=form.clean_email(),
                realname=form.cleaned_data['realname'],
                userpwd=encrypt.encodeMD5(form.clean_checkpassword()),
                photo="",
                url="",
                aboutme="",
                regtime=datetime.now()
            )
            user.save()
            #mailer.sendRegistSuccessMail(user)
            return HttpResponseRedirect('/register/success/')
    else:
        form=RegistForm()
    variables=RequestContext(request,{'form':form})
    return render_to_response('login/signup.html',variables)