示例#1
0
def create_account(request):
    try:
        restricted_usernames = ['p','login','register','settings','upload','logout','load_friends','find_friends','friends','like','upload_picture']
        username = request.POST['username']
        password = request.POST['password']
        fb_id = request.POST['fb_id']
        token = request.POST['token']
        email = request.POST['email']
        fb_name = request.POST['fb_name']
        if users.objects.filter(username=username) or username in restricted_usernames:
            response = {'response':{'message':'username not available'}}
            return HttpResponse(simplejson.dumps(response),status=200,mimetype='application/json')
        elif users.objects.filter(email=email):
            response = {'response':{'message':'email address is already being used'}}
            return HttpResponse(simplejson.dumps(response),status=200,mimetype='application/json')
        elif email.find('@') == -1 or email.find('.') == -1:
            response = {'response':{'message':'email address is invalid'}}
            return HttpResponse(simplejson.dumps(response),status=200,mimetype='application/json')
        elif len(username) > 20:
            response = {'response':{'message':'username is too long.'}}
            return HttpResponse(simplejson.dumps(response),status=200,mimetype='application/json')
        elif len(username) < 5:
            response = {'response':{'message':'username is too short.'}}
            return HttpResponse(simplejson.dumps(response),status=200,mimetype='application/json')
        else:
            hash_pw = hashlib.md5(password).hexdigest()
            ### added check for ghost account.  this prevents the BobStehler bug.  should probably return a message saying that the FB ID already exists
            ### we're going to want to error out if the FBID exists under anouther account.  Rather than create  anew account, we want to tell the user that an eaccount already exists.
            acct_check = users.objects.filter(fb_id=fb_id)
            if acct_check:
                if acct_check[0].is_ghost_account == 0:
                    response = {'response': {'message': 'facebook account already tied to another account'}}
                    return HttpResponse(simplejson.dumps(response),status=400,mimetype='application/json')    
                else:
                    users.objects.filter(fb_id=fb_id).update(is_ghost_account=0,fb_name=fb_name,username=username,password=hash_pw,email=email)
            #if len(users.objects.filter(fb_id=fb_id,is_ghost_account=1)) > 0:
                #users.objects.filter(fb_id=fb_id).update(is_ghost_account=0,fb_name=fb_name,username=username,password=hash_pw,email=email)
            else:
                new_user = users(username=username,password=hash_pw,email=email)
                new_user.save()
            new_entry = users.objects.filter(username=username)[0]
            new_settings = settings(user_id=new_entry,email_on_tag=1,email_on_like=0,email_on_my_pic_liked=0,email_on_friend_tagged=0,email_on_friend_liked=0,post_tags_to_twitter=0,post_tags_to_facebook=0,post_likes_to_twitter=0,post_likes_to_facebook=0,email_on_comment=0,email_on_pic_commented_on=0,email_on_friend_commented_on=0)
            new_settings.save()
            request.session['username'] = username
            res = load_fb_friends_new(fb_id,token,username)
            response = {'response':{'message':'yay',"username":username}}
            return HttpResponse(simplejson.dumps(response),status=201,mimetype='application/json')
    except Exception, e:
        response = {'response':{'message':str(e)}}
        return HttpResponse(simplejson.dumps(response),status=400,mimetype='application/json')
示例#2
0
def create_ghost_account(fb_id,fb_name):
    ghost = users(is_ghost_account=1,fb_id=fb_id,profile_pic='http://graph.facebook.com/' + fb_id + '/picture',username=fb_name,fb_name=fb_name)
    ghost.save()
    ghost_entry = users.objects.filter(username=fb_name)[0]
    ghost_settings = settings(user_id=ghost_entry,email_on_tag=0,email_on_like=0,email_on_my_pic_liked=0,email_on_friend_tagged=0,email_on_friend_liked=0,post_tags_to_twitter=0,post_tags_to_facebook=0,post_likes_to_twitter=0,post_likes_to_facebook=0,email_on_comment=0,email_on_pic_commented_on=0,email_on_friend_commented_on=0)
    ghost_settings.save()