Beispiel #1
0
def forgot_passwd(request):
    if request.method == "POST":
        if not request.is_ajax():
            raise Http404
        result={}
        passwd = request.POST.get('passwd', '')
        telcode = request.POST.get("code", '')
        mobile = request.POST.get('mobile', '')
        if not (passwd and telcode and mobile):
            result['code'] = '3'
            result['res_msg'] = u'传入参数不足!'
            return JsonResponse(result)
        ret = verifymobilecode(mobile,telcode)
        if ret != 0:
            result['code'] = 1
            if ret == -1:
                result['res_msg'] = u'请先获取手机验证码'
            elif ret == 1:
                result['res_msg'] = u'手机验证码输入错误!'
            elif ret == 2:
                result['res_msg'] = u'手机验证码已过期,请重新获取'
        else:
            user = MyUser.objects.get(mobile=mobile)
            user.set_password(passwd)
            user.save(update_fields=["password"])
            result['code'] = 0
        return JsonResponse(result)
    else:
        hashkey = CaptchaStore.generate_key()
        codimg_url = captcha_image_url(hashkey)
        return render(request,'registration/forgot_passwd.html',
                  {'hashkey':hashkey, 'codimg_url':codimg_url})
Beispiel #2
0
def change_zhifubao(request):
    result = {}
    user = request.user
    zhifubao = request.POST.get("account", '')
    zhifubao_name = request.POST.get("name", '')
    telcode = request.POST.get("telcode", '')
    ret = verifymobilecode(user.mobile, telcode)
    if ret != 0:
        result['code'] = 2
        if ret == -1:
            result['msg'] = u'请先获取手机验证码!'
        elif ret == 1:
            result['msg'] = u'手机验证码输入错误!'
        elif ret == 2:
            result['msg'] = u'手机验证码已过期,请重新获取'
        return JsonResponse(result)
    else:
        user.zhifubao = zhifubao
        user.zhifubao_name = zhifubao_name
        user.save(update_fields=[
            "zhifubao",
            "zhifubao_name",
        ])
        result['code'] = 0
        result['msg'] = u"支付宝账号更改成功!"
    return JsonResponse(result)
Beispiel #3
0
def change_zhifubao(request):
    if request.method == 'POST':
        if not request.is_ajax():
            raise Http404
        result = {}
        user = request.user
        zhifubao = request.POST.get("account", '')
        zhifubao_name = request.POST.get("name", '')
        telcode = request.POST.get("telcode", '')
        ret = verifymobilecode(user.mobile, telcode)
        if ret != 0:
            result['code'] = 2
            if ret == -1:
                result['msg'] = u'请先获取手机验证码!'
            elif ret == 1:
                result['msg'] = u'手机验证码输入错误!'
            elif ret == 2:
                result['msg'] = u'手机验证码已过期,请重新获取'
            return JsonResponse(result)
        else:
            user.zhifubao = zhifubao
            user.zhifubao_name = zhifubao_name
            user.save(update_fields=[
                "zhifubao",
                "zhifubao_name",
            ])
            result['code'] = 0
            result['msg'] = u"支付宝账号更改成功!"
        return JsonResponse(result)
    else:
        return render(request, 'account/m_account_change_zhifubao.html')
Beispiel #4
0
def forgot_passwd(request):
    if request.method == "POST":
        if not request.is_ajax():
            raise Http404
        result = {}
        passwd = request.POST.get('passwd', '')
        telcode = request.POST.get("code", '')
        mobile = request.POST.get('mobile', '')
        if not (passwd and telcode and mobile):
            result['code'] = '3'
            result['res_msg'] = u'传入参数不足!'
            return JsonResponse(result)
        ret = verifymobilecode(mobile, telcode)
        if ret != 0:
            result['code'] = 1
            if ret == -1:
                result['res_msg'] = u'请先获取手机验证码'
            elif ret == 1:
                result['res_msg'] = u'手机验证码输入错误!'
            elif ret == 2:
                result['res_msg'] = u'手机验证码已过期,请重新获取'
        else:
            user = MyUser.objects.get(mobile=mobile)
            user.set_password(passwd)
            user.save(update_fields=["password"])
            result['code'] = 0
        return JsonResponse(result)
    else:
        hashkey = CaptchaStore.generate_key()
        codimg_url = captcha_image_url(hashkey)
        return render(request, 'registration/forgot_passwd.html', {
            'hashkey': hashkey,
            'codimg_url': codimg_url
        })
