示例#1
0
    def post(self):
        if self.ensure_is_logged_in() and self.ensure_has_display_name():
            self.check_CSRF()
            user_id = self.user_id
            message_accept = self.request.get('accept')
            message_decline = self.request.get('decline')

            if message_accept:
                sender_id = EnkiModelMessage.get_by_id(
                    int(message_accept)).sender
                if sender_id:
                    EnkiModelFriends.add_friend(user_id, sender_id)
                    self.add_infomessage(
                        MSG.SUCCESS(),
                        MSG.FRIEND_ADDED(
                            EnkiModelDisplayName.get_display_name(sender_id)))
            elif message_decline:
                sender_id = EnkiModelMessage.get_by_id(
                    int(message_decline)).sender
                if sender_id:
                    EnkiModelMessage.remove_messages_crossed(
                        user_id, sender_id)

            self.render_tmpl('messages.html',
                             data=EnkiModelMessage.get_messages(self.user_id))
示例#2
0
 def delete_account(self, delete_posts=False, token=''):
     token_to_save = 'accountdelete'
     if not token:
         # there is no token if the user has no email address: they are deleted immediately. They must be logged in.
         user_to_delete = self.enki_user
     else:
         # a user has followed a accountdelete token link. The user account associated with the token will be deleted
         tokenEntity = EnkiModelTokenVerify.get_by_token(token)
         user_to_delete = EnkiModelUser.get_by_id(tokenEntity.user_id)
         # delete all user related tokens except any verify token related to account deletion that's not yet been used
         if tokenEntity.type == token_to_save:
             token_to_save = 'accountandpostsdelete'
     verify_tokens_to_delete = EnkiModelTokenVerify.fetch_keys_by_user_id_except_type(
         user_to_delete.key.id(), token_to_save)
     if verify_tokens_to_delete:
         ndb.delete_multi(verify_tokens_to_delete)
     email_rollback_tokens_to_delete = EnkiModelTokenEmailRollback.fetch_keys_by_user_id(
         user_to_delete.key.id())
     if email_rollback_tokens_to_delete:
         ndb.delete_multi(email_rollback_tokens_to_delete)
     # Delete the user account and log them out.
     if not HandlerBase.account_is_active(user_to_delete.key.id()):
         # delete user if the account is inactive
         display_names = EnkiModelDisplayName.fetch_keys_by_user_id(
             user_to_delete.key.id())
         if display_names:
             ndb.delete_multi(display_names)
         user_to_delete.key.delete()
     else:
         # anonymise the user
         if user_to_delete.email:
             # delete email subscriptions
             EnkiModelEmailSubscriptions.remove_by_email(
                 user_to_delete.email)
             user_to_delete.email = None
         if user_to_delete.password:
             user_to_delete.password = None
         if user_to_delete.auth_ids_provider:
             user_to_delete.auth_ids_provider = []
         user_to_delete.put()
         # keep all historical display_names. Add a new current display_name '[deleted]' (unless it's already been deleted)
         display_name = EnkiModelDisplayName.get_by_user_id_current(
             user_to_delete.key.id())
         if display_name:
             if display_name.prefix != EnkiModelDisplayName.DELETED_PREFIX or display_name.suffix != EnkiModelDisplayName.DELETED_SUFFIX:
                 EnkiModelDisplayName.set_display_name(
                     user_to_delete.key.id(),
                     EnkiModelDisplayName.DELETED_PREFIX,
                     EnkiModelDisplayName.DELETED_SUFFIX)
         # delete user's sent and received messages
         EnkiModelMessage.delete_user_messages(user_to_delete.key.id())
         # delete user's posts if required
         if delete_posts:
             EnkiModelPost.delete_user_posts(user_to_delete.key.id())
     # log the deleted user out
     if self.enki_user == user_to_delete.key.id():
         self.log_out()
     EnkiModelTokenAuth.revoke_user_authentications(user_to_delete.key.id())
