def validate(): email = request.args.get('email') vcode = request.args.get('vcode') code = md5(app.config.get('SECRET_KEY') + email) user = User.query.filter_by(email=email).first() if user is None: flash('Validate failed!') return redirect(url_for('login')) if vcode != code: flash('Validate failed! Code error!') return redirect(url_for('login')) if user.service_port == 0: # find a idle port prot_max = app.config.get('MAX_SERVICE_PORT') max_service_port = db.session.query(db.func.max(User.service_port)).scalar() if max_service_port == 0: user.service_port = app.config.get('MIN_SERVICE_PORT') elif max_service_port >= prot_max: flash('There is no idle port. Contact us!') return redirect(url_for('login')) user.service_port = max_service_port + 1 user.transfer_enable = app.config.get('USER_INIT_TRANSFER') user.service_enable = 1 user.service_switch = 1 db.session.commit() flash('Validate success. Please login!') return redirect(url_for('login'))
def validate(): email = request.args.get('email') vcode = request.args.get('vcode') code = md5(app.config.get('SECRET_KEY') + email) user = User.query.filter_by(email=email).first() if user is None: flash('Validate failed!') return redirect(url_for('login')) if vcode != code: flash('Validate failed! Code error!') return redirect(url_for('login')) if user.service_port == 0: # find a idle port prot_max = app.config.get('MAX_SERVICE_PORT') max_service_port = db.session.query(db.func.max( User.service_port)).scalar() if max_service_port == 0: user.service_port = app.config.get('MIN_SERVICE_PORT') elif max_service_port >= prot_max: flash('There is no idle port. Contact us!') return redirect(url_for('login')) user.service_port = max_service_port + 1 user.transfer_enable = app.config.get('USER_INIT_TRANSFER') user.service_enable = 1 user.service_switch = 1 db.session.commit() flash('Validate success. Please login!') return redirect(url_for('login'))
def sign(): # valid username and password email = request.form['email'] if re.match('\S+@\S+\.\S+', email) is None: flash('Invalid email address.') return redirect(url_for('login')) password = request.form['password'] if re.match('[0-9a-f]{32}', password) is None: flash('Invalid password.') return redirect(url_for('login')) user = User.query.filter_by(email=email).first() if user is not None: flash('Email already exist.') return redirect(url_for('login')) try: msg = Message("Account", sender=app.config.get('MAIL_USERNAME'), recipients=[email]) msg.body = app.config.get('HOST_URL') + "/validate?vcode=%s&email=%s" % \ (md5(app.config.get('SECRET_KEY') + email), email) mail.send(msg) except: import traceback traceback.print_exc() flash('Mail error happend. Contact us!') return redirect(url_for('login')) user = User() user.email = email user.login_pass = password user.service_pass = str(random.randint(1000000, 99999999)) user.transfer_download = 0 user.transfer_upload = 0 user.transfer_enable = 0 user.service_enable = 0 user.service_switch = 0 user.last_service_time = 0 user.last_get_gift_time = 0 user.type = 0 user.service_port = 0 db.session.add(user) flash('Validate email send.') return redirect(url_for('login'))