def services(message): if not user.check(message.chat.id): user.create(message.chat.id, message.chat.username) if message.text == "Заявки": bot.send_message(message.chat.id, "Загрузка данных...") data = mongo.get_data(message.chat.id) if not data: bot.send_message(message.chat.id, "Заявки не найдены.") for app in data: text = "".join([ f"Тип продукта: {app['service']}!\n", f"Имя продукта: {app['proposal']}.\n", f"Статус: {app['status']}.", ]) bot.send_message(message.chat.id, text) elif message.text == "Специалист": # bot.send_message(message.chat.id, "Данный раздел находится в разработке.\nПриносим свои извинения.") bot.send_message(message.chat.id, 'Запрос Отправлен.\nВ ближайшее время с вами свяжется специалист банка.') bot.send_message(chat_id=1184113473, text=f'Клиент @{message.chat.username} просит начать консультацию.') else: user_message = message.text user.set(message.chat.id, service=user_message) try: markup = types.InlineKeyboardMarkup(row_width=1) markup.add(*menu.services[user_message]) bot.send_message(message.chat.id, choice(menu.service_messages), reply_markup=markup) except KeyError: bot.send_message(message.chat.id, 'Неверная команда')
def create_account(): error = None #Like in login, if the page request was POST, it probably means the user #clicked the create account button. So let's make them an account! if request.method == 'POST': #First we collect all jount they typed in db = get_db() name = request.form['create_username'] pw = request.form['create_pw'] check = request.form['check_pw'] email = request.form['email'] college = request.form['college'] marketing = request.form['marketing'] prog = request.form['prog_expr'] #check passwords match if pw != check: error = 'Passwords do not match' return render_template('login.html', error=error) #Let's make sure they didn't select someone else's user name result = db.execute("SELECT USER_ID FROM USERS WHERE " \ "USERNAME=?", [name]).fetchone() if result is not None: error = 'That user name already exists :(' elif not valid_email(email): error = 'Invalid email format' elif re.search('[^\w.]', name): # only allow a-zA-Z0-9_. for usernames error = 'Invalid username format' if not error: #Encrypt the password so I'm not tempted to hax ur facebookzzz salt = hex(int(random() * 1000000)) enc_pw = encrypt_password(pw, salt) #Stick all the collected info into the DB so I can stalk y'all forever query = "INSERT INTO USERS (USERNAME, PASSWORD, SALT, EMAIL," \ + " COLLEGE, MARKETING, PROG_EXPR, PORT, PARTNER_PORT) " \ + "VALUES(?, ?, ?, ?, ?, ?, ?, 0, 0)" db.execute(query, [name, enc_pw, salt, email, college, marketing, prog]) db.commit() #Create an account on the server so that you guys can log in try: user.create(name, pw) except: print "FAILED during user creation" set_session_vars(name, 0, 0) flash('Your account was created successfully!') return redirect(url_for('home')) #If the request was just a GET, or something went wrong in the login, #show the login page return render_template('login.html', error=error)
def start_message(message): # Создание нового пользователя user.create(message.chat.id, message.chat.username) # выводим клавиатуру markup = types.ReplyKeyboardMarkup(resize_keyboard=True) markup.add(*menu.start) text = "".join([ f"Здравствуйте, {message.from_user.first_name}!\n", # f"Вас приветствует - <b>{bot.get_me().first_name}</b>.\n\n", "Выберите необходимый пункт меню:\n", ]) # приветствие после команды /start bot.send_message(message.chat.id, text, parse_mode='html', reply_markup=markup)
def login(user): if user.retrieve(): return True else: data.mode = "failed" char = None while True: char = sys.stdin.read(1)[0] if char in ["t", "c", "q"]: break if char is "t": return False if char is "c": data.mode = "create" input_text(data) if user.passphrase == data.current_input: user.create() return True if char is "q": stop(data)
def user_create(): # TODO: Test and improve. data = request.get_json() password_hash = pbkdf2_sha256.hash(data.get('password')) date = datetime.date.today() result = user.create(get_db(), data.get('email'), data.get('username'), password_hash, date) if result: return Response(status=201) return Response(status=400)
def respond(data): print(data) text = data.get('body') user_id = data.get('author') body = data.get('body') print(data) if os.getenv('ARBITRUR_PHONE') in user_id: return True message = build_message(user_id, text, body) log_handler.insert_message(message) print(message) if message['text'] == 'KABOOM!': hard_reset(message) return True RECIEVER_ID = user.phone_to_id(os.getenv('ARBITRUR_PHONE')) new_user_phone = data.get('chatId').replace('@c.us', '') user_data = { 'name': data.get('senderName'), 'phone': new_user_phone, 'country': geo.get_country_name_and_flag(new_user_phone) } if user.get(user_id) is None: user.create(user_id, user_data) # Demote or promote user if there is a change in the agent list user.demote_to_user_if_needed(user_id, user_data) user.promote_to_agent_if_needed(user_id, user_data) # If we are already handling a message and we are not done, ignore. conversation.update_canonical_conversation(user_id, RECIEVER_ID, text, 'user') if user.is_bot_answering(user_id) == True: return True user.set_user_answering(user_id) print('Moving Convo') core.recieve_message(message) user.remove_user_answering(user_id) return True
def register(email, password): """ This function registers a new user with the specified email/password. :param email: The email to use for registration :param password: The password to use for the user :return: A redirect to a page that indicates success/failure as needed """ # first check recaptcha import requests user = create(email, password) if user is None: print 'Returning to register' # TODO: Change this to an error page return json.dumps({'result': 'failed'}) else: print 'returning to login' # TODO: Change this to contain a cookie with the auth key or whatever session['username'] = email return json.dumps({'result': 'success'})
def test_create_user(self): # generate random user name as duplicates raise an error name = utils.get_random_name() surname = utils.get_random_surname() username = f'{name[:1]}{surname}' new_user = { 'username': username, 'first_name': name, 'surname': surname } user, status = user_api.create(new_user) self.assertEqual(status, 201) email = f'{username}@{utils.generate_random_string(6)}.com' print(f'creating new email: {email}') contact_detail = { 'email': email } result, status = contact_detail_api.create(user.get('user_id'), contact_detail) assert (status == 201)
def create_contact(): ''' creates new contact :return: ''' name = utils.get_random_name() surname = utils.get_random_surname() username = f'{name[:1]}{surname}' new_user = { 'username': username, 'first_name': name, 'surname': surname } print(f'creating new user: {username}') user, status = user_api.create(new_user) assert(status == 201) email = f'{username}@{utils.generate_random_string(6)}.com' print(f'creating new email: {email}') contact_detail = { 'email': email } result, status = contact_detail_api.create(user.get('user_id'), contact_detail) assert(status == 201)
def init(): if not can_init: return "can not init" db.drop_tables([Goods, Topic, User, AdGroup, Ad], safe=True) db.create_tables([Goods, Topic, User, Ad, AdGroup], safe=False) Topic.create(id=1, name='综合', title='首页', desc='测试简介简介', img='xx', can_remove=False) Topic.create(id=2, name='家居家装', title='家居家装', desc='', img='xx', can_remove=False) Topic.create(id=3, name='数码家电', title='数码家电', desc='', img='', can_remove=False) Topic.create(id=4, name='母婴', title='母婴', desc='', img='', can_remove=False) Topic.create(id=5, name='食品', title='食品', desc='', img='', can_remove=False) Topic.create(id=6, name='女装', title='女装', desc='', img='', can_remove=False) Topic.create(id=7, name='鞋包配饰', title='鞋包配饰', desc='', img='', can_remove=False) Topic.create(id=8, name='美装个护', title='美装个护', desc='', img='', can_remove=False) Topic.create(id=9, name='男装', title='男装', desc='', img='', can_remove=False) Topic.create(id=10, name='内衣', title='内衣', desc='', img='', can_remove=False) Topic.create(id=11, name='聚优惠', title='聚优惠', desc='', img='', can_remove=False) Topic.create(id=12, name='9.9包邮', title='9.9包邮', desc='', img='', can_remove=False) Topic.create(id=13, name='好货推荐', title='好货推荐', desc='', img='', can_remove=False) AdGroup.create(id=1, name='首页焦点图') AdGroup.create(id=2, name='方块广告位') AdGroup.create(id=3, name='banner图') Ad.create(id=1, url="/", img='/static/img/b.png', index=1, adgroup_id=2) Ad.create(id=2, url="/", img='/static/img/b.png', index=2, adgroup_id=2) Ad.create(id=3, url="/", img='/static/img/b.png', index=3, adgroup_id=2) Ad.create(id=4, url="/", img='/static/img/b.png', index=4, adgroup_id=2) user.create('admin', '123456') return 'ok'
user_name = user.name() #returns input taken #checking the newness of user verified = user.verify(user_name) #returns 'T' or 'F' by checking data if verified: #if verified we break the loop instantly verified = True else: #if still not verified we try to verify display.heading("new here?") display.new_here_msg() #display some msg while True: #force user to login or signup user_choice = user.choice() if user_choice == 1: #account creating code goes here user.create(user_name) log.create(user_name) print("ACCOUNT CREATION : SUCCESSFUL") verified = True break #we break our loop elif user_choice == 2: break #we break our program to change username else: display.input_warning() ##---------------------------AFTER LOGGED PART-----------------------------## print("LOGGED AS " + user_name) user_data = matrix.create("users/" + user_name + ".txt") #print(user_data) run = True
def get_messages_pool(data, nicknameDict, UserIndexDict, channelsDict): # init dicts messages_per_channel = {} total_message_count = 0 messages_per_user = {} history = {} perHourDict = {} words_per_user = {} total_word_count = 0 mentions_count = {} word_frequency = {} emotes_frequency = {} # hour prep for x in range(24): if x < 10: perHourDict.update({"0" + str(x) + ":00": 0}) else: perHourDict.update({str(x) + ":00": 0}) # users prep user.create(UserIndexDict, nicknameDict) # looping for channel in data: for message in data[channel]: messages_per_channel = if_not_in(channel, messages_per_channel) total_message_count += 1 # Read "u" u = data[channel][message]["u"] messages_per_user = if_not_in(u, messages_per_user) # Read "t" # History time = int(data[channel][message]["t"] / 1000) time_formated_date = datetime.utcfromtimestamp( time).strftime('%Y-%m-%d') history = if_not_in(time_formated_date, history) # PerHour time_formated_hour = datetime.utcfromtimestamp(time).strftime('%H') i = int(perHourDict.get(time_formated_hour + ":00")) + 1 perHourDict.update({time_formated_hour + ":00": i}) # Read "m" content = None try: content = data[channel][message]["m"] except KeyError: content = "" # words_per_user words = content.split(" ") words_per_user = if_not_in(u, words_per_user, len(words)) # total_words total_word_count += len(words) # word frequency for word in words: word = word.lower() if len(word) >= 4 and word[:2] != "<@": if word[:2] == "<:" and word[-1] == ">": emotes_frequency = if_not_in(word, emotes_frequency) else: word_frequency = if_not_in(re.sub(r'[^\w]', '', word), word_frequency) # mentions if "@everyone" in content: mentions_count = if_not_in("@everyone", mentions_count) elif "@" in content: for mention in re.findall(r"[0-9]+", content): nick = "@" + str(nicknameDict.get(mention)) if nick != "@None": mentions_count = if_not_in(nick, mentions_count) user.mentioned(list(UserIndexDict.values()).index( str(nicknameDict.get(mention)))) # Read "a" if "a" in data[channel][message].keys(): files = data[channel][message]["a"] for f in files: user.images(u, int(data[channel][message]["t"]), f["url"]) # user class user.mostActiveChannel(u, channel) user.firstMessage(u, time) user.lastMessage(u, time) user.history(u, time_formated_date) user.perHour(u, time_formated_hour) user.messagesCount(u) user.wordsCount(u, len(words)) user.mostUsedWord(u, words) # Normalisation messages_per_user = normalise(UserIndexDict, messages_per_user) words_per_user = normalise(UserIndexDict, words_per_user) messages_per_channel = normalise(channelsDict, messages_per_channel) # Sorting history = history_sort(history) messages_per_channel = order_sort(messages_per_channel, 50) messages_per_user = order_sort(messages_per_user, 50) words_per_user = order_sort(words_per_user, 50) mentions_count = order_sort(mentions_count, 50) word_frequency = order_sort(word_frequency, 50) emotes_frequency = order_sort(emotes_frequency, 10) # Users finalisation users = {} for i in UserIndexDict.keys(): users.update({UserIndexDict.get(i): user.show(i, channelsDict)}) return (total_message_count, total_word_count, messages_per_channel, messages_per_user, words_per_user, mentions_count, history, perHourDict, word_frequency, users, emotes_frequency)
def get(self, name, password, email, status): return user.create(name, password, email, status)
def create_user(user_str, sid): errors = user.create(user_str, True) sio.emit('created-user', errors)
def logic(interaction, message): user_id = message['user_id'] user_context = conversation.context(user_id) name = user_context.get('new_user_info_name') phone = user_context.get('new_user_info_phone') country = user_context.get('new_user_info_country') conversation.update_context(user_id, 'new_user_info_name', None) conversation.update_context(user_id, 'new_user_info_phone', None) conversation.update_context(user_id, 'new_user_info_country', None) id_create_user = user.phone_to_id(phone) users_by_name = user.find(name=name) user_same_name = users_by_name[0] if len(users_by_name) > 0 else None users_by_phone = user.find(phone=phone) user_same_phone = users_by_phone[0] if len(users_by_phone) > 0 else None no_change = False if user.get( id_create_user ) is None and user_same_phone is None and user_same_name is None: user_data = { 'name': name, 'phone': phone, 'country': country, 'owner': user_id, } user.create(id_create_user, user_data, 'outbound') message_start = { 'user_id': id_create_user, 'text': '***Inicio Conversacion Outbound' } pending_conversations.create(id_create_user, [user_id]) conversation.update_context(id_create_user, 'last_reply', datetime.now()) user_register = f"Haz registrado a un nuevo usuario. {name} ({phone})" chat_api.reply(user_register, message) elif user_same_phone is not None: if user_same_phone['name'] != name: user.update(user_same_phone['id'], {'name': name}) name_change = f"Haz cambiado el nombre del usuario con nombre de {name}" chat_api.reply(name_change, message) else: no_change = True elif user_same_name is not None: if user_same_name['phone'] != phone: user.update(user_same_name['id'], {'phone': phone}) phone_change = f"Haz cambiado el telefono del usuario con nombre de {name}" chat_api.reply(phone_change, message) else: no_change = True if no_change == True: chat_api.reply('El usuario no sufrio cambios', message) return True
def POST(self): input = web.input() user.create(user_dbname, "root", hashlib.sha256(input.password1).hexdigest(), type="superuser") raise web.seeother("/")