示例#3
0
def send_friend_request( sender_id, friend_id ):
	if friend_id != sender_id: # friend is not me
		if not exist_EnkiFriends_by_friends( sender_id, friend_id ): # we're not currently friends
			already_invited = enki.libmessage.get_key_EnkiMessage_by_sender_recipient( friend_id, sender_id )
			if already_invited:
				# if an invite from the potential friend already exists, add the couple of friends immediately and delete the invite(s)
				add_friend( sender_id, friend_id )
			# send an invitation to friend (unless it's a duplicate)
			elif not enki.libmessage.exist_EnkiMessage_by_sender_recipient( sender_id, friend_id ):
				message = EnkiModelMessage( sender = sender_id, recipient = friend_id, type = 'friend_request' )
				message.put()
			result = enki.libutil.ENKILIB_OK
	else:
		result = enki.libdisplayname.ERROR_DISPLAY_NAME_INVALID
	return result
示例#4
0
def get_EnkiMessage_by_sender_recipient( sender_id, recipient_id ):
	entity = EnkiModelMessage.query( ndb.AND( EnkiModelMessage.sender == sender_id,
	                                          EnkiModelMessage.recipient == recipient_id )).get()
	if entity:
		return entity
	else:
		return None
示例#5
0
def exist_EnkiMessage_by_sender_recipient( sender_id, recipient_id ):
	count = EnkiModelMessage.query( ndb.AND( EnkiModelMessage.sender == sender_id,
	                                         EnkiModelMessage.recipient == recipient_id )).count( 1 )
	if count:
		return True
	else:
		return False
示例#6
0
def exist_sent_or_received_message( user_id ):
	count = EnkiModelMessage.query( ndb.OR( EnkiModelMessage.sender == user_id,
	                                        EnkiModelMessage.recipient == user_id )).count( 1 )
	if count:
		return True
	else:
		return False
示例#7
0
 def send_friend_request(cls, sender_id, friend_id):
     result = enki.libutil.ENKILIB_OK
     if friend_id != sender_id:  # friend is not me
         if not cls.exist_by_user_ids(
                 sender_id, friend_id):  # we're not currently friends
             already_invited = EnkiModelMessage.get_key_by_sender_recipient(
                 friend_id, sender_id)
             if already_invited:
                 # if an invite from the potential friend already exists, add the pair of friends immediately and delete the invite(s)
                 cls.add_friend(sender_id, friend_id)
                 result = cls.INFO_FRIENDS
             # send an invitation to friend (unless it's a duplicate)
             elif not EnkiModelMessage.exist_by_sender_recipient(
                     sender_id, friend_id):
                 EnkiModelMessage.send_message(sender_id, friend_id,
                                               'friend_request')
     else:
         result = EnkiModelDisplayName.ERROR_DISPLAY_NAME_INVALID
     return result
示例#8
0
def send_friend_request(sender_id, friend_id):
    result = enki.libutil.ENKILIB_OK
    if friend_id != sender_id:  # friend is not me
        if not exist_EnkiFriends_by_friends(
                sender_id, friend_id):  # we're not currently friends
            already_invited = enki.libmessage.get_key_EnkiMessage_by_sender_recipient(
                friend_id, sender_id)
            if already_invited:
                # if an invite from the potential friend already exists, add the pair of friends immediately and delete the invite(s)
                add_friend(sender_id, friend_id)
                result = INFO_FRIENDS
            # send an invitation to friend (unless it's a duplicate)
            elif not enki.libmessage.exist_EnkiMessage_by_sender_recipient(
                    sender_id, friend_id):
                message = EnkiModelMessage(sender=sender_id,
                                           recipient=friend_id,
                                           type='friend_request')
                message.put()
    else:
        result = enki.libdisplayname.ERROR_DISPLAY_NAME_INVALID
    return result
示例#9
0
 def account_is_active(cls, user_id):
     # detect activity on a user account
     result = False
     has_friends = True if EnkiModelFriends.fetch_by_user_id(
         user_id) else False
     has_messages = True if EnkiModelMessage.exist_sent_or_received(
         user_id) else False
     has_forum_posts = True if EnkiModelPost.fetch_by_author(
         user_id) else False
     has_product = True if EnkiModelProductKey.exist_by_purchaser_or_activator(
         user_id) else False
     has_email_subscriptions = False
     email = ndb.Key(EnkiModelUser, user_id).get().email
     if email:
         has_email_subscriptions = True if EnkiModelEmailSubscriptions.exist_by_email(
             email) else False
     if has_friends or has_messages or has_forum_posts or has_product or has_email_subscriptions:
         result = True
     return result