Beispiel #5
0
def bind_bankcard(request):
    result = {'code': -1, 'url': ''}
    if not request.is_ajax():
        raise Http404
    user = request.user
    if not user.is_authenticated():
        result['code'] = 1
        result['url'] = reverse('login') + "?next=" + reverse('bind_bankcard')
        return JsonResponse(result)
    if request.method == 'POST':
        card_number = request.POST.get("card_number", '')
        real_name = request.POST.get("real_name", '')
        bank = request.POST.get("bank", '')
        subbranch = request.POST.get("subbranch", '')
        telcode = request.POST.get("code", '')
        ret = verifymobilecode(user.mobile, telcode)
        if ret != 0:
            result['code'] = '2'
            if ret == -1:
                result['res_msg'] = u'请先获取手机验证码'
            elif ret == 1:
                result['res_msg'] = u'手机验证码输入错误!'
            elif ret == 2:
                result['res_msg'] = u'手机验证码已过期,请重新获取'
            return JsonResponse(result)
        card = user.user_bankcard.first()
        card.card_number = card_number
        card.real_name = real_name
        card.bank = bank
        card.subbranch = subbranch
        card.save()
        result['code'] = 0
    elif request.method == 'GET':
        if user.user_bankcard.exists():
            raise Http404
        card_number = request.GET.get("card_number", '')
        real_name = request.GET.get("real_name", '')
        bank = request.GET.get("bank", '')
        subbranch = request.GET.get("subbranch", '')
        print 'bank' + bank
        if card_number and real_name and bank:
            user.user_bankcard.create(user=user,
                                      card_number=card_number,
                                      real_name=real_name,
                                      bank=bank,
                                      subbranch=subbranch)
        result['code'] = 0
    return JsonResponse(result)
Beispiel #6
0
def validate_telcode(request):
    result={}
    mobile = request.GET.get("mobile", '')
    telcode = request.GET.get("code", '')
    ret = verifymobilecode(mobile,telcode)
    if ret != 0:
        result['code'] = 1
        if ret == -1:
            result['res_msg'] = u'请先获取手机验证码'
        elif ret == 1:
            result['res_msg'] = u'手机验证码输入错误!'
        elif ret == 2:
            result['res_msg'] = u'手机验证码已过期,请重新获取'
    else:
        result['code'] = 0
    return JsonResponse(result)
Beispiel #7
0
def validate_telcode(request):
    result = {}
    mobile = request.GET.get("mobile", '')
    telcode = request.GET.get("code", '')
    ret = verifymobilecode(mobile, telcode)
    if ret != 0:
        result['code'] = 1
        if ret == -1:
            result['res_msg'] = u'请先获取手机验证码'
        elif ret == 1:
            result['res_msg'] = u'手机验证码输入错误!'
        elif ret == 2:
            result['res_msg'] = u'手机验证码已过期,请重新获取'
    else:
        result['code'] = 0
    return JsonResponse(result)
Beispiel #8
0
def bind_bankcard(request):
    result={'code':-1, 'url':''}
    if not request.is_ajax():
        raise Http404
    user = request.user
    if not user.is_authenticated():
        result['code'] = 1
        result['url'] = reverse('login') + "?next=" + reverse('bind_bankcard')
        return JsonResponse(result)
    if request.method == 'POST':
        card_number = request.POST.get("card_number", '')
        real_name = request.POST.get("real_name", '')
        bank = request.POST.get("bank", '')
        subbranch = request.POST.get("subbranch",'')
        telcode = request.POST.get("code", '')
        ret = verifymobilecode(user.mobile,telcode)
        if ret != 0:
            result['code'] = '2'
            if ret == -1:
                result['res_msg'] = u'请先获取手机验证码'
            elif ret == 1:
                result['res_msg'] = u'手机验证码输入错误!'
            elif ret == 2:
                result['res_msg'] = u'手机验证码已过期,请重新获取'
            return JsonResponse(result)
        card = user.user_bankcard.first()
        card.card_number = card_number
        card.real_name = real_name
        card.bank = bank
        card.subbranch = subbranch
        card.save()
        result['code'] = 0
    elif request.method == 'GET':
        if user.user_bankcard.exists():
            raise Http404
        card_number = request.GET.get("card_number", '')
        real_name = request.GET.get("real_name", '')
        bank = request.GET.get("bank", '')
        subbranch = request.GET.get("subbranch",'')
        print 'bank' + bank
        if card_number and real_name and bank:
            user.user_bankcard.create(user=user, card_number=card_number, real_name=real_name,
                                       bank=bank, subbranch=subbranch)
        result['code'] = 0
    return JsonResponse(result)
