def check_user_session(msg): session_id = db.get_session_id(msg['FromUserName']) if not session_id: return { 'status': 'session_id_not_exist', 'response': weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=u'请先输入 login 命令登陆' ) } else: user_info = db.get_user_info(msg['FromUserName']) if not user_info: return { 'status': 'user_not_exist', 'response': weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=LOGIN_TEXT ) } else: jwxt = Jwxt(user_info['sno'], user_info['password']) jwxt.cookies = {'JSESSIONID': session_id} return { 'status': 'success', 'instance': jwxt }
def user_info(): ign = request.args.get('ign') user_info_dict = get_user_info(ign) response = app.response_class(response=json.dumps(user_info_dict), status=200, mimetype='application/json') return response
def check_user_status(msg): user_info = db.get_user_info(msg['FromUserName']) if not user_info: return { 'status': 'user_not_exist', 'response': weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=LOGIN_TEXT ) } jwxt = Jwxt(user_info['sno'], user_info['password']) if not jwxt.login(): return { 'status': 'jwxt_fail_login', 'response': weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=ERROR_TEXT ) } return { 'status': 'success', 'instance': jwxt }
def login_module(): player_name=input("Username: "******"Please enter your password:"******"Incorrect password. Please try again.") player=Player(user_name,user_password,experience,level) database.sync_from_db(player) print("\nWelcome back!\n") else: password=input("Welcome new player! Please create your password:"******"\n") pokemon1=generate_pokemon_by_name(random.choice(["Charmander","Squirtle","Bulbasaur"])) database.update_pokedex(pokemon1) database.insert_player_pokemon(player,pokemon1) player.pokemon_in_hand.append(pokemon1) print("You recieved a level " + str(pokemon1.pokemon_level) + " " + pokemon1.name + " (HP: " + str(pokemon1.hp) + ", CP: " + str(pokemon1.cp) + ")") for i in range(10): player.bag.add_item(PokeBall("Poke Ball")) player.bag.add_item(Potion("Potion")) player.bag.add_item(Revive("Revive")) print("10 Potions, Poke Balls and Revives have been added to your bag\n") return player
def login_module(): player_name = input("Enter your name:\n") user_exist = database.check_username_in_database(player_name) if (user_exist): user_name, user_password, level, experience = database.get_user_info( player_name) while (input("Please enter your password:"******"Wrong password! Please Try again!") player = Player(user_name, user_password, experience, level) database.sync_from_db(player) print("\nWelcome back! Login completed.\n") else: password = input("Welcome new player! Please create your password:"******"Poke Ball")) player.bag.add_item(Potion("Potion")) player.bag.add_item(Revive("Revive")) player.bag.add_item(RazzBerry("Razz Berry")) player.bag.add_item(Candy("Rare candy")) player.bag.add_item(Candy("Sweet candy")) player.bag.add_item(Candy("Rainbow candy")) player.bag.add_item(Stardust("Silver dust")) player.bag.add_item(Stardust("Gold dust")) player.bag.add_item(Stardust("Diamond dust")) print("Welcome! You will start a new journey.") print("You are given Amazing starting items. Check your bag") return player
def add_email_to_application_name(self): try: email = get_user_info()[1] if email == None: email = get_user_email()['email'] set_user_info({'email': email}) self.name_of_application += ' - {}'.format(email) except: pass
def add_email_to_application_name(self): try: email = get_user_info()[1] if email == None: email = get_user_email()['email'] set_user_info({'email':email}) self.name_of_application += ' - {}'.format(email) except: pass
def add_email_to_application_name(self): try: email = get_user_info()[1] if email == None: email = get_user_email()["email"] set_user_info({"email": email}) self.name_of_application += " - {}".format(email) except: pass
def mainpage(): #equivalent of saying "Is there a user logged in?" if "login" in session and session["login"]: username = session["username"] info = database.get_user_info(username) return render_template("mainpage.html", info=info if info else []) # elif "signout" in session and session["signout"]: else: return "you're not logged in"
def _get_token(**kwargs): try: user_info = get_user_info() refresh_token = user_info[3] if kwargs.get('refresh_token') == True: return refresh_token token = user_info[2] expiry = user_info[4] except: raise IndexError('No settings were returned from the database') if expiry < time.time(): token = update_token()['token'] return token
def _get_token(**kwargs): try: user_info = get_user_info() refresh_token = user_info[3] if kwargs.get('refresh_token') == True: return refresh_token token = user_info[2] expiry = user_info[4] except: raise IndexError('No settings were returned from the database') if expiry < time.time(): token = update_token()['token'] return token
def get_user(data): try: username = data["username"] except KeyError: emit('Error', broadcast=True) return if (db.get_user(username)): password, first_name, name = db.get_user_info(username) user_info = { "success": "success", "username": username, "password": '******', "first_name": first_name, "name": name } emit("user", user_info) else: emit('Error', {"message": "this user doesn't exist", "show": "true"})
def login(): if request.method == 'GET': return render_template('login.html') elif request.method == 'POST': if database.check_user_and_pass(request.form['username'], request.form['password']) == True: session['login'] = True session['username'] = request.form['username'] print("success") # run a differnet function info = database.get_user_info(session["username"]) return redirect(url_for("mainpage", info=info if info else [])) else: print('error:username or password are incorrect!!') return render_template( 'login.html', incorrect_user_or_pass= '******') return redirect(url_for('fpage'))
def temp(email, transaction_id): get_photo_from_db() user_id, phone_number = get_user_info(email) if get_photo_from_db: confidence, label = recognize_face() print(f"Match: {confidence}, DB OwnerMatched Label:{label}") if user_id == label and confidence > 70: send_msg(email, phone_number, transaction_id) ##allow_user return "Message Sent" if confidence == 1000 and label == 0: return "no face detected" else: send_msg(email, phone_number, transaction_id) return "Face not Matched" else: send_msg(email, phone_number, transaction_id) return "Message Sent"
def login_module(): player_name = input("input your name:\n") user_exist = database.check_username_in_database(player_name) if (user_exist): user_name, user_password, level, experience = database.get_user_info( player_name) while (input("Please enter your password:"******"Wrong password! Please Try again!") player = Player(user_name, user_password, experience, level) database.sync_from_db(player) database.active_user(player_name) print("\nWelcome back! Login completed.\n") else: password = input("Welcome new player! Please create your password:"******"Poke Ball")) player.bag.add_item(Potion("Potion")) database.active_user(player_name) print("Welcome! You will start a new journey.") print("You are given 10 Poke Balls and 10 Potions as starting items.") return player
def weixin(): # parse xml to dict obj xml = eT.fromstring(request.data) msg = dict() for ele in list(xml): msg[ele.tag] = ele.text # subscribe or unsubscribe if 'Event' in msg.keys(): return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=WELCOME_TEXT ) # normal command ask = msg['Content'] if ask == 'user': # prompt user to set their sno and password return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=LOGIN_TEXT ) elif ask == 'login': # prompt user to login check = check_user_status(msg) if check['status'] != 'success': return check['response'] else: jwxt = check['instance'] db.set_session_id(msg['FromUserName'], jwxt.cookies['JSESSIONID']) return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=u'已尝试登陆' ) elif re.match(r'^\d+#.+$', ask): # set sno and password sno, password = ask[:ask.find('#')], ask[ask.find('#') + 1:] user_info = db.get_user_info(msg['FromUserName']) if user_info: db.update_user(msg['FromUserName'], sno, password) else: db.create_user(msg['FromUserName'], sno, password) return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=u'创建成功' if not user_info else u'修改成功' ) elif ask in [str(i) for i in range(10)]: # query course from day 0-7, 0 stand for all, 1-7 stand for Monday to Sunday check = check_user_session(msg) if check['status'] != 'success': return check['response'] else: jwxt = check['instance'] try: # get today or tomorrow course (ask = 8, ask = 9) if ask == '8': ask = str(date.today().weekday() + 1) elif ask == '9': ask = str(date.today().weekday() + 2) course_list = jwxt.get_course_list(CURRENT_XND, CURRENT_XQ) course_list.sort(key=lambda x: int(x['day']) * 100 + int(x['start_time'])) output_list = [] for course in [course for course in course_list if ask == '0' or course['day'] == int(ask)]: course['start_time'] = COURSE_START_TIME[int(course['start_time']) - 1] course['end_time'] = COURSE_END_TIME[int(course['end_time']) - 1] course['date'] = WEEK_TIME[int(course['day']) - 1] output = u'{course_name}\n{date} {start_time}-{end_time}\n{location}{duration}'.format(**course) output_list.append(output) if not output_list: output_list.append(u'此期间没有课程') return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=('\n' + '-' * 20 + '\n').join(output_list) ) except: return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=u'会话过期, 请重新输入 login 命令登陆' ) elif re.match(r'^(cj#)(\d+#\d+)$', ask): # query score by xnd(year-year+1) and xq[0(all), 1, 2, 3] check = check_user_session(msg) if check['status'] != 'success': return check['response'] else: jwxt = check['instance'] try: tmp = ask.split('#') xnd, xq = u'{}-{}'.format(int(tmp[1]), int(tmp[1]) + 1), tmp[2] if xq in ['0', '1', '2', '3']: if xq == '0': score_list = reduce(lambda x, y: x + y, [jwxt.get_score_list(xnd, str(i)) for i in range(1, 4)]) else: score_list = jwxt.get_score_list(xnd, xq) output_list = [] for score in score_list: if len(score.get('jxbpm', '')) > 1: output = u'{kcmc}\n成绩: {zpcj}\n排名: {jxbpm}'.format(**score) else: output = u'{kcmc}\n成绩: {zpcj}'.format(**score) output_list.append(output) if not output_list: output_list.append(u'此期间没有成绩') return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=('\n' + '-' * 20 + '\n').join(output_list) ) else: return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=u'请输入正确的查询格式' ) except: return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=u'会话过期, 请重新输入 login 命令登陆' ) elif re.match(r'^gpa(#\d+#\d+)?$', ask): # query gpa by xnd(year-year+1) and xq[0(all), 1, 2, 3] or all gpa check = check_user_session(msg) if check['status'] != 'success': return check['response'] else: jwxt = check['instance'] try: output_list = [] tmp = ask.split('#') if len(tmp) == 1: gpa_list = jwxt.get_all_gpa() else: xnd, xq = '{}-{}'.format(int(tmp[1]), int(tmp[1]) + 1), tmp[2] if xq not in ['1', '2', '3']: return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=u'请输入正确的查询格式' ) gpa_list = jwxt.get_gpa(xnd, xq) for gpa in gpa_list: output = u'{oneColumn}: {twoColumn}'.format(**gpa) output_list.append(output) if not output_list: output_list.append(u'此期间没有绩点') return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content='\n'.join(output_list) ) except: return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=u'会话过期, 请重新输入 login 命令登陆' ) elif ask == 'credit': check = check_user_session(msg) if check['status'] != 'success': return check['response'] else: jwxt = check['instance'] count = 3 while not jwxt.tno and count >= 0: count -= 1 jwxt.get_info() try: output_list = [u'已获得的学分:'] for credit in jwxt.get_credit(): output = u'{oneColumn}: {twoColumn}'.format(**credit) output_list.append(output) output_list.append(u'-' * 20) output_list.append(u'毕业所需学分:') for credit in jwxt.get_total_credit(): output = u'{oneColumn}: {twoColumn}'.format(**credit) output_list.append(output) return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content='\n'.join(output_list) ) except: return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=u'会话过期, 请重新输入 login 命令登陆' ) else: # prompt user help information return weixin_response( from_user_name=msg['ToUserName'], to_user_name=msg['FromUserName'], content=HELP_TEXT )
def get_user_info(self): return database.get_user_info(self.user_id)