当前位置: 首页>>代码示例>>Python>>正文


Python Player.user方法代码示例

本文整理汇总了Python中models.Player.user方法的典型用法代码示例。如果您正苦于以下问题:Python Player.user方法的具体用法?Python Player.user怎么用?Python Player.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Player的用法示例。


在下文中一共展示了Player.user方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: twitter_callback

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import user [as 别名]
def twitter_callback(request):
    """ This method deals with the callback needed by twitter, and creating the their user.

    """
    if 'denied' in request.GET:
        return HttpResponseRedirect('/')

    twitter_conn = twitter(
        twitter_token = keys.CONSUMER_KEY,
        twitter_secret = keys.CONSUMER_SECRET,
        oauth_token = request.session['request_token']['oauth_token'],
        oauth_token_secret = request.session['request_token']['oauth_token_secret']
    )

    auth_tokens = twitter_conn.get_authorized_tokens()

    try:
        user = User.objects.get(username = auth_tokens['screen_name'])
    except User.DoesNotExist:
        user = create_django_user(auth_tokens['screen_name'], auth_tokens['oauth_token_secret'])
        player = Player()
        player.user = user
        player.twitter_oauth_token = auth_tokens['oauth_token']
        player.twitter_oauth_secret = auth_tokens['oauth_token_secret']
        request.session['twitter'] = player
        form = PlayerForm(initial={'username': player.user.username})
        return render(request, 'register.html', {'form': form})
    player = Player.objects.get(user=user)
    user = authenticate(username=player.user.username, password=player.twitter_oauth_secret)
    login(request, user)
    return HttpResponseRedirect('/')
开发者ID:fyelles,项目名称:courtside,代码行数:33,代码来源:views.py

示例2: gameEdit

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import user [as 别名]
def gameEdit(gameId = None):
    form = EditGameForm()
    if form.validate_on_submit():
        game = Game.query.get(gameId)
        if form.userToAdd.data != "":
            player = Player()
            player.user = User.query.filter_by(nickname = form.userToAdd.data).first()
            game.players.append(player)
        if form.title.data != "":
            game.title = form.title.data
        db.session.commit()
        return redirect(url_for("gameDetail", gameId = gameId))
    return render_template("gameEdit.html", title = "Edit game #" + gameId,
            form = form)
开发者ID:fuyemi,项目名称:assassins-game,代码行数:16,代码来源:views.py

示例3: new_register

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import user [as 别名]
def new_register(request):
    """ This is for a new user who wishes to register independent of twitter and facebook;
        we use gravatar for these users.
    """
    if request.method == 'POST':
        form = NewPlayerForm(request.POST)
        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            phone_number = form.cleaned_data['phone_number']
            sports = form.cleaned_data['sports']
            gender = form.cleaned_data['gender']
            password1 = form.cleaned_data['password1']
            #password2 = form.cleaned_data['password2'] # unused

            user = User.objects.create_user(username=username, email=email, password=password1)
            user.first_name = first_name
            user.last_name = last_name
            user.save()
            player = Player()
            player.gender = gender
            player.user = user
            player.phone_number = phone_number
            player.image_url = get_gravatar(player.user.email)
            player.save()
            player.sports = sports
            user = authenticate(username=player.user, password=password1)
            login(request, user)
            EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

            from django.core.mail import EmailMessage
            from django.template.loader import render_to_string
            from django.utils.html import strip_tags
            subject, from_email, to = 'Welcome', '[email protected]', user.email
            html_content = render_to_string('email_signup.html', {'user': user.first_name})
            text_content = strip_tags(html_content)
            msg = EmailMessage(subject, text_content, to=[to])
            msg.send()
            # task here to email user
            SignUpTask.delay(user)
            return HttpResponseRedirect('/')
    else:
        if 'email' in request.GET:
            form = NewPlayerForm(initial={'email': request.GET['email']})
        else:
            form = NewPlayerForm()
    return render(request, 'new_register.html', {'form': form})
