def userRegist(): if current_user.is_authenticated: flash('Please logout before registe a new account') next = request.args.get('next') if next: return redirect(next) return redirect(url_for('index.indexPage')) else: form = RegisterForm() if form.validate_on_submit(): user = User() user.username = form.username.data user.email = form.email.data user.password = generate_password_hash(form.password.data) user.sex = form.sex.data user.age = form.age.data user.school = form.school.data user.location = form.location.data user.createdTime = date.today() user.isactive = True user.isauthenticated = False print(user.username) user.save() login_user(user) return redirect(url_for('index.indexPage')) return render_template('login/registe.html', form=form)
def userRegistWithCode(code): ''' 用户注册,有无邀请码来区分不同的组册情况 ''' if current_user.is_authenticated: flash('Please logout before registe a new account') next = request.args.get('next') if next: return redirect(next) return redirect(url_for('index.indexPage')) else: form = RegisterForm() if code: form.inviteCode.data = code if form.validate_on_submit(): user = User() user.username = form.username.data user.email = form.email.data user.password = generate_password_hash(form.password.data) user.sex = form.sex.data user.age = form.age.data user.school = form.school.data user.location = form.location.data user.createdTime = date.today() user.isactive = True user.isauthenticated = False uniqueCode = form.inviteCode.data if uniqueCode: if Pair.query(bson.objectid.ObjectId(str(code))): flash('This invite code has been used') return redirect(url_for('login.userRegist')) user.save() login_user(user) if user.sex == 'male': try: pair = Pair() pair.boy = user pair.girl = User.query( bson.objectid.ObjectId(str(code))) pair.save() except Exception as e: print(str(e)) else: try: pair = Pair() pair.girl = user pair.boy = User.query( bson.objectid.ObjectId(str(code))) pair.save() except Exception as e: print(str(e)) return redirect(url_for('index.indexPage')) print(user.username) user.save() login_user(user) return redirect(url_for('index.indexPage')) return render_template('login/registe.html', form=form)