コード例 #1
0
def register(request):
    if (request.method == "POST"):
        first_name = request.POST.get('first_name')
        last_name = request.POST.get('last_name')
        phone = request.POST.get('phone')
        street = request.POST.get('street')
        city = request.POST.get('city')
        postcode = request.POST.get('postcode')
        password = request.POST.get('password')
        email = request.POST.get('email')

        user = User(first_name=first_name,
                    last_name=last_name,
                    phone=phone,
                    street=street,
                    city=city,
                    postcode=postcode,
                    password=password,
                    email=email,
                    type="user")

        user.save()

        return render(request,
                      'website/account.html',
                      context={
                          'status': "",
                          'message': 'Account is created successfully'
                      })
    raise Http404
コード例 #2
0
def register(request):
    """
    user register api
    :param request:
    :return:
    """
    data = request.data
    mobile = data["mobile"]
    code = data["verify_code"]
    password = data["password"]
    #
    # sms_code = SmsCode.objects.filter(code=code).first()
    #
    # expired_date = sms_code.expired_date
    now = datetime.datetime.now()
    # # delta = datetime.timedelta(minutes=5)
    # if sms_code.verified > 0 or expired_date < now:

    res = SmsCode.objects.filter(code=code,
                                 mobile=mobile,
                                 expired_date__lt=now).update(verified=1)

    if res == 0:
        return Response(
            json.dumps(
                Result(status=common.SMS_CODE_EXPIRED,
                       error="code has been expired")))

    user = User()
    user.user_id = gen_user_id(mobile)
    user.mobile = mobile
    user.password = encode_passwd(mobile, user.user_id, password)
    # datetime.datetime.now().date()
    user.birthday = datetime.datetime.now().date()
    user.created_at = datetime.datetime.now()
    user.save()

    # User.objects
    return Response({})