Пример #1
0
    def create(self, user_id):
        """Create and return cookie properties to create a cookie for
        authentication purposes.
        
        """
        fotogal_user = FotogalUser()

        if utils.validate_id(user_id) and fotogal_user.exists(id=user_id):
            random_token = self.__gen_random_token()
            random_token = str(user_id) + ':' + random_token

            # truncate to 64 chars because of the primary key limit.
            if len(random_token) > 64:
                random_token = random_token[:64]

            datetime_now = datetime.datetime.now()
            expire_timedelta = datetime_now + datetime.timedelta(days=7)

            created_ts = int(datetime_now.strftime('%s'))
            expire_ts = int(expire_timedelta.strftime('%s'))
            
            enc_base64_value = self.__encrypt(random_token)
            
            auth_session_dict = {'random_token': random_token, 
                'created_ts': created_ts, 'expire_ts': expire_ts, 
                'user_id': user_id}
                        
            nosql = FotogalNosql()
            nosql_result = nosql.add(self._nosql_table, auth_session_dict)

            if nosql_result:
                return (self._cookie_name, enc_base64_value, expire_ts,)
        
        return None
Пример #2
0
    def add_new_user(self, new_user_dict={}):
        """Add a new user and return the new generated ID from NoSQL.

        """
        if 'password' in new_user_dict:
            passwd_hash = generate_password_hash(new_user_dict['password'])
            new_user_dict['password'] = passwd_hash

            table = self._nosql_table

            nosql = FotogalNosql()
            nosql_result = nosql.add(table, new_user_dict)

            return nosql_result

        else:
            return None
Пример #3
0
    def save(self, user_id, img_filename, img_content, is_profile):
        """Save the image content into Object Storage and register the
        properties in NoSQL.

        """
        if utils.validate_id(user_id):
            new_img_filename = self.__get_new_filename(img_filename)
            img_data_dict = self.__add_img_data(new_img_filename, img_content)

            if img_data_dict:
                img_created_ts = datetime.datetime.now().strftime('%s')

                img_dict = {
                    'image_url': '',
                    'image_filename': new_img_filename,
                    'image_original_filename': img_filename,
                    'image_host_fqdn': '',
                    'image_uri': '',
                    'image_type': '',
                    'created_ts': img_created_ts,
                    'user_id': user_id,
                    'liked_list': [],
                    'disliked_list': [],
                    'main_comment': '',
                    'is_profile': is_profile
                }

                for k, v in img_data_dict.items():
                    img_dict[k] = img_data_dict[k]

                nosql = FotogalNosql()
                new_img_id = nosql.add(self._img_nosql_table, img_dict)

                return new_img_id

        return None