开发者ID:nsnitesh7,项目名称:courtside,代码行数:51,代码来源:views.py

示例4: new_register

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import user [as 别名]
def new_register(request):
    """ This is for a new user who wishes to register independent of twitter and facebook;
        we use gravatar for these users.
    """
    if request.method == 'POST':
        form = NewPlayerForm(request.POST)
        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            phone_number = form.cleaned_data['phone_number']
            sports = form.cleaned_data['sports']
            gender = form.cleaned_data['gender']
            password1 = form.cleaned_data['password1']
            #password2 = form.cleaned_data['password2'] # unused

            user = User.objects.create_user(username=username, email=email, password=password1)
            user.first_name = first_name
            user.last_name = last_name
            user.save()
            player = Player()
            player.gender = gender
            player.user = user
            player.phone_number = phone_number
            player.image_url = get_gravatar(player.user.email)
            player.save()
            player.sports = sports
            user = authenticate(username=player.user, password=password1)
            login(request, user)
            # task here to email user
            SignUpTask.delay(user)
            return HttpResponseRedirect('/')
    else:
        if 'email' in request.GET:
            form = NewPlayerForm(initial={'email': request.GET['email']})
        else:
            form = NewPlayerForm()
    return render(request, 'new_register.html', {'form': form})
开发者ID:DjangoBD,项目名称:courtside,代码行数:41,代码来源:views.py

示例5: facebook_callback

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import user [as 别名]
def facebook_callback(request):
    """ This method is responsible for the facebook callback and generating the facebook user.
    """

    if 'error' in request.GET:
        return HttpResponseRedirect('/')

    code = request.GET["code"]

    args = dict(
        client_id = keys.FACEBOOK_APP_ID,
        redirect_uri = 'http://tini.ep.io/facebook/callback',
        client_secret = keys.FACEBOOK_APP_SECRET,
        code = code
    )


    token_url = 'https://graph.facebook.com/oauth/access_token?' + urllib.urlencode(args)
    data = urllib.urlopen(token_url)
    response = data.read()
    data.close()

    # print 'Token URL:' + token_url
    # print 'Response:'
    # print response

    try:
        split = response.split('=')
        access_token = split[1].strip('&expires')
        expires = split[2]

        # print 'Access Token: ' + access_token
        # print 'Expires: ' + expires
    except:
        error = json.loads(response)
        return HttpResponseRedirect('/error')

    profile = json.load(urllib.urlopen('https://graph.facebook.com/me?' + urllib.urlencode(dict(access_token=access_token))))


    args = dict(
        access_token = access_token
    )

    graph_url = 'https://graph.facebook.com/me?' + urllib.urlencode(args)
    #print graph_url

    response = urllib.urlopen(graph_url)
    facebook_user = json.load(response)

    username = facebook_user.get('username', '')
    gender = facebook_user.get('gender', '')


    try:
        player = Player.objects.get(facebook_id=facebook_user.get('id', None))
    except ObjectDoesNotExist:
        user = User(username=username)
        user.set_password(access_token)
        user.first_name = facebook_user['first_name']
        user.last_name = facebook_user['last_name']
        user.email = facebook_user['email']

        player = Player()
        player.user = user
        player.gender = get_gender_initial(gender=gender)
        player.facebook_id = facebook_user['id']
        player.facebook_oauth_token = access_token
        request.session['facebook'] = player
        form = PlayerForm(initial={'username': player.user.username, 'first_name': user.first_name, 'last_name': user.last_name, 'email': player.user.email, 'gender': player.gender})
        return render(request, 'register.html', {'form': form})

    # player = Player.objects.get(user=user)
    # print player
    user = authenticate(username=player.user.username, password=player.facebook_oauth_token)
    login(request, user)
    return HttpResponseRedirect('/')
开发者ID:fyelles,项目名称:courtside,代码行数:79,代码来源:views.py


注:本文中的models.Player.user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。