def dosignup(): # try: input_name = request.form['input_name'] input_email = request.form['input_email'] input_password = request.form['input_password'] if input_name and input_email and input_password: hashed_password = generate_password_hash(input_password) user = functions.get_user_info(input_email) if user is None: functions.sign_up_user(input_name, input_email, hashed_password) user = functions.get_user_info(input_email) global user_id user_id = str(user['user_id']) global user_name user_name = user['name'] session[user_id] = True flash(functions.get_flash_message("signup")) return redirect(url_for('index')) else: flash(functions.get_flash_message("email_exists")) else: flash(functions.get_flash_message("empty_fields")) return redirect(url_for('signup'))
def run(config): # TODO: 减少对 config.json 的调用次数,导入一次就够了 functions.schedule_run(config) token, login_response = functions.get_token(config) if token: userinfo = functions.get_user_info(token) index = 0 date = functions.get_date("today") seats = functions.search_seats(token, config["room"], date) while seats is not False and index < len(seats): response = functions.post_data(seats, config, token, index) status = response[u"status"] index = index + 1 time.sleep(random.uniform(0.1, 0.5)) if status == u"fail": print "\n--------------Oops! failed!---------------\n" print "\n------------" + response[u'message'] + "-------------" break elif status == u"success": print "\n-------------Yeah! it's done!-------------\n" break # TODO: 将所有除了success和该座位已被预约以外的status设置为返回status并break # TODO: 调整send_mail参数 functions.send_mail(config, response[u'message']) else: response = None return userinfo, response
def dologin(): try: input_email = request.form['input_email'] input_password = request.form['input_password'] if input_email and input_password: user = functions.get_user_info(input_email) if user is None: flash(functions.get_flash_message("bad_login")) return redirect(url_for('login')) password = user['password'] if check_password_hash(password, input_password): # login_user(unicode(user_id)) global user_id user_id = str(user['user_id']) global user_name user_name = str(user['name']) session[user_id] = True session[user_name] = True flash(functions.get_flash_message("new_login")) return redirect(url_for('index')) else: flash(functions.get_flash_message("bad_login")) else: flash(functions.get_flash_message("empty_fields")) return redirect(url_for('login')) except Exception as e: print e flash(functions.get_flash_message("login_error")) return redirect(url_for('login'))