English 中文(简体)
在连接 d果应用的面板后选择用户名称
原标题:Facitiy to select username after facebook connect on django application

我正致力于将jan果应用与面具结合起来,我几乎只是想让用户在我/她成功贴上手提书之后选择其用户名称:

供使用:

登记册:

username = forms.RegexField(regex=r ^w+$ ,
                            max_length=30,
                            widget=forms.TextInput(attrs=attrs_dict),
                            label=_(u username ))

def clean_username(self):
    """
    Validate that the username is alphanumeric and is not already
    in use.

    """
    try:
        user = User.objects.get(username__iexact=self.cleaned_data[ username ])
    except User.DoesNotExist:
        return self.cleaned_data[ username ]
    raise forms.ValidationError(_(u This username is already taken. Please choose another. ))

此外,还制作了一个对照模板。

这里的意思是,我使用了从中删除的词语。

def register_username(request, form_class=RegisterUsernameForm, template_name= registration/register_username_form.html , extra_context=None):

    if request.method ==  POST :
        form = form_class(data=request.POST, files=request.FILES)
        if form.is_valid():
            username = form[ username ].data
            return HttpResponseRedirect(reverse( facebook_settings ))
    else:
        form = form_class()

    if extra_context is None:
            extra_context = {}
    context = RequestContext(request)
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value
    return render_to_response(template_name,
                          {  form : form },
                          context_instance=context)

在其中,我刚刚从......处获得用户名。

我对我的“詹戈”申请有一丝不.之处,即检查我的台目中是否存在用户,如果当时不产生新用户,则需要重新引导这种“用户名”形式,上面已经提到。 这样,用户可以选择,然后将登记在 d子上。

FbBackend:

def fb_authenticate(self, request, facebook_id=None):
    if not facebook_id: return None
    try:
        profile = UserProfile.objects.get(facebook_id=facebook_id)

        #To Check whether the same user is loggin in to facebook if not then logout the perivous one and login new one.
        if request.user != profile.user :
           from django.contrib.auth import logout
           logout(request)
           request.user=profile.user

        UpdateFbUserDetails(request, profile.user, facebook_id)
        return profile.user
    except UserProfile.DoesNotExist:
        # No user. Create one.
        pass

    #Get user facebook account details like first name, last name and email address. 
    username = request.facebook.users.getInfo([request.facebook.uid], [ name ])[0][ name ]
    firstname = request.facebook.users.getInfo([request.facebook.uid], [ first_name ])[0][ first_name ]
    lastname = request.facebook.users.getInfo([request.facebook.uid], [ last_name ])[0][ last_name ]
    emailaddress = request.facebook.users.getInfo([request.facebook.uid], [ email ])[0][ email ]

    # Create the username for facebook logged in user 
    fbusername = (emailaddress.rsplit ( @ )[0]).replace ( . ,  ) + "_"+((emailaddress.rsplit ( @ )[1])[0]).capitalize()


    try:
        user = User.objects.get(email=emailaddress)
        # This shouldn t really happen. Log an error.
        # logging.error( Strange: user %s already exists.  % username)
    except User.DoesNotExist:
        user = User.objects.create_user(fbusername,emailaddress, xxxx )#( fb_%s  % facebook_id,   )
        user.first_name = firstname 
        user.last_name = lastname

    if not UpdateFbUserDetails(request, user, facebook_id):
        return None
    user.save()
    profile, created = UserProfile.objects.get_or_create(user=user)
    profile.facebook_id = facebook_id
    new_basics_info = UserBasicInfo()
    new_basics_info.full_name = username
    new_basics_info.save()
    profile.basics_info = new_basics_info
    new_personal_info = UserPersonalInfo()
    new_personal_info.save()
    profile.personal_info = new_personal_info
    profile.save()
    return user

请帮助我如何做到这一点。

增 编

Ansh J

最佳回答

我已经解决这个问题。

我只是把所有储蓄法典放在以下几个方面:

if form.is_valid(): and the when user is logged in I navigate him to that page and when he select join then will get registered in my django application .

问题回答

暂无回答




相关问题
problem serving static files to sub directories

In the development environment, static files are served properly as long as the url pattern is limited to one directory. Sub directories lose the css. For example the css processes for the template ...

Django Dynamic menu design question

I want to create dynamic menus according to user permissions. As was already discussed here and by the the documentation itself, I know that I can achieve this in the templates using the following ...

Django DRY URLs for Model access

Reader s Digest version: How do I get data (either single row if specified or full table) from a model by taking a URL argument of the model s name without hardcoding the URLconfs to match each model? ...

Pass session data onto URL

I have some information that is set in the sessions, and I was wondering if it s possible to pass this info onto the URL for the view that uses this session data. I want this to be working in such a ...

Dynamic SEO-friendly URLs

I d like to deploy dynamic URL s for my app in two ways: when viewing available vehicle, I get a link like: http://www.url.com/2006-Acura-MDX-Technology-Package I also have a filter page, so here, ...

url template tag in django template

I was trying to use the url template tag in django, but no lucky, I defined my urls.py like this urlpatterns = patterns( , url(r ^analyse/$ , views.home, name="home"), url(r ^...

django url scheme in apache and dev server

I have a a django application which is being served from apache/mod_wsgi under www.mysite.com/mysite suppose I redirect url "myapp" -> myapp/urls.py so to visit it from apache I will visit www....

热门标签