本文整理汇总了Python中newebe.profile.models.UserManager类的典型用法代码示例。如果您正苦于以下问题:Python UserManager类的具体用法?Python UserManager怎么用?Python UserManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserManager类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self):
'''
Creates a picture and corresponding activity. Then picture is
propagated to all trusted contacts.
Errors are stored inside activity.
'''
filebody = self.request.body
filename = self.get_argument("qqfile")
try:
tag = self.get_argument("tag")
except:
tag = "all"
filetype = mimetypes.guess_type(filename)[0] or \
'application/octet-stream'
if filebody:
picture = Picture(
title = "New Picture",
path=filename,
contentType=filetype,
authorKey = UserManager.getUser().key,
author = UserManager.getUser().name,
isMine = True,
isFile = True,
tags = [tag]
)
picture.save()
picture.put_attachment(content=filebody, name=filename)
thumbnail = self.get_thumbnail(filebody, filename, (200, 200))
thbuffer = thumbnail.read()
picture.put_attachment(thbuffer, "th_" + filename)
os.remove("th_" + filename)
preview = self.get_thumbnail(filebody, filename, (1000, 1000))
picture.put_attachment(preview.read(), "prev_" + filename)
os.remove("th_" + filename)
picture.save()
self.create_owner_creation_activity(
picture, "publishes", "picture")
self.send_files_to_contacts("pictures/contact/",
fields =
{ "json": str(picture.toJson(localized=False)) },
files = [("picture", str(picture.path), thbuffer)],
tag=tag)
logger.info("Picture %s successfuly posted." % filename)
self.return_json(picture.toJson(), 201)
else:
self.return_failure("No picture posted.", 400)
示例2: get_current_user
def get_current_user(self):
'''
With tornado, authentication is handled in this method.
'''
user = UserManager.getUser()
if user:
if user.password is None:
logger.error("User has no password registered")
self.redirect("/register/password/")
else:
password = self.get_secure_cookie("password")
if not password or \
user.password != hashlib.sha224(password).hexdigest():
logger.error("User is not authenticated")
self.redirect("/login/")
else:
return user
else:
logger.error("User is not authenticated")
self.redirect("/register/")
示例3: post
def post(self):
'''
Sets given password as user password (after sha-224 encryption).
'''
user = UserManager.getUser()
if user is None:
self.return_failure("User does not exist.")
elif user.password is not None:
self.return_failure("Password is already set.")
else:
data = self.get_body_as_dict(expectedFields=["password"])
if data:
postedPassword = data["password"]
if postedPassword and len(postedPassword) > 3:
password = \
hashlib.sha224(postedPassword).hexdigest()
user.password = password
user.save()
self.set_secure_cookie("password", postedPassword)
self.return_json(user.toJson())
else:
self.return_failure(
"Password is too short. User password is not set.", 400)
else:
self.return_failure(
"Data are not correct. User password is not set.", 400)
示例4: get
def get(self):
'''
Retrieves current user (newebe owner) data at JSON format.
'''
user = UserManager.getUser()
self.return_document(user)
示例5: get
def get(self):
'''
If no user exist, it redirects to register root page, else
it returns register page.
'''
if UserManager.getUser():
self.redirect("/")
else:
self.render("../auth/templates/register.html",
isTheme=self.is_file_theme_exists())
示例6: create_owner_deletion_activity
def create_owner_deletion_activity(self, doc, verb, docType):
'''
Creates a new activity corresponding to a document deletion made
by owner.
* doc: The deleted document.
* verb: verb linked to this activity.
* docType: Type of the deleted document.
'''
self.create_deletion_activity(
UserManager.getUser().asContact(), doc, verb, docType, True)
示例7: save
def save(self):
'''
When document is saved, the last modified field is updated to
make sure it is always correct.
'''
if not self.authorKey:
user = UserManager.getUser()
self.authorKey = user.key
self.author = user.name
self.lastModified = datetime.datetime.utcnow()
NewebeDocument.save(self)
示例8: given_there_are_3_posts_of_and_3_posts_of_my_contacts
def given_there_are_3_posts_of_and_3_posts_of_my_contacts(step,
nbposts,
nbcontactposts):
nbposts = int(nbposts)
nbcontactposts = int(nbcontactposts)
for i in range(1, nbposts + 1):
micropost = MicroPost()
micropost.author = UserManager.getUser().name
micropost.authorKey = UserManager.getUser().key
micropost.content = "my content {}".format(i)
micropost.date = datetime.datetime(2011, i, 01, 11, 05, 12)
micropost.isMine = True
micropost.save()
for i in range(1, nbcontactposts + 1):
micropost = MicroPost()
micropost.author = world.user2.name
micropost.authorKey = world.user2.key
micropost.content = "contact content {}".format(i)
micropost.date = datetime.datetime(2011, i, 10, 11, 05, 12)
micropost.isMine = False
micropost.save()
示例9: send_profile_to_contacts
def send_profile_to_contacts(self):
'''
External methods to not send too much times the changed profile.
A timer is set to wait for other modifications before running this
function that sends modification requests to every contacts.
'''
client = HTTPClient()
self.sending_data = False
user = UserManager.getUser()
jsonbody = user.toJson()
activity = Activity(
authorKey = user.key,
author = user.name,
verb = "modifies",
docType = "profile",
method = "PUT",
docId = "none",
isMine = True
)
activity.save()
for contact in ContactManager.getTrustedContacts():
try:
request = HTTPRequest("%scontacts/update-profile/" % contact.url,
method="PUT", body=jsonbody, validate_cert=False)
response = client.fetch(request)
if response.error:
logger.error("""
Profile sending to a contact failed, error infos are
stored inside activity.
""")
activity.add_error(contact)
activity.save()
except:
logger.error("""
Profile sending to a contact failed, error infos are
stored inside activity.
""")
activity.add_error(contact)
activity.save()
logger.info("Profile update sent to all contacts.")
示例10: delete
def delete(self, id):
'''
Deletes picture corresponding to id.
'''
picture = PictureManager.get_picture(id)
if picture:
user = UserManager.getUser()
if picture.authorKey == user.key:
self.create_owner_deletion_activity(
picture, "deletes", "picture")
self.send_deletion_to_contacts("pictures/contact/", picture)
picture.delete()
self.return_success("Picture deleted.")
else:
self.return_failure("Picture not found.", 404)
示例11: set_default_user
def set_default_user(self, url=ROOT_URL):
"""
Set to DB default user. This is useful for automatic login.
"""
self.root_url = url
self.user = UserManager.getUser()
if self.user:
self.user.delete()
self.user = User(
name="John Doe",
password=hashlib.sha224("password").hexdigest(),
key="key",
authorKey="authorKey",
url=url,
description="my description",
)
self.user.save()
示例12: on_picture_found
def on_picture_found(self, picture, id):
'''
'''
self.picture = picture
data = dict()
data["picture"] = picture.toDict(localized=False)
data["contact"] = UserManager.getUser().asContact().toDict()
contact = ContactManager.getTrustedContact(picture.authorKey)
client = ContactClient()
body = json_encode(data)
try:
client.post(contact, u"pictures/contact/download/",
body, self.on_download_finished)
except HTTPError:
self.return_failure("Cannot download picture from contact.")
示例13: put
def put(self, key):
'''
Resend deletion of micropost with *key* as key to the contact given in
the posted JSON. Corresponding activity ID is given inside the posted
json.
Here is the format : {"contactId":"data","activityId":"data"}
'''
data = self.get_body_as_dict(
expectedFields=["contactId", "activityId", "extra"])
if data:
contactId = data["contactId"]
activityId = data["activityId"]
date = data["extra"]
contact = ContactManager.getTrustedContact(contactId)
activity = ActivityManager.get_activity(activityId)
if not contact:
self.return_failure("Contact not found", 404)
elif not activity:
self.return_failure("Activity not found", 404)
else:
user = UserManager.getUser()
picture = Picture(
authorKey = user.key,
date = date_util.get_date_from_db_date(date)
)
logger.info(
"Attemp to resend a picture deletion to contact: {}.".format(
contact.name))
self.forward_to_contact(picture, contact, activity,
method = "PUT")
else:
self.return_failure("Micropost not found", 404)
示例14: set_default_user_2
def set_default_user_2(self, url=ROOT_URL):
'''
Set to DB default user. This is useful for automatic login.
'''
self.root_url = url
User._db = db2
self.user = UserManager.getUser()
if self.user:
self.user.delete()
self.user = User(
name = "Dan Frazer",
password = hashlib.sha224("password").hexdigest(),
key = "key2",
authorKey = "authorKey2",
url = url,
description = "my description"
)
self.user.save()
User._db = db