def wrapper(*args, **kwargs): user_info = database.check_user(kwargs['event'].data["from"]["userId"]) if user_info["not_exist"]: database.add_user(kwargs['event'].data["from"]["userId"]) user_info = database.check_user( kwargs['event'].data["from"]["userId"]) func(*args, **kwargs)
def wrapper(*args, **kwargs): user_info = database.check_user(kwargs['event'].data["from"]["userId"]) if user_info["not_exist"]: database.add_user(kwargs['event'].data["from"]["userId"], kwargs['event'].data["from"]["firstName"], kwargs['event'].data["from"].get('lastName', '')) user_info = database.check_user( kwargs['event'].data["from"]["userId"]) func(*args, **kwargs)
def auth_signup(): post_data = request.get_json() from database import check_user user = check_user(post_data['username'], post_data['password']) print(user) if user is not None and (user['email'] is None or user['email'] == ''): from database import update_user if update_user(post_data['username'], post_data['email'], post_data['fullname']): token = jwt.encode({ 'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'username': post_data['username'] }, JWT_SECRET, algorithm=JWT_ALGORITHM).decode('utf-8') return { 'success': True, 'token': token } else: return { 'success': False, 'reason': 'creation_failed' } return { 'success': False, 'reason': 'no_account' if user is None else 'already_created' }
def check_user(self, username, password): if db.check_user(username, password): print("welcome ", username) self.show_frame(MainMenu) else: print("who are you??")
def process(message_data): user_db = database.connect_db() type = message_data.get('post_type') message_type = message_data.get('message_type') if type == 'message' and message_type == 'private': uid = message_data.get('user_id') message = message_data.get('message') exist = database.check_user(uid, user_db) matched = re.search(pattern=r"[(.*?)]", string=message, flags=re.M | re.I) if exist == 0: if matched: database.user_register(uid, matched.group(1), user_db) return 0 else: send._pri_m('数据库中并没有查询到您的数据呢QAQ\n来注册一个吧', uid) send._pri_m('注册格式为: [您喜欢的名称] (保留方括号噢@A@)', uid) send._pri_m('请尽量使用英文字母噢(*^_^*)', uid) return 0 else: reply = response.reply(uid, type, message) data = reply.get_response() if data != 'ERROR': send._pri_m(data, uid) return 0 elif type == 'message' and message_type == 'group': uid = message_data.get('user_id') gid = message_data.get('group_id') message = message_data.get('message') self_id = message_data.get('self_id') if not database.check_user(uid, user_db): stri = '数据库中并没有查询到您的数据呢QAQ\n来注册一个吧\n向机器人私聊发送消息完成注册' send._group_m(stri, gid, uid) return 0 reply = response.group_reply(str(self_id), uid, type, message) data = reply.get_response() print data if data != 'ERROR': send._group_m(data, gid, uid) return 0 elif type == 'requests': uid = message_data.get('user_id') flag = message_data.get('flag') send._acc_request(flag) return 0
def check_user(): username = login_tbox1Text.get() password = login_tbox2Text.get() if db.check_user(username, password): print("welcome ", username) else: print("who are you??")
def login(): POST_USERNAME = str(request.form['username']) POST_PASSWORD = str(request.form['password']) res = check_user(POST_USERNAME, POST_PASSWORD) if res: session['logged_in'] = True session['team_id'] = res.id return redirect('/')
def f_login(): if request.method == 'POST': user = request.form['username'] passw = request.form['password'] check = request.form.getlist('check') if check_user(user, passw): if check: session['user'] = user return render_template("ad-search.html", Username=user) return render_template("main.html", items=get_4())
def f_login(): if request.method == 'POST': user = request.form['username'] passw = request.form['password'] check = request.form.getlist('check') if check_user(user, passw): if check: session['user'] = user return render_template("ad-search.html", Username=user) return render_template("main.html", items=get_4())
def main(): options = int(input("1: Add User" "\n2: Delete User" "\n3: Check User" "\n4: Display Db" "\n5: Create Db\n")) if options == 1: try: database.new_user() except Exception as error: print("ERROR:", error) finally: print("\n") main() if options == 2: try: database.delete_user() except Exception as error: print("ERROR:", error) finally: print("\n") main() if options == 3: try: database.check_user() except Exception as error: print("ERROR:", error) finally: print("\n") main() if options == 4: database.display_db() print("\n") main() if options == 5: try: database.create_db() print("Database created\n") except Exception as error: print("Error", error) finally: main()
def login(): if request.method == 'POST': email = request.form['email'] password = request.form['password'] if db.check_user(email, password): print('logged in') return render_template('hello.html', name=email) else: return "password or username is incorrect" return render_template('login.html')
def access_db(): """Renders 'user.html' page and checks for passed username inside the database. Gets user's data tuple only when flash messages are not displayed.""" form = LoginForm() global session_user if form.validate_on_submit(): if not signing_up: # As signing in... if database.check_user(form.username.data) is not None: flash('Username taken!') return redirect(url_for('access_db')) else: database.create_user(form.username.data, form.userkey.data) session_user = database.check_user(form.username.data) return redirect(url_for('user_choice')) else: if database.check_user(form.username.data) is None: flash('Cannot find username in database!') else: session_user = database.check_user(form.username.data) return redirect(url_for('user_choice')) return render_template('user.html', form=form)
def login(): if request.method == 'POST': email = request.form['email'] password = request.form['password'] if db.check_user(email, password): print('logged in') session['email'] = email return redirect(url_for('index')) else: return "password or username is incorrect" # Get request return render_template('login.html')
def login(): message = '' if request.method == 'POST': email = request.form.get('email') password_input = request.form.get('password') user = get_user(email) print(user) if check_user(email, password_input): login_user(user) return redirect(url_for('home')) else: message = 'Failed to login!' return render_template('login.html', message=message)
def start(update, context): tel_id = update.message.chat.id if not db.check_user(tel_id): keys = [[ InlineKeyboardButton('آقا', callback_data='male'), InlineKeyboardButton('خانم', callback_data='female') ]] update.message.reply_text( 'سلام، به ربات دوستیاب خوش آمدید \n\n' 'برای شروع ابتدا جنسیت خود را انتخاب کنید', reply_markup=InlineKeyboardMarkup(keys, one_time_keyboard=True)) else: gender = db.get_gender(tel_id)[0] if gender == 'male': choices_male(update, context, False) elif gender == 'female': choices_female(update, context, False)
def auth(request): body = json.loads(request.body) if body["type"] == "isLog": for this_session in request.session.keys(): #If session exists yet return HttpResponse(json.dumps({"isLog": True })) #Return true if session exists return HttpResponse(json.dumps( {"isLog": False})) #Return false if session doesn't exist elif body["type"] == "login": if database.check_user( body["login"], body["password"] ) == True: #Checking if login and password correct request.session[body["login"]] = body[ "password"] #Start new session return HttpResponse( json.dumps({"redirect_url": url + "?profile=" + body["login"]}) ) #Return redirection link to profile page after success login else: return HttpResponse( json.dumps({'error': 'Incorrect login or password' })) #Error if login or password incorrect elif body["type"] == "logout": for this_session in request.session.keys(): #Get session name del request.session[this_session] #Delete session with this name break #Stop loop return HttpResponse(json.dumps({"redirect_url": url + "auth" })) #Return redirection link to auth elif body["type"] == "registration": if database.check_login( body["login"]) == True: #Checking login uniqueness return HttpResponse(json.dumps({'error': 'User already exist' })) #Error if this login exist yet database.add_user(body["name"], body["login"], body["password"]) #Create new user request.session[body["login"]] = body["password"] #Start new session return HttpResponse( json.dumps({ "redirect_url": url + "?profile=" + body["login"] })) #Return redirection link to profile page after registration
def auth_login(): post_data = request.get_json() from database import check_user from database import clear_user_token user = check_user(post_data['username'], post_data['password']) if user is not None and (user['email'] is not None and user['email'] != ''): clear_user_token(post_data['username']) token = jwt.encode({ 'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'username': post_data['username'] }, JWT_SECRET, algorithm=JWT_ALGORITHM).decode('utf-8') return { 'success': True, 'token': token, 'fullName': user['fullName'], 'email': user['email'], 'webAlerts': user['webAlerts'], 'emailAlerts': user['emailAlerts'] } return { 'success': False, 'reason': 'no_account' if user is None else 'signup_required' }
def check_new_msg(self): url = self.url + "getUpdates?offset={}".format(self.offset) content = self.get_url(url) if content == None: return try: update_id = content['update_id'] txt = content['message']['text'] user_id = content['message']['from']['id'] self.update_offset(update_id) if int(check_user(user_id)) == 1: if get_state(user_id,"on_register")[0][0] == 1: txt = txt.strip(" ") try: text = txt.split(",") res = change_parameters(user_id,text[0],text[1],text[2],text[3], text[4]) except Exception as e: print(e) res = 0 if res ==1: self.send_message(user_id, "Valores registrados con exito!") reset_field(user_id,"ack_eth") reset_field(user_id,"ack_btc") else: self.send_message(user_id, "Hubo un problema registrando sus valores. Intentelo nuevamente") reset_field(user_id, "on_register") else: print(txt) if txt == '1': history_file = open("./history.txt") last_prices = history_file.readlines()[-1] history_file.close() last_prices = last_prices.strip("\n") last_prices = last_prices.split(",") self.send_message(user_id,"Los ultimos precios registrados son:\nFECHA: "+last_prices[0]+"\nBTC = "+last_prices[1]+" USD"+"\nETH = "+last_prices[2]+" USD") elif txt == '2': generate_plot('BTC', get_state(user_id, 'hours')[0][0]) generate_plot('ETH', get_state(user_id, 'hours')[0][0]) self.send_img(user_id,"./btc.png") self.send_img(user_id,"./eth.png") self.send_img(user_id,"./btc_candlestick.png") self.send_img(user_id,"./eth_candlestick.png") elif txt == '3': self.send_message(user_id,"Para registrarse correctamente, escriba los limites superiores e inferiores de su alarma separados por coma. Si no desea tener en cuenta un parametro escriba -1 en su valor. Por ejemplo: btc_sup,btc_inf,eth_sup,eth_inf, hours.\n") set_field(user_id, "on_register") elif txt == '4': th_sup_btc = get_state(user_id,'th_sup_btc')[0][0] th_inf_btc = get_state(user_id,'th_inf_btc')[0][0] th_sup_eth = get_state(user_id,'th_sup_eth')[0][0] th_inf_eth = get_state(user_id,'th_inf_eth')[0][0] hours = str(get_state(user_id,'hours')[0][0]) self.send_message(user_id,"Tus parametros actuales son:\nLIMITE SUPERIOR BTC = " +th_sup_btc+"\nLIMITE INFERIOR BTC = "+th_inf_btc+"\nLIMITE SUPERIOR ETH = "+th_sup_eth+"\nLIMITE INFERIOR ETH = "+th_inf_eth+"\nVENTANA DE TIEMPO PARA GRAFICOS = "+hours+"h") elif txt == 'btc_ok': set_field(user_id , "ack_btc") self.send_message(user_id, " Alarma de BTC reconocida!") print("BTC ACK = 1") elif txt == 'eth_ok': set_field(user_id , "ack_eth") self.send_message(user_id, " Alarma de ETH reconocida!") print("ETH ACK = 1") else: self.display_options(user_id) else: self.send_message(user_id,"Para registrarse correctamente, escriba los limites superiores e inferiores de su alarma separados por coma. Si no desea tener en cuenta un parametro escriba -1 en su valor. Por ejemplo: btc_sup,btc_inf,eth_sup,eth_inf, hours.\n") print(add_user(user_id)) set_field(user_id, "on_register") except Exception as e: self.update_offset(update_id) print(e) pass
def login(): global who global currentUserID all_disabled() if len(entry_userId.get()) != 0 and len(entry_pass.get()) != 0: userID = database.check_user(entry_userId.get(), entry_pass.get()) if userID: if userID == "0": who = 0 button_take.configure(state='normal') button_give.configure(state='normal') elif userID == "1": who = 1 button_middle.configure(state='normal') button_add.configure(state='normal') button_del.configure(state='normal') button_take.configure(state='normal') button_give.configure(state='normal') button_frequency.configure(state='normal') button_onHand.configure(state='normal') elif userID == "2": who = 2 button_middle.configure(state='normal') button_add.configure(state='normal') button_del.configure(state='normal') button_take.configure(state='normal') button_give.configure(state='normal') button_plusOne.configure(state='normal') button_plusTwo.configure(state='normal') button_plusFive.configure(state='normal') button_plusTen.configure(state='normal') button_plusFT.configure(state='normal') button_plusTwenty.configure(state='normal') button_frequency.configure(state='normal') button_onHand.configure(state='normal') elif userID == "5": messagebox.showerror('error', 'Неверный пароль') return else: messagebox.showerror('error', 'Пользователь не найден') else: messagebox.showerror('error', 'Заполните необходимые поля') return var1.set(0) var2.set(0) var3.set(0) if len(entry_userId.get()) != 0: currentUserID = entry_userId.get() fill_on_hand_table() entry_userId.delete(0, 'end') entry_pass.delete(0, 'end') button_sortID.configure(state='normal') button_sortID2.configure(state='normal') button_sortName.configure(state='normal') button_sortName2.configure(state='normal') button_sortAuthor.configure(state='normal') button_sortAuthor2.configure(state='normal') button_sortYear.configure(state='normal') button_sortYear2.configure(state='normal') button_sortCount.configure(state='normal') button_sortCount2.configure(state='normal') button_exit.configure(state='normal') button_enter.configure(state='disabled') button_reg.configure(state='disabled')
def pword(db, tok): key = itsdangerous.URLSafeSerializer(config.cred['secretKeys']) out = key.loads(tok) res = database.check_user(db, out[0], out[1]) if res: return template('pwordReset', user=tok, pwordError=False)
def robot(message): if message.text == "/start": if message.from_user.id in config.ADMIN_ID: markup = types.InlineKeyboardMarkup() a = types.InlineKeyboardButton("Iran Cyber Security Group", url="https://iran-cyber.net") b = types.InlineKeyboardButton("Safe Data Hosting Co", url="https://safe-data.ir") markup.add(a) markup.add(b) bot.send_message(message.chat.id, "Yay, Admin 😎🌹\nSend me your Link", reply_markup=markup) else: if database.check_user(message.from_user.id) == "New_User": markup = types.InlineKeyboardMarkup() a = types.InlineKeyboardButton("En", callback_data="En") b = types.InlineKeyboardButton("Fa", callback_data="Fa") markup.add(a, b) bot.send_message( message.chat.id, "سلام [{}](tg://user?id={})\nبه ربات کوتاه کننده لینک ایران سایبر خوش آمدید\nزبان خود را انتخاب کنید\n➖➖➖➖➖➖\nHi [{}](tg://user?id={})\nWelcome to IRan Cyber Shortlink Bot\nSelect Your Language" .format(message.from_user.first_name, message.from_user.id, message.from_user.first_name, message.from_user.id), reply_markup=markup, parse_mode="Markdown") for x in config.ADMIN_ID: bot.send_message( x, "New user -> [{}](tg://user?id={})".format( message.from_user.first_name, message.from_user.id), parse_mode="markdown") else: if database.check_lang(message.from_user.id) == "Fa": markup = types.InlineKeyboardMarkup() change_lang = types.InlineKeyboardButton( "تغییر زبان", callback_data="change_lang") a = types.InlineKeyboardButton( "Iran Cyber Security Group", url="https://iran-cyber.net") b = types.InlineKeyboardButton("Safe Data Hosting Co", url="https://safe-data.ir") markup.add(change_lang) markup.add(a) markup.add(b) bot.send_message( message.chat.id, "سلام [{}](tg://user?id={})\nبه ربات کوتاه کننده لینک ایران سایبر خوش آمدید\nلینک خود را برای کوتاه شدن ارسال کنید" .format(message.from_user.first_name, message.from_user.id), reply_markup=markup, parse_mode="Markdown") else: markup = types.InlineKeyboardMarkup() change_lang = types.InlineKeyboardButton( "change language", callback_data="change_lang") a = types.InlineKeyboardButton( "Iran Cyber Security Group", url="https://iran-cyber.net") b = types.InlineKeyboardButton("Safe Data Hosting Co", url="https://safe-data.ir") markup.add(change_lang) markup.add(a) markup.add(b) bot.send_message( message.chat.id, "Hi [{}](tg://user?id={})\nWelcome to IRan Cyber Shortlink Bot\nEnter Your Link" .format(message.from_user.first_name, message.from_user.id), reply_markup=markup, parse_mode="Markdown") else: if message.text.startswith("http://") or message.text.startswith( "https://"): markup = types.InlineKeyboardMarkup() a = types.InlineKeyboardButton("Iran Cyber Security Group", url="https://iran-cyber.net") b = types.InlineKeyboardButton("Safe Data Hosting Co", url="https://safe-data.ir") markup.add(a) markup.add(b) if message.from_user.id in config.ADMIN_ID: bot.send_message(message.chat.id, "Shorten Link : \n{}".format( short_link(message.text)), reply_markup=markup) else: if database.check_lang(message.from_user.id) == "Fa": bot.send_message(message.chat.id, "لینک کوتاه شده ی شما \n{}".format( short_link(message.text)), reply_markup=markup) else: bot.send_message(message.chat.id, "Shorten Link : \n{}".format( short_link(message.text)), reply_markup=markup)