我正致力于将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