コード例 #1
0
ファイル: handler.py プロジェクト: TimelyToga/genie_API
def create_user(request):
    guid = request.json['guid']
    if(request.json.has_key('username')):
        username = request.json['username']
    else:
        username = ""

    ## TODO: Do some guid checking

    user = User.user_from_id(guid)
    if user:
        ## TODO: login user
        ## We know this is new user
        return JsonResponse({'reason': "user already exists", "guid": guid})

    with transaction.atomic():
        ## Create new user
        user = User(guid=guid)
        user.db_key = generate(User, 18, 'numeric')
        if username:
            user.username = username
        user.save()

        ## Create new Session
        session = Session()
        session.key = base64.urlsafe_b64encode(os.urandom(16))
        session.user = user
        session.created = gdate.datetime.utcnow()
        session.save()

    setattr(request, 'session', session)
    return JsonResponse(dict({'sid': session.pk}.items() + user.get_as_data(True).items()))
コード例 #2
0
ファイル: handler.py プロジェクト: TimelyToga/genie_API
def create(request):
    content = request.json['content']
    user = Session.user_from_sid(request.json['sid'])

    if not user:
        return JsonResponseBadRequest({'success': False})

    with transaction.atomic():
        post = Post(content=content)
        post.created_by = user
        post.id = generate(Post, 18, 'numeric')
        post.save()

    return JsonResponse({'post_id': post.id, 'poster': post.user_set})