Ejemplo n.º 1
0
    def new_user(email, username, password, management_api, admin=False):
        """Initializes a new user, generating a salt and encrypting
        his password. Then creates a RabbitMQ user if needed and sets
        permissions.
        """
        email = email.lower()
        user = User(email=email, username=username, admin=admin)

        user.salt = os.urandom(14).encode('base_64')
        user.secret_hash = hash_password(password=password, salt=user.salt)

        if management_api is not None:
            # Creating the appropriate rabbitmq user if it doesn't already
            # exist.
            try:
                management_api.user(username)
            except management_api.exception:
                management_api.create_user(username=username, password=password)

            read_perms = '^(queue/{0}/.*|exchange/.*)'.format(username)
            write_conf_perms = '^(queue/{0}/.*|exchange/{0}/.*)'.format(username)

            management_api.set_permission(username=username,
                                          vhost='/',
                                          read=read_perms,
                                          configure=write_conf_perms,
                                          write=write_conf_perms)

        db_session.add(user)
        db_session.commit()

        return user
Ejemplo n.º 2
0
 def post(self):
     # 获取request的json并新建一个用户
     data = request.get_json()
     address = self.object(data)
     db_session.add(address)
     db_session.commit()
     return 'ok', 'basic'
Ejemplo n.º 3
0
def seed_cedict():
    """Seed the Chinese/English dictionary with data from CEDICT."""
    with open('seeds/cedict3.csv', 'rb') as f:
        reader = csv.reader(f, delimiter=',', quotechar='"')
        for row in reader:
            if row[0] == '#':
                continue
            else:
                for i in range(len(row)):
                    row[i] = row[i].decode('utf-8')

                trad, simp, pinyin = row[0], row[1], row[2]
                definition = ''.join(row[3:])
                pinyin = pinyin.strip('"')
                definition = definition.strip('"')

                entry = Dict_Entry(simplified=simp,
                                   traditional=trad,
                                   pinyin=pinyin,
                                   definition=definition)
                db_session.add(entry)
        try:
            db_session.commit()
        except sqlalchemy.exc.IntegrityError, e:
            db_session.rollback()
Ejemplo n.º 4
0
def start(bot, update):
	id = update.message.chat.id
	if id > 0: # groups ignored
		keyboard = [['Status', 'Media'], 
			        ['Settings', 'Chat'], 
			        ['Referral link']]
		reply_markup = ReplyKeyboardMarkup(keyboard, resize_keyboard=True)
		welcome_text = '''Welcome to the AIRDROP CTLgroup bot!
						To get 25 CTLcoin please do the following:
						- specify in the bot settings the links to your reposts from our Facebook and Twitter pages
						- subscribe to our telegram channel @CryptoTradeLine and go to chat
						To get additional tokens invite your friends to the bot and get 1 CTLcoin for each one connected to the bot'''
		bot.send_message(chat_id=id, text=welcome_text, reply_markup=reply_markup)
		msg = update.message.text.replace('/start', '').strip()
		entered_user = User.query.filter(User.id==id).first()
		if entered_user == None:

			db_session.add(User(id=id, name=update.message.chat.username, inviter=msg))
			db_session.commit()
			print('commited')
			if msg != '' and msg != str(id):
				bonus = 1
				inviter = User.query.filter(User.id==msg).first()
				inviter.tokens_acc += bonus
				inviter.refs += 1
				tokens_left = Parametr.query.filter(Parametr.parametr=='Tokens_left').first()
				tokens_left.value_flt -= bonus
				db_session.commit()
				bot.send_message(chat_id=msg, text='+ %s tokens for friend inviting ' % bonus + update.message.chat.first_name)
			elif msg == str(id):
				update.message.text_reply('You have received a link to yourself, do /start')
		elif msg == str(id):
			bot.send_message(chat_id=id, text='You invited yourself')
Ejemplo n.º 5
0
def create_new_tag(dish_id, rest_id, tag_id):
    """Add more tags"""
    rest_dish = Rest_Dish(dish_id=dish_id, rest_id=rest_id)
    db_session.add(rest_dish)
    db_session.commit()

    dish_tag = Dish_Tag(dish_id=dish_id, tag_id=tag_id, rest_dish_id=rest_dish.id)
    db_session.add(dish_tag)
    db_session.commit()
Ejemplo n.º 6
0
def create_new_tag(dish_id, rest_id, tag_id):
    """Add more tags"""
    rest_dish = Rest_Dish(dish_id=dish_id, rest_id=rest_id)
    db_session.add(rest_dish)
    db_session.commit()

    dish_tag = Dish_Tag(dish_id=dish_id,
                        tag_id=tag_id,
                        rest_dish_id=rest_dish.id)
    db_session.add(dish_tag)
    db_session.commit()
