示例#1
0
    def clean(self):
        """
        确保找到了用户,并且验证码一致
        """       

        cleaned_data = super(PwdMobileForm, self).clean()
        mobile = cleaned_data.get('mobile')
        vcode = cleaned_data.get('vcode')
        if mobile and vcode:
            user = verify_sms_helper.get_user_from_mobile(mobile)

            if user:
                server_vcode = VerifySms.objects.get_vcode(user=user)

                # 还没有生成验证码
                if not server_vcode:                                   
                    self._errors['mobile'] = self.error_class([u'尊敬的用户,请先生成验证码'])
                    del cleaned_data['mobile']          

                else:               

                    # 有验证码,比对
                    if vcode != server_vcode:
                        self._errors['vcode'] = self.error_class(['您输入的验证码不匹配,请重新录入'])
                        del cleaned_data['vcode']           
            else:
                self._errors['mobile'] = self.error_class(['这个手机号码没有关联任何用户,请检查您的手机号码是否录入正确。'])
                del cleaned_data['mobile']         
            

        return cleaned_data
示例#2
0
def pwd_back_mobile(request, template_name="kinger/pwd_back/pwd_back_mobile_a.html"):
    """
    通过手机找回密码处理页面,单击下一步
    """
    print 2222
    if request.method == 'POST':
        print 333
        form = PwdMobileForm(request.POST) 
        if form.is_valid():
            mobile = form.cleaned_data['mobile']
            print mobile,'mobile'
            user = verify_sms_helper.get_user_from_mobile(mobile)
            VerifySms.objects.set_vcode_invalid(user)
            print 1111111111
            request.session['pwd_back'] = {
                'type':'mobile',
                'step':{                            
                    'turn':1,
                    'finish':True
                },
                'con':{
                    'user':user,
                    'mobile':mobile
                }
            }
            
            messages.success(request,'身份验证成功,请重置密码')
            return redirect('kinger_pwd_back_pwd_reset')
           
    else:
        form = PwdMobileForm()

    ctx = {
        'form':form,
        'mobile':True
    }
    return render(request, template_name, ctx)