本文整理汇总了Python中models.User.user方法的典型用法代码示例。如果您正苦于以下问题:Python User.user方法的具体用法?Python User.user怎么用?Python User.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.user方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insertUser
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import user [as 别名]
def insertUser(request):
errors = []
u = User()
u.user = re.escape(request.POST.get('user'))
u.email = request.POST.get('email')
password = re.escape(request.POST.get('password'))
salt = uuid.uuid4().hex
hashed_password = hashlib.sha512(password + salt).hexdigest()
u.password = hashed_password
u.salt = salt
u.locked = False
u.activated = False
u.attempts = 0
num_users = u.query(User.user==u.user).count()
num_emails = u.query(User.email==u.email).count()
if num_users == 0 and num_emails == 0:
code = hashlib.sha512(u.user + salt).hexdigest()
u.code = re.escape(code)
u.put()
params = { 'user' : u.user, 'code': code}
sendEmail(u.email, "Account verification url: http://dsswkvn.appspot.com/validateaccount?" + urllib.urlencode(params))
return True
else:
message = "No se ha podido insertar el usuario"
if (num_users != 0):
errors.append("User already exists")
if (num_emails != 0):
errors.append("Email already exists")
template_values = {
'errors': errors
}
return template_values
示例2: save
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import user [as 别名]
def save(self, *args, **kwargs):
"Form processor"
profile = None
if self.invitation:
# Create DjangoUser
django_user = django_auth.User(
username=self.cleaned_data['username'], password='')
django_user.set_password(self.cleaned_data['password'])
django_user.save()
# Crate profile
try:
profile = django_user.profile
except:
profile = User()
profile.user = django_user
profile.name = django_user.username
profile.default_group = self.invitation.default_group
profile.save()
# Create contact
try:
contact_type = ContactType.objects.get(
Q(name='Person') | Q(slug='person'))
except:
contact_type = ContactType.objects.all()[0]
try:
# Check if contact has already been created (e.g. by a signals
contact = profile.get_contact()
if not contact:
contact = Contact()
except:
contact = Contact()
contact.name = self.cleaned_data['name']
contact.contact_type = contact_type
contact.related_user = profile
contact.save()
# Set email
try:
emailfield = contact_type.fields.filter(field_type='email')[0]
email = ContactValue(
value=self.invitation.email, field=emailfield, contact=contact)
email.save()
except:
pass
# Add quick start widget
widget = Widget(user=profile,
perspective=profile.get_perspective(),
module_name='anaf.core',
widget_name='widget_welcome')
widget.save()
return profile
示例3: activateAccount
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import user [as 别名]
def activateAccount(user, code):
u = User()
u.user = user
u.code = code
users = u.query(ndb.AND(User.user==u.user, User.code == u.code)).fetch()
if(len(users)>0):
users[0].activated = True
users[0].put()
示例4: checkValidUser
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import user [as 别名]
def checkValidUser(request):
u = User()
u.user = re.escape(request.POST.get('user'))
num_users = u.query(User.user==u.user).count()
if (num_users == 0):
return True
else:
return False
示例5: confirmChange
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import user [as 别名]
def confirmChange(user, code):
u = User()
u.user = user
u.code = code
users = u.query(ndb.AND(User.user==u.user, User.code == u.code)).fetch()
if(len(users)>0):
users[0].password = users[0].new_password
users[0].new_password = ''
users[0].put()
示例6: changePassword
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import user [as 别名]
def changePassword(request, user):
password = re.escape(request.POST.get('password'))
newpassword = re.escape(request.POST.get('newPassword'))
confirm = re.escape(request.POST.get('confirmPassword'))
error = False
errors = []
u = User()
u.user = user
u.password = password
u.new_password = newpassword
users = u.query(User.user==u.user).fetch()
if(len(users)>0):
salt = users[0].salt
hashed_password = hashlib.sha512(password + salt).hexdigest()
hashed_newpassword = hashlib.sha512(newpassword + salt).hexdigest()
users = u.query(ndb.AND(User.user==u.user, User.password == hashed_password)).fetch()
if(len(users)>0):
if(users[0].password != hashed_newpassword):
users[0].new_password = hashed_newpassword
users[0].put()
params = { 'user' : users[0].user, 'code': users[0].code}
sendEmail(users[0].email, "Change password url: http://dsswkvn.appspot.com/confirmchange?" + urllib.urlencode(params))
else:
error = True
password_error = "New password must be different from the last one"
errors.append(password_error)
else:
error = True
password_error = "Wrong password"
errors.append(password_error)
else :
error = True
user_error = "Wrong user"
errors.append(user_error)
if error:
template_values = {
'errors': errors
}
return template_values
else:
return False
示例7: login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import user [as 别名]
def login(request):
u = User()
u.user = re.escape(request.POST.get('user'))
password = re.escape(request.POST.get('password'))
user = u.query(User.user==u.user).fetch()
if(len(user)>0):
salt = user[0].salt
else:
return 3
hashed_password = hashlib.sha512(password + salt).hexdigest()
u.password = hashed_password
num_users = u.query(ndb.AND(User.user==u.user, User.password == u.password)).count()
if (num_users > 0):
user = User()
user = u.query(User.user==u.user).fetch()
if (user[0].activated == False):
return 4
else:
if(user[0].locked == False):
user[0].attempts = 0
user[0].put()
return 1
else:
return 0
else:
num_users = u.query(User.user==u.user).count()
if (num_users > 0):
user = User()
user = u.query(User.user==u.user).fetch()
attempts = user[0].attempts
if (attempts < 3):
attempts = attempts + 1
if (attempts >= 3):
user[0].locked = True
user[0].attempts = attempts
user[0].put()
return 2
else:
return 3
示例8: _populate
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import user [as 别名]
def _populate(self):
leader = User.user(self.request.POST['leader'])
group = Group(name=self.request.POST['name'],
leader=leader)
return group
示例9: getUsersPhotos
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import user [as 别名]
def getUsersPhotos(user):
u = User()
u.user = user
i = Image()
photos = i.query(Image.user==u.user).fetch()
return photos
示例10: getEmail
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import user [as 别名]
def getEmail(user):
u = User()
u.user = user
users = u.query(User.user==u.user).fetch()
return users[0].email
示例11: getAttempts
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import user [as 别名]
def getAttempts(request):
u = User()
u.user = re.escape(request.POST.get('user'))
users = u.query(User.user==u.user).fetch()
return users[0].attempts