Beispiel #9
0
def bind_zhifubao(request):
    result = {'code': -1, 'url': ''}
    if not request.is_ajax():
        raise Http404
    user = request.user
    if not user.is_authenticated():
        result['code'] = 1
        result['url'] = reverse('login') + "?next=" + reverse('bind_zhifubao')
        return JsonResponse(result)
    if request.method == 'POST':
        zhifubao = request.POST.get("account", '')
        zhifubao_name = request.POST.get("name", '')
        telcode = request.POST.get("code", '')
        ret = verifymobilecode(user.mobile, telcode)
        if ret != 0:
            result['code'] = '2'
            if ret == -1:
                result['res_msg'] = u'请先获取手机验证码'
            elif ret == 1:
                result['res_msg'] = u'手机验证码输入错误!'
            elif ret == 2:
                result['res_msg'] = u'手机验证码已过期,请重新获取'
            return JsonResponse(result)
        user.zhifubao = zhifubao
        user.zhifubao_name = zhifubao_name
        user.save(update_fields=[
            "zhifubao",
            "zhifubao_name",
        ])
        result['code'] = 0
    elif request.method == 'GET':
        if user.zhifubao:
            raise Http404
        zhifubao = request.GET.get("account", '')
        zhifubao_name = request.GET.get("name", '')
        user.zhifubao = zhifubao
        user.zhifubao_name = zhifubao_name
        user.save(update_fields=[
            "zhifubao",
            "zhifubao_name",
        ])
        result['code'] = 0
    return JsonResponse(result)
Beispiel #10
0
def password_reset(request):
    if request.method == 'POST':
        if not request.is_ajax():
            raise Http404
        result = {}
        telcode = request.POST.get('code', None)
        mobile = request.POST.get('mobile', None)
        password = request.POST.get('password', None)
        if not (telcode and mobile and password):
            result['code'] = '3'
            result['msg'] = u'传入参数不足!'
            return JsonResponse(result)
        user = None
        try:
            user = MyUser.objects.get(mobile=mobile)
        except:
            result['code'] = '1'
            result['msg'] = u'该手机号码尚未注册!'
            return JsonResponse(result)
        ret = verifymobilecode(mobile, telcode)
        if ret != 0:
            result['code'] = '2'
            if ret == -1:
                result['msg'] = u'请先获取手机验证码'
            elif ret == 1:
                result['msg'] = u'手机验证码输入错误!'
            elif ret == 2:
                result['msg'] = u'手机验证码已过期,请重新获取'
        else:
            user.set_password(password)
            user.save(update_fields=["password"])
            result['code'] = 0
            result['msg'] = u'密码重置成功!'
        return JsonResponse(result)
    else:
        hashkey = CaptchaStore.generate_key()
        codimg_url = captcha_image_url(hashkey)
        context = {
            'hashkey': hashkey,
            'codimg_url': codimg_url,
        }
        return render(request, 'm_password_reset.html', context)
Beispiel #11
0
def bind_user(request):
    if request.method == 'POST':
        result = {}
        openid = request.session['openid']
        if not openid:
            result['code'] = '3'
            result['msg'] = u'请在微信中提交'
            return JsonResponse(result)
        mobile = request.POST.get('mobile')
        telcode = request.POST.get('telcode')
        ret = verifymobilecode(mobile, telcode)
        if ret != 0:
            result['code'] = '2'
            if ret == -1:
                result['msg'] = u'请先获取手机验证码'
            elif ret == 1:
                result['msg'] = u'手机验证码输入错误!'
            elif ret == 2:
                result['msg'] = u'手机验证码已过期,请重新获取'
        else:
            result['code'] = 0
            try:
                user = MyUser.objects.get(mobile=mobile)
            except MyUser.DoesNotExist:
                request.session['mobile'] = mobile
                result['url'] = "/weixin/bind-user/setpasswd/"
            else:
                user.open_id = openid
                user.save(update_fields=['open_id'])
                user.backend = 'django.contrib.auth.backends.ModelBackend'  #为了略过用户名和密码验证
                auth_login(request, user)
                result['url'] = "/weixin/bind-user/success/"
        return JsonResponse(result)
    else:
        code = request.GET.get('code', '')
        if not code:
            return HttpResponse(u"微信授权失败,请稍后再试")
        url = ' https://api.weixin.qq.com/sns/oauth2/access_token'
        logger.info(code)
        params = {
            'grant_type': 'authorization_code',
            'appid': settings.APPID,
            'secret': settings.SECRET,
            'code': code,
        }
        json_ret = httpconn(url, params, 0)
        if 'openid' in json_ret:
            openid = json_ret['openid']
            request.session['openid'] = openid
            try:
                user = MyUser.objects.get(open_id=openid)
            except MyUser.DoesNotExist:
                return render(request, 'm_bind.html')
            else:
                user.backend = 'django.contrib.auth.backends.ModelBackend'  #为了略过用户名和密码验证
                auth_login(request, user)
                return redirect('account_index')
        else:
            logger.error('(zhuanfa?)Getting access_token error:' +
                         str(json_ret))
            return HttpResponse(u"本页面转发或刷新无效,请在微信公众号中重新打开")
