def make_user(self, name, email, raw_password): """ Takes in a user's information and makes a document in the table representing the user. Requires not user_exists(email). Returns the user. """ assert not self.user_exists(email), ( 'ASSERTION ERROR: User exists with email \'%s\'!' % email) new_user = self._mk.User() new_user.name = name new_user.email = email password = get_hashed_password(raw_password) new_user.password = password new_user.date_created = get_unicode_datetime() new_user.date_last_login = get_unicode_datetime() new_user.bookmark_sort_key = DEFAULT_BOOKMARK_SORT_KEY new_user.bookmark_sort_order = DEFAULT_BOOKMARK_SORT_ORDER new_user.save() return new_user
def get_user_and_login(self, email, raw_password): """ Takes an e-mail address and password and checks if a User exists with this combination. Updates date_last_login if user exists, None otherwise. """ password = get_hashed_password(raw_password) user = self._mk.User.find_one({'email':email, 'password':password}) if user is not None: user.date_last_login = get_unicode_datetime() user.save() return user
def click_bookmark(self, bookmark_id): """ Get a bookmark and record a click for that bookmark. Returns the bookmark. """ bookmark = self.get_bookmark(unicode(bookmark_id)) assert bookmark is not None, ('ASSERTION ERROR: Attempted to click an ' 'invalid bookmark.') bookmark.clicks += 1 bookmark.date_last_clicked = get_unicode_datetime() bookmark.save() return bookmark
def make_circle(self, user_id, name): """ Makes a circle for the given user with the given name. Requires not circle_exists(user, name). Returns the circle. """ assert not self.circle_exists(user_id, name), ('ASSERTION ERROR: ' 'A circle already exists for this user with that name.') new_circle = self._mk.Circle() new_circle.name = name new_circle.owner = unicode(user_id) new_circle.date_created = get_unicode_datetime() new_circle.save() return new_circle
def make_bookmark(self, user_id, url): """ Makes a bookmark for the given user with the given url. Requires not bookmark_exists(user, url). Returns the bookmark. """ assert not self.bookmark_exists(user_id, url), ('ASSERTION ERROR: ' 'A bookmark already exists with the given URL for that user.') new_bookmark = self._mk.Bookmark() new_bookmark.url = url new_bookmark.owner = unicode(user_id) new_bookmark.date_created = get_unicode_datetime() new_bookmark.clicks = 0 new_bookmark.save() return new_bookmark