Ejemplo n.º 7
0
    def new_user(email, admin=False):
        """Initializes a new user, generating a salt and encrypting
        his password. Then creates a RabbitMQ user if needed and sets
        permissions.
        """
        email = email.lower()
        user = User(email=email, admin=admin)

        db_session.add(user)
        db_session.commit()

        return user
Ejemplo n.º 8
0
def seed_users():
    """Seed users with test users."""

    emilypass = os.environ.get("EMILYPASS")
    emily = User(username='******')
    emily.set_password(emilypass)

    nickpass = os.environ.get("NICKPASS")
    nick = User(username="******")
    nick.set_password(nickpass)

    db_session.add(emily)
    db_session.add(nick)
    db_session.commit()
Ejemplo n.º 9
0
def seed_images():
    with open("seeds/images_seed.txt") as f:
        reader = csv.reader(f, delimiter="|")
        for row in reader:
            dish_id = row[0]
            filename = row[1].strip()

            image = Image(dish_id=dish_id, filename=filename)
            db_session.add(image)

    try: 
        db_session.commit()
    except sqlalchemy.exc.IntegrityError, e:
        db_session.rollback()
Ejemplo n.º 10
0
def seed_users():
    """Seed users with test users."""

    emilypass = os.environ.get("EMILYPASS")
    emily = User(username='******')
    emily.set_password(emilypass)

    nickpass = os.environ.get("NICKPASS")
    nick = User(username="******")
    nick.set_password(nickpass)

    db_session.add(emily)
    db_session.add(nick)
    db_session.commit()
Ejemplo n.º 11
0
def seed_images():
    with open("seeds/images_seed.txt") as f:
        reader = csv.reader(f, delimiter="|")
        for row in reader:
            dish_id = row[0]
            filename = row[1].strip()

            image = Image(dish_id=dish_id, filename=filename)
            db_session.add(image)

    try:
        db_session.commit()
    except sqlalchemy.exc.IntegrityError, e:
        db_session.rollback()
Ejemplo n.º 12
0
def seed_tags():
    """Seed tags with test data."""
    tags = [
        Tag(name="spicy"),
        Tag(name="chicken"),
        Tag(name="pork"),
        Tag(name="beef"),
        Tag(name="vegetarian"),
        Tag(name="fish")
    ]

    for tag in tags:
        db_session.add(tag)

    db_session.commit()
Ejemplo n.º 13
0
    def create_user(username, password, password_verify):
        if password != password_verify:
            return "Error: Passwords do not match."

        user = db_session.query(User).filter_by(username=username)

        if user:
            return "Error: User already exists."

        user = User(username=username)
        user.set_password(password)
        db_session.add(user)
        db_session.commit()

        return "User created."
Ejemplo n.º 14
0
def seed_tags():
    """Seed tags with test data."""
    tags = [
        Tag(name="spicy"),
        Tag(name="chicken"),
        Tag(name="pork"),
        Tag(name="beef"),
        Tag(name="vegetarian"),
        Tag(name="fish")
    ]

    for tag in tags:
        db_session.add(tag)

    db_session.commit()
Ejemplo n.º 15
0
    def change_password(self, new_password, management_api):
        """"Changes" a user's password by deleting his rabbitmq account
        and recreating it with the new password.
        """
        try:
            management_api.delete_user(self.username)
        except management_api.exception:
            pass
        management_api.create_user(username=self.username, password=new_password)
        management_api.set_permission(username=self.username, vhost='/',
                                      read='.*', configure='.*', write='.*')

        self.salt = os.urandom(14).encode('base_64')
        self.secret_hash = hash_password(password=new_password, salt=self.salt)

        db_session.add(self)
        db_session.commit()
Ejemplo n.º 16
0
def seed_restaurants():
    """Seed restaurants with test data."""
    r1 = Restaurant(name="Chef Zhao's")
    r2 = Restaurant(name="Fu Lam Mum")
    r3 = Restaurant(name="Chef Chu's")
    r4 = Restaurant(name="Queen House")
    r5 = Restaurant(name="Cafe Macs")
    db_session.add(r1)
    db_session.add(r2)
    db_session.add(r3)
    db_session.add(r4)
    db_session.commit()
Ejemplo n.º 17
0
def seed_food_words():
    """Seed food_words table with common food words."""
    with open('seeds/food_words_seed.txt', 'rb') as f:
        reader = csv.reader(f, delimiter='|')
        for row in reader:
            for i in range(len(row)):
                row[i] = row[i].decode('utf-8')
                row[i] = row[i].strip()

            simplified = row[0]
            english = row[1].lower()

            food_word = Food_Word(simplified=simplified, english=english)
            db_session.add(food_word)

        try: 
            db_session.commit()
        except sqlalchemy.exc.IntegrityError, e:
            db_session.rollback()