Beispiel #12
0
def register(request):
    if request.method == 'POST':
        if not request.is_ajax():
            raise Http404
        result = {}
        telcode = request.POST.get('code', None)
        mobile = request.POST.get('mobile', None)
        password = request.POST.get('password', None)
        invite_code = request.POST.get('invite', None)
        if not (telcode and mobile and password):
            result['code'] = '3'
            result['msg'] = u'传入参数不足!'
            return JsonResponse(result)
        if MyUser.objects.filter(mobile=mobile).exists():
            result['code'] = '1'
            result['msg'] = u'该手机号码已被注册,请直接登录!'
            return JsonResponse(result)
        ret = verifymobilecode(mobile,telcode)
        if ret != 0:
            result['code'] = '2'
            if ret == -1:
                result['msg'] = u'请先获取手机验证码'
            elif ret == 1:
                result['msg'] = u'手机验证码输入错误!'
            elif ret == 2:
                result['msg'] = u'手机验证码已过期,请重新获取'
            return JsonResponse(result)
        inviter = None
        if invite_code:
            try:
                inviter = MyUser.objects.get(invite_code=invite_code)
            except MyUser.DoesNotExist:
                result['code'] = '2'
                result['msg'] = u'该邀请码不存在,请检查'
                return JsonResponse(result)
        try:
            username = '******' + str(mobile)
            user = MyUser(mobile=mobile, username=username, inviter=inviter)
            user.set_password(password)
            user.save()
            logger.info('Creating User:'******' succeed!')
            # 注册奖励2元
            reg_award = 200
            trans = charge_money(user, '0', reg_award, u"注册奖励")
            if trans:
                logger.debug('Registering Award money is successfully payed!')
            else:
                logger.debug('Registering Award money is failed to pay!!!')
        except Exception,e:
            logger.error(e)
            result['code'] = '4'
            result['msg'] = u'创建用户失败!'
        else:
            result['code'] = '0'
            # 邀请人奖励10积分
            if inviter:
                invite_award_scores = 10
                inviter.invite_scores += invite_award_scores
                translist = charge_score(inviter, '0', invite_award_scores, u"邀请奖励")
                if translist:
                    logger.debug('Inviting Award scores is successfully payed!')
                    inviter.save(update_fields=['invite_scores'])
                else:
                    logger.debug('Inviting Award scores is failed to pay!!!')
            try:
                userl = authenticate(username=username, password=password)
                auth_login(request, userl)
                user.this_login_time = datetime.now()
                Userlogin.objects.create(user=userl,)
            except:
                pass
        return JsonResponse(result)
