示例#1
0
文件: views.py 项目: yfjelley/publish
def forgetpw(request):
    if request.method == 'POST':
        form = ForgetPW(request.POST)
        if form.is_valid():
            cd = form.clean()
            username = cd['username']
            user = User.objects.get(username=username)
            pw = user.userinformation.abcdefg
            context = u'密码为' + str(pw)
            try:
                send_mail(
                    subject=u'密码找回',
                    message=context,
                    from_email=EMAIL_HOST_USER,  # 发件邮箱
                    recipient_list=[user.userinformation.email],
                    fail_silently=False,
                    auth_user=EMAIL_HOST_USER,  # SMTP服务器的认证用户名
                    auth_password=EMAIL_HOST_PASSWORD,  # SMTP服务器的认证用户密码
                    connection=None
                )
                message = u'邮件已发送'
            except:
                message = u'邮件发送失败'

            return render_to_response('forget_password.html', {'message': message},
                                      context_instance=RequestContext(request))
        else:
            return render_to_response('forget_password.html', {'form': form}, context_instance=RequestContext(request))
    else:
        form = ForgetPW()
        return render_to_response('forget_password.html', {'form': form}, context_instance=RequestContext(request))
示例#2
0
文件: views.py 项目: yfjelley/web
def forgetpw(request):
    if request.method == 'POST':
        form = ForgetPW(request.POST)
        if form.is_valid():
            cd = form.clean()
            username = cd['username']
            _code = dict_code.get('smscode')
            smscode = cd['smscode']
            user = User.objects.get(username=username)
            pw = user.userinformation.abcdefg
            print type(pw), type(smscode), type(_code)

            if pw is not None and _code == int(smscode):

                user = auth.authenticate(username=username, password=pw)

                auth.login(request, user)
                message = u'success login!'
                return HttpResponseRedirect(reverse('searchindex'))
                #return render_to_response('success_login.html',{"message":message},
                #                     context_instance=RequestContext(request))

            else:
                message = u'手机号或者验证码错误'
                return render_to_response('success_login.html',{"message":message},
                                      context_instance=RequestContext(request))


        else:
            return render_to_response('forget_password.html', {'form': form}, context_instance=RequestContext(request))
    else:
        form = ForgetPW()
        return render_to_response('forget_password.html', {'form': form}, context_instance=RequestContext(request))
示例#3
0
def forgetpw(request):
    if request.method == 'POST':
        form = ForgetPW(request.POST)
        if form.is_valid():
            cd = form.clean()
            username = cd['username']
            user = User.objects.get(username=username)
            pw = user.userinformation.abcdefg
            context = u'密码为' + str(pw)
            try:
                send_mail(
                    subject=u'密码找回',
                    message=context,
                    from_email=EMAIL_HOST_USER,  # 发件邮箱
                    recipient_list=[user.userinformation.email],
                    fail_silently=False,
                    auth_user=EMAIL_HOST_USER,  # SMTP服务器的认证用户名
                    auth_password=EMAIL_HOST_PASSWORD,  # SMTP服务器的认证用户密码
                    connection=None)
                message = u'邮件已发送'
            except:
                message = u'邮件发送失败'

            return render_to_response('forget_password.html',
                                      {'message': message},
                                      context_instance=RequestContext(request))
        else:
            return render_to_response('forget_password.html', {'form': form},
                                      context_instance=RequestContext(request))
    else:
        form = ForgetPW()
        return render_to_response('forget_password.html', {'form': form},
                                  context_instance=RequestContext(request))
示例#4
0
文件: views.py 项目: yfjelley/web
def forgetpw(request):
    if request.method == 'POST':
        form = ForgetPW(request.POST)
        if form.is_valid():
            cd = form.clean()
            username = cd['username']
            _code = dict_code.get('smscode')
            smscode = cd['smscode']
            user = User.objects.get(username=username)
            pw = user.userinformation.abcdefg
            print type(pw), type(smscode), type(_code)

            if pw is not None and _code == int(smscode):

                user = auth.authenticate(username=username, password=pw)

                auth.login(request, user)
                message = u'success login!'
                return HttpResponseRedirect(reverse('searchindex'))
                #return render_to_response('success_login.html',{"message":message},
                #                     context_instance=RequestContext(request))

            else:
                message = u'手机号或者验证码错误'
                return render_to_response(
                    'success_login.html', {"message": message},
                    context_instance=RequestContext(request))

        else:
            return render_to_response('forget_password.html', {'form': form},
                                      context_instance=RequestContext(request))
    else:
        form = ForgetPW()
        return render_to_response('forget_password.html', {'form': form},
                                  context_instance=RequestContext(request))