Ejemplo n.º 18
0
def seed_food_words():
    """Seed food_words table with common food words."""
    with open('seeds/food_words_seed.txt', 'rb') as f:
        reader = csv.reader(f, delimiter='|')
        for row in reader:
            for i in range(len(row)):
                row[i] = row[i].decode('utf-8')
                row[i] = row[i].strip()

            simplified = row[0]
            english = row[1].lower()

            food_word = Food_Word(simplified=simplified, english=english)
            db_session.add(food_word)

        try:
            db_session.commit()
        except sqlalchemy.exc.IntegrityError, e:
            db_session.rollback()
Ejemplo n.º 19
0
def seed_restaurants():
    """Seed restaurants with test data."""
    r1 = Restaurant(name="Chef Zhao's")
    r2 = Restaurant(name="Fu Lam Mum")
    r3 = Restaurant(name="Chef Chu's")
    r4 = Restaurant(name="Queen House")
    r5 = Restaurant(name="Cafe Macs")
    db_session.add(r1)
    db_session.add(r2)
    db_session.add(r3)
    db_session.add(r4)
    db_session.commit()
Ejemplo n.º 20
0
def seed_cedict():
    """Seed the Chinese/English dictionary with data from CEDICT."""
    with open('seeds/cedict3.csv', 'rb') as f:
        reader = csv.reader(f, delimiter=',', quotechar='"')
        for row in reader:
            if row[0] == '#':
                continue
            else:
                for i in range(len(row)):
                    row[i] = row[i].decode('utf-8')

                trad, simp, pinyin = row[0], row[1], row[2]
                definition = ''.join(row[3:])
                pinyin = pinyin.strip('"')
                definition = definition.strip('"')

                entry = Dict_Entry(simplified=simp, traditional=trad, pinyin=pinyin, definition=definition)
                db_session.add(entry)
        try: 
            db_session.commit()
        except sqlalchemy.exc.IntegrityError, e:
            db_session.rollback()
Ejemplo n.º 21
0
def seed_dishes():
    """Seed dishes table with common dish names from Dianping and others."""
    with open('seeds/dishes_seed.txt', 'rb') as f:
        reader = csv.reader(f, delimiter='|')
        for row in reader:
            for i in range(len(row)):
                row[i] = row[i].decode('utf-8')
                row[i] = row[i].strip()

            chin_name = row[0]
            eng_name = row[1].lower()
            if len(row) > 2:
                desc = row[2]
                dish = Dish(chin_name=chin_name, eng_name=eng_name, desc=desc)
            else:
                dish = Dish(chin_name=chin_name, eng_name=eng_name)
            db_session.add(dish)

        try:
            db_session.commit()
        except sqlalchemy.exc.IntegrityError, e:
            db_session.rollback()
Ejemplo n.º 22
0
def seed_dishes():
    """Seed dishes table with common dish names from Dianping and others."""
    with open('seeds/dishes_seed.txt', 'rb') as f:
        reader = csv.reader(f, delimiter='|')
        for row in reader:
            for i in range(len(row)):
                row[i] = row[i].decode('utf-8')
                row[i] = row[i].strip()

            chin_name = row[0]
            eng_name = row[1].lower()
            if len(row) > 2:
                desc = row[2]
                dish = Dish(chin_name=chin_name, eng_name=eng_name, desc=desc)                                            
            else:
                dish = Dish(chin_name=chin_name, eng_name=eng_name)
            db_session.add(dish)

        try: 
            db_session.commit()
        except sqlalchemy.exc.IntegrityError, e:
            db_session.rollback()
Ejemplo n.º 23
0
def add_review(user_id, dish_id, rest_id, tag_id, text):
    now = datetime.datetime.now()

    rest_dish = Rest_Dish(dish_id=dish_id, rest_id=rest_id)
    db_session.add(rest_dish)
    db_session.commit()

    dish_tag = Dish_Tag(dish_id=dish_id, tag_id=tag_id, rest_dish_id=rest_dish.id)
    db_session.add(dish_tag)
    db_session.commit()

    review = Review(user_id=user_id, rest_dish_id=rest_dish.id, dish_id=dish_id, text=text, date=now)
    db_session.add(review)
    db_session.commit()
Ejemplo n.º 24
0
def add_review(user_id, dish_id, rest_id, tag_id, text):
    now = datetime.datetime.now()

    rest_dish = Rest_Dish(dish_id=dish_id, rest_id=rest_id)
    db_session.add(rest_dish)
    db_session.commit()

    dish_tag = Dish_Tag(dish_id=dish_id,
                        tag_id=tag_id,
                        rest_dish_id=rest_dish.id)
    db_session.add(dish_tag)
    db_session.commit()

    review = Review(user_id=user_id,
                    rest_dish_id=rest_dish.id,
                    dish_id=dish_id,
                    text=text,
                    date=now)
    db_session.add(review)
    db_session.commit()