Beispiel #13
0
def register(request):
    if request.method == 'POST':
        if not request.is_ajax():
            raise Http404
        result = {}
        telcode = request.POST.get('code', None)
        mobile = request.POST.get('mobile', None)
        password = request.POST.get('password', None)
        invite_code = request.POST.get('invite', None)
        if not (telcode and mobile and password):
            result['code'] = '3'
            result['msg'] = u'传入参数不足!'
            return JsonResponse(result)
        if MyUser.objects.filter(mobile=mobile).exists():
            result['code'] = '1'
            result['msg'] = u'该手机号码已被注册,请直接登录!'
            return JsonResponse(result)
        ret = verifymobilecode(mobile, telcode)
        if ret != 0:
            result['code'] = '2'
            if ret == -1:
                result['msg'] = u'请先获取手机验证码'
            elif ret == 1:
                result['msg'] = u'手机验证码输入错误!'
            elif ret == 2:
                result['msg'] = u'手机验证码已过期,请重新获取'
            return JsonResponse(result)
        inviter = None
        if invite_code:
            try:
                inviter = MyUser.objects.get(invite_code=invite_code)
            except MyUser.DoesNotExist:
                result['code'] = '2'
                result['msg'] = u'该邀请码不存在,请检查'
                return JsonResponse(result)
        try:
            username = '******' + str(mobile)
            user = MyUser(mobile=mobile, username=username, inviter=inviter)
            user.set_password(password)
            user.save()
            logger.info('Creating User:'******' succeed!')
            # 注册奖励2元
            reg_award = 200
            trans = charge_money(user, '0', reg_award, u"注册奖励")
            if trans:
                logger.debug('Registering Award money is successfully payed!')
            else:
                logger.debug('Registering Award money is failed to pay!!!')
        except Exception, e:
            logger.error(e)
            result['code'] = '4'
            result['msg'] = u'创建用户失败!'
        else:
            result['code'] = '0'
            # 邀请人奖励10积分
            if inviter:
                invite_award_scores = 10
                inviter.invite_scores += invite_award_scores
                translist = charge_score(inviter, '0', invite_award_scores,
                                         u"邀请奖励")
                if translist:
                    logger.debug(
                        'Inviting Award scores is successfully payed!')
                    inviter.save(update_fields=['invite_scores'])
                else:
                    logger.debug('Inviting Award scores is failed to pay!!!')
            try:
                userl = authenticate(username=username, password=password)
                auth_login(request, userl)
                user.this_login_time = datetime.now()
                Userlogin.objects.create(user=userl, )
            except:
                pass
        return JsonResponse(result)
Beispiel #14
0
def register(request):
    if request.method == 'GET':
        hashkey = CaptchaStore.generate_key()
        codimg_url = captcha_image_url(hashkey)
        icode = request.GET.get('icode', '')
        return render(request, 'registration/register.html', {
            'hashkey': hashkey,
            'codimg_url': codimg_url,
            'icode': icode
        })
    if request.method == 'POST':
        if not request.is_ajax():
            raise Http404
        result = {}
        username = request.POST.get('username', None)
        telcode = request.POST.get('code', None)
        mobile = request.POST.get('mobile', None)
        email = request.POST.get('email', None)
        password = request.POST.get('password', None)
        invite_code = request.POST.get('invite', None)
        if not (telcode and mobile and email and password and username):
            result['code'] = '3'
            result['res_msg'] = u'传入参数不足!'
            return JsonResponse(result)
        ret = verifymobilecode(mobile, telcode)
        if ret != 0:
            result['code'] = '2'
            if ret == -1:
                result['res_msg'] = u'请先获取手机验证码'
            elif ret == 1:
                result['res_msg'] = u'手机验证码输入错误!'
            elif ret == 2:
                result['res_msg'] = u'手机验证码已过期,请重新获取'
            return JsonResponse(result)
        inviter = None
        if invite_code:
            try:
                inviter = MyUser.objects.get(invite_code=invite_code)
            except MyUser.DoesNotExist:
                result['code'] = '2'
                result['res_msg'] = u'该邀请码不存在,请检查'
                return JsonResponse(result)
        try:
            user = MyUser(email=email,
                          mobile=mobile,
                          username=username,
                          inviter=inviter)
            user.set_password(password)
            user.save()
            logger.info('Creating User:'******' succeed!')
            # 注册奖励2元
            reg_award = 2
            trans = charge_money(user, '0', reg_award, u"注册奖励")
            if trans:
                logger.debug('Registering Award money is successfully payed!')
            else:
                logger.debug('Registering Award money is failed to pay!!!')
        except Exception, e:
            print e
            logger.error('Creating User is failed!!!')
            result['code'] = '4'
            result['res_msg'] = u'创建用户失败!'
        else:
            result['code'] = '0'
            # 邀请人奖励20积分
            if inviter:
                invite_award_scores = 20
                inviter.invite_scores += invite_award_scores
                translist = charge_score(inviter, '0', invite_award_scores,
                                         u"邀请奖励")
                if translist:
                    logger.debug(
                        'Inviting Award scores is successfully payed!')
                    inviter.save(update_fields=['invite_scores'])
                else:
                    logger.debug('Inviting Award scores is failed to pay!!!')
            result['code'] = '0'
            try:
                userl = authenticate(username=username, password=password)
                auth_login(request, userl)
                user.this_login_time = datetime.now()
                Userlogin.objects.create(user=userl, )
            except:
                pass
        return JsonResponse(result)