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


Python Profile.user方法代码示例

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


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

示例1: create_profile

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import user [as 别名]
def create_profile(user, oauth_token, secret_token):
    profile = Profile()
    profile.user = user
    profile.oauth_token = oauth_token
    profile.oauth_secret = secret_token
    profile.save()
    return
开发者ID:IAbuElRuzz,项目名称:ReTweeted,代码行数:9,代码来源:dbapi.py

示例2: signup_user

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import user [as 别名]
def signup_user(request):
    """
    view untuk fungsionalitas pendaftaran user
    """
    template = "accounts/signup.html"
    if request.POST:
        form = RegistrationForm(request.POST)
        if form.is_valid():
            nohp = form.cleaned_data["nohp"]
            sec_question = form.cleaned_data['sec_question']
            sec_answer = form.cleaned_data['sec_answer']
            user = form.save()
            profile = Profile()
            profile.user = user
            profile.nohp = nohp
            profile.sec_question = sec_question
            profile.sec_answer = sec_answer
            profile.save()
            request.session['signup_success'] = True
            return HttpResponseRedirect(reverse('signup_success'))
    else:
        form = RegistrationForm()
    return render_to_response(template,
        {"form": form},
        context_instance=RequestContext(request))
开发者ID:sakti,项目名称:ittelkomnewsmap,代码行数:27,代码来源:views.py

示例3: authorized

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import user [as 别名]
def authorized(request):
    """Callback for the oauth2 authorize call

                Args:
                    request: django request object
                Returns: Redirect to home page on success
                """
    context = RequestContext(request)

    if (request.method == 'GET'):
        #retrieve code from url
        code = request.GET.get('code', '')

        #build the url needed for the second step of the oauth2 flow. With this we should get the access token
        url = settings.SAMI_ACCOUNT_ACCESS_TOKEN

        param = {'code':code, #(required) code we just retrieved
             'redirect_uri':settings.SAMI_RETURN_URI, #(optional) a redirect url in case something goes wrong
             'client_id': settings.CLIENT_ID, #(required) app client id
             'client_secret': settings.CLIENT_SECRET, #(required) app client secret
             'grant_type': "authorization_code" #(required) type of access to be granted
            }

        #do a post request for the second step of the oauth2 flow
        result = requests.post(url, data = param)
        if (result.status_code != 200):
            print("Error: Could not get access token from oauth server")

        data = ast.literal_eval(result.text)
        token = (data["access_token"])

        #get current user
        samiUser = getSelf(token=token)

        contextDict = {'active':"home"}
        response = HttpResponseRedirect('/', contextDict, context)

        #We will use django built in login funcionality to log in and log out users to the demo site. We shall associate
        #a profile model containing the access_token for the user so we can retrieve each time the user does a request
        try:
            #we use the sami user id as user name so it is unique
            user = User.objects.get(username=samiUser.id)
        except User.DoesNotExist:

            #if no user found we create one
            user = User.objects.create_user(username=samiUser.id, password=samiUser.id)

            #we create a profile, stash the access token and link it to the user
            profile = Profile()
            profile.user = user
            profile.oauth_token = token
            profile.save()

        #django login
        user = authenticate(username=samiUser.id, password=samiUser.id)
        django_login(request, user)

    return response
开发者ID:Travis346,项目名称:sami-python-demo,代码行数:60,代码来源:user.py

示例4: edit_profile

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import user [as 别名]
def edit_profile(request):
    """
    Show and edit user profile.
    """
    username = request.user.username

    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            nickname = form.cleaned_data['nickname']
            intro = form.cleaned_data['intro']
            try:
                profile = Profile.objects.get(user=request.user.username)
            except Profile.DoesNotExist:
                profile = Profile()
                
            profile.user = username
            profile.nickname = nickname
            profile.intro = intro
            profile.save()
            messages.success(request, _(u'Successfully edited profile.'))
            # refresh nickname cache
            refresh_cache(request.user.username)
            
            return HttpResponseRedirect(reverse('edit_profile'))
        else:
            messages.error(request, _(u'Failed to edit profile'))
    else:
        try:
            profile = Profile.objects.get(user=request.user.username)
            form = ProfileForm({
                    'nickname': profile.nickname,
                    'intro': profile.intro,
                    })
        except Profile.DoesNotExist:
            form = ProfileForm()

    # common logic
    try:
        server_crypto = UserOptions.objects.is_server_crypto(username)
    except CryptoOptionNotSetError:
        # Assume server_crypto is ``False`` if this option is not set.
        server_crypto = False   

    sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username)
            
    return render_to_response('profile/set_profile.html', {
            'form': form,
            'server_crypto': server_crypto,
            "sub_lib_enabled": sub_lib_enabled,
            }, context_instance=RequestContext(request))
