本文整理汇总了Python中account.models.Account.create_user方法的典型用法代码示例。如果您正苦于以下问题:Python Account.create_user方法的具体用法?Python Account.create_user怎么用?Python Account.create_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类account.models.Account
的用法示例。
在下文中一共展示了Account.create_user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __create_new_account__
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import create_user [as 别名]
def __create_new_account__(self,email,user_data):
"""
We found a new account that does not exist in our database.
Create a Django User from user email and the associated Account object.
Password is automatically generated for the user.
"""
try:
id = self.__extract_account_id__(user_data["resource_uri"])
new_user = Account.create_user(email,email,
user_data["first_name"],
user_data["last_name"],
generate_password=True
)
new_account = Account(ip_address=user_data[u'tr_ip_address'],
email=email,
imported=True,
synched=False,
name = "%s %s" % (user_data["first_name"],user_data["last_name"]),
user = new_user,
imported_date = dt.utcnow().replace(tzinfo=utc),
external_id = id
)
new_account.save()
return True
except Exception,e :
print "Exception %s" % e
return False
示例2: account_registration
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import create_user [as 别名]
def account_registration(request):
# if request.user.is_authenticated():
# return HttpResponseRedirect("/profile/")
if request.method == "POST":
form = RegistrationForm(request.POST)
if form.is_valid():
password = form.cleaned_data["password"]
logger.info( "Password is %s" % password )
username = form.cleaned_data["email"]
if len(username)>30:
username = username[:30]
user,success = Account.create_user(
email=form.cleaned_data["email"],
username= username,
password= password,
generate_password=False
)
acc = Account(user=user)
acc.email = form.cleaned_data["email"]
acc.name = form.cleaned_data["name"]
acc.synched = False
acc.ip_address = get_client_ip(request)
acc.save()
request.session[session_account_id_key] = acc.id
return HttpResponseRedirect("/profile/")
else:
response_data = {
"success":False,
"errors": [(k, v[0]) for k, v in form.errors.items()]
}
return HttpResponse(json.dumps(response_data),mimetype="application/json")
# return render_to_response("register.html",{"form":form},context_instance=RequestContext(request))
else:
"""user not submit"""
form = RegistrationForm
context = {"form":form}
return render_to_response("register.html",context,context_instance=RequestContext(request))
示例3: obj_create
# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import create_user [as 别名]
def obj_create(self, bundle, request=None, **kwargs):
bundle.obj = self._meta.object_class()
# raise ValueError(bundle.obj)
email = None
str = []
# well during debugging kwargs seems to be empty somehow!
# so probably the following for block is totally unnecessary
# I guess full_hydrate does the magic
for key, value in kwargs.items():
str.append("%s = %s" % (key,value))
print >>sys.stderr,("%s = %s" % (key,value))
setattr(bundle.obj, key, value)
bundle = self.full_hydrate(bundle)
email = bundle.obj.email
user = Account.create_user(username=email,email=email,generate_password=True)
bundle.obj.user = user
bundle.obj.ip_address = "127.0.0.1"
# Save FKs just in case.
self.save_related(bundle)
obj = None
bundle.obj.save()
# Now pick up the M2M bits.
m2m_bundle = self.hydrate_m2m(bundle)
self.save_m2m(m2m_bundle)
return bundle