예제 #1
0
def verify_phone(request):
    '''
    because in this section, we will create two customer, in user and in customer.
    if there is an error when we do this function, we duplicate username, which is
    primary key, therefore, we need define this operation as atomic.
    * description : 用户注册
    * param       :
    * return      : FAILED/SUCCESS字段
    '''
    try:
      password = request.POST.get('password', '')
      verification_code = request.POST['verification_code']
      if verification_code == request.session['phone_verify']:
          phone_number = request.session['phone_number']
          date = datetime.now()
          u = User.objects.create_user(phone_number, "", password);
          u.save()
          newCustomer = Customer(user=u, phone=phone_number, nickname=phone_number, identity_tag='C',
                                     city=City.objects.get(id="1"), icon='icon/554773dd308df20150504212757.png')
          newCustomer.save()
          u = authenticate(username=phone_number, password=password)

          if u is not None:
              login(request, u)
              del request.session['phone_number']
              del request.session['phone_verify']
              return HttpResponse(json.dumps({'state': 'SUCCESS'}))
          else:
              return HttpResponse(json.dumps({'state': 'FAILED'}))
      else:
          del request.session['phone_number']
          del request.session['phone_verify']
          return HttpResponse(json.dumps({'state': 'FAILED'}))
    except Exception as e:
        print e
예제 #2
0
def registerView(requset):
    name = requset.POST["Name"].strip()
    pws = requset.POST["Password"]
    email = requset.POST["Email Address"]
    date = datetime.now()
    u = User.objects.create_user(email, email, pws)
    # u = User(username=email, password=pws, email=email, date_joined=date, last_login=date, is_staff=0, is_active=1)
    try:
        u.save()
        # 少了一个nickname字段
        newCustomer = Customer(
            user=u, phone='187373737', nickname=name, identity_tag='C',
            icon='554768afa7a7920150504204015.png'
        )
        newCustomer.save()

        u = authenticate(username=email, password=pws)

    except Exception, e:
        raise e
        # 返回一个ajiax错误信息
        return HttpResponse("erro")