示例#10
0
def get_EnkiMessage_by_sender_recipient(sender_id, recipient_id):
    entity = EnkiModelMessage.query(
        ndb.AND(EnkiModelMessage.sender == sender_id,
                EnkiModelMessage.recipient == recipient_id)).get()
    return entity
示例#11
0
def exist_EnkiMessage_by_sender_recipient(sender_id, recipient_id):
    count = EnkiModelMessage.query(
        ndb.AND(EnkiModelMessage.sender == sender_id,
                EnkiModelMessage.recipient == recipient_id)).count(1)
    return count > 0
示例#12
0
def fetch_EnkiMessage_by_recipient(user_id):
    list = EnkiModelMessage.query(
        EnkiModelMessage.recipient == user_id).fetch()
    return list
示例#13
0
def count_EnkiMessage_by_recipient(user_id):
    count = EnkiModelMessage.query(
        EnkiModelMessage.recipient == user_id).count()
    return count
示例#14
0
 def get_data(self, handler):
     data = [0]
     if handler.user_id:
         if EnkiModelMessage.exist_by_recipient(handler.user_id):
             data = [1]  # user has message
     return data
示例#15
0
def exist_sent_or_received_message( user_id ):
	count = EnkiModelMessage.query( ndb.OR( EnkiModelMessage.sender == user_id,
	                                        EnkiModelMessage.recipient == user_id )).count( 1 )
	return count > 0
示例#16
0
 def remove_friend(cls, user_id, friend_id):
     friends = cls.get_key_by_user_ids(user_id, friend_id)
     if friends:
         friends.delete()
     # clean up any remaining friend invitations (from either side)
     EnkiModelMessage.remove_messages_crossed(user_id, friend_id)
示例#17
0
def get_key_EnkiMessage_by_sender_recipient( sender_id, recipient_id ):
	entity = EnkiModelMessage.query( ndb.AND( EnkiModelMessage.sender == sender_id,
	                                          EnkiModelMessage.recipient == recipient_id )).get( keys_only = True )
	return entity
示例#18
0
def exist_EnkiMessage_by_sender_recipient( sender_id, recipient_id ):
	count = EnkiModelMessage.query( ndb.AND( EnkiModelMessage.sender == sender_id,
	                                         EnkiModelMessage.recipient == recipient_id )).count( 1 )
	return count > 0
示例#19
0
 def get_data(self, handler):
     if handler.ensure_is_logged_in():
         friends = EnkiModelFriends.count_by_user_id(handler.user_id)
         messages = EnkiModelMessage.count_by_recipient(handler.user_id)
         data = [friends, messages]
         return data
示例#20
0
def count_EnkiMessage_by_recipient( user_id ):
	count = EnkiModelMessage.query( EnkiModelMessage.recipient == user_id ).count()
	return count
示例#21
0
 def get(self):
     if self.ensure_is_logged_in() and self.ensure_has_display_name():
         self.render_tmpl('messages.html',
                          active_menu='profile',
                          data=EnkiModelMessage.get_messages(self.user_id))
示例#22
0
def exist_sent_or_received_message(user_id):
    count = EnkiModelMessage.query(
        ndb.OR(EnkiModelMessage.sender == user_id,
               EnkiModelMessage.recipient == user_id)).count(1)
    return count > 0
示例#23
0
def fetch_keys_sent_or_received_message( user_id ):
	list = EnkiModelMessage.query( ndb.OR( EnkiModelMessage.sender == user_id,
	                                        EnkiModelMessage.recipient == user_id )).fetch( keys_only = True )
	return list
示例#24
0
def fetch_EnkiMessage_by_recipient( user_id ):
	list = EnkiModelMessage.query( EnkiModelMessage.recipient == user_id ).fetch()
	return list
示例#25
0
 def add_friend(cls, user_id, friend_id):
     if not cls.exist_by_user_ids(user_id, friend_id):
         friends = cls(friends=[user_id, friend_id])
         friends.put()
     # clean up any remaining friend invitations (from either side)
     EnkiModelMessage.remove_messages_crossed(user_id, friend_id)