开发者ID:gleez,项目名称:seahub,代码行数:53,代码来源:views.py

示例5: twitter_authenticated

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import user [as 别名]
def twitter_authenticated(request):
    oauth_token = request.session.get('oauth_token',None)
    oauth_token_secret = request.session.get('oauth_token_secret', None)
    if oauth_token == None and oauth_token_secret == None:
        return  HttpResponseRedirect('/')

    # Step 1. Use the request token in the session to build a new client.
    token = oauth.Token(oauth_token, oauth_token_secret)
    client = oauth.Client(consumer, token)
    # Step 2. Request the authorized access token from Twitter.
    resp, content = client.request(access_token_url, "GET")
    if resp['status'] != '200':
        return  HttpResponseRedirect('/')
    access_token = dict(cgi.parse_qsl(content))
    # Step 3. Lookup the user or create them if they don't exist.
    try:
        #user = User.objects.get(username=access_token['screen_name'])
        user = User.objects.get(username=access_token['user_id'])
    except User.DoesNotExist:
        # When creating the user I just use their [email protected]
        # for their email and the oauth_token_secret for their password.
        # These two things will likely never be used. Alternatively, you 
        # can prompt them for their email here. Either way, the password 
        # should never be used.
        user = User.objects.create_user(access_token['user_id'], '%[email protected]' % access_token['screen_name'],
            access_token['oauth_token_secret'])
        # Save our permanent token and secret for later.
        profile = Profile()
        profile.user = user
        profile.twitter_username = access_token['screen_name']
        profile.oauth_token = access_token['oauth_token']
        profile.oauth_secret = access_token['oauth_token_secret']
        profile.save()
        

    # Authenticate the user and log them in using Django's pre-built 
    # functions for these things.
    if not user.check_password(access_token['oauth_token_secret']):
        user.set_password(access_token['oauth_token_secret'])
        user.save()
        profile = Profile.objects.get(user = user)
        profile.oauth_token = access_token['oauth_token']
        profile.oauth_secret = access_token['oauth_token_secret']
        profile.save()

    user = authenticate(username=access_token['user_id'], password=access_token['oauth_token_secret'])
    login(request, user)

    return HttpResponseRedirect('/')
开发者ID:taras1k,项目名称:twevent,代码行数:51,代码来源:views.py

示例6: edit_profile

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import user [as 别名]
def edit_profile(request):
    """
    Show and edit user profile.
    """
    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            nickname = form.cleaned_data['nickname']
            intro = form.cleaned_data['intro']
            try:
                profile = Profile.objects.get(user=request.user.username)
            except Profile.DoesNotExist:
                profile = Profile()
                
            profile.user = request.user.username
            profile.nickname = nickname
            profile.intro = intro
            profile.save()
            messages.success(request, _(u'Successfully edited profile.'))
            # refresh nickname cache
            refresh_cache(request.user.username)
            
            return HttpResponseRedirect(reverse('edit_profile'))
        else:
            messages.error(request, _(u'Failed to edit profile'))
    else:
        try:
            profile = Profile.objects.get(user=request.user.username)
            form = ProfileForm({
                    'nickname': profile.nickname,
                    'intro': profile.intro,
                    })
        except Profile.DoesNotExist:
            form = ProfileForm()

    return render_to_response('profile/set_profile.html', {
            'form': form,
            }, context_instance=RequestContext(request))
开发者ID:orymate,项目名称:seahub,代码行数:40,代码来源:views.py

示例7: register

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import user [as 别名]
def register(request):
    """Try to register new user"""

    if request.user.is_authenticated():
        return redirect('grunts')

    if request.method == 'POST':
        form = CustomRegisterForm(data=request.POST)
        if not form.is_valid():
            return render(
                request,
                'auth/register.html',
                {'form': form}
            )
        else:
            # If valid form -> create user
            user = User.objects.create_user(
                username=form.cleaned_data['username'],
                password=form.cleaned_data['password1']
            )

            # And associate profile
            profile = Profile()
            profile.user = user
            profile.save()

            # Login registered user
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            login_user(request, user)

            # Go to device list
            return redirect('grunts')
    else:
        form = CustomRegisterForm()

    return render(request, 'auth/register.html', {'form': form})
开发者ID:Xifax,项目名称:android-sms-bank,代码行数:38,代码来源:views.py


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