Пример #1
0
def register():
    # 用户已登录
    if current_user.is_authenticated:
        return redirect(url_for('home.index'))
    # 用户未登录
    else:
        error = None
        form = RegistrationForm()
        if request.method == 'POST':
            if form.validate_on_submit():
                new_user = User(
                    username=form.username.data,
                    email=form.email.data,
                    password=form.password.data,
                )
                db.session.add(new_user)
                db.session.commit()
                flash('恭喜, 您已成功注册, 请登录')
                return redirect(url_for('.login'))
            else:
                return render_template('user/register.html',
                                       form=form,
                                       error=error)
        else:
            return render_template('user/register.html',
                                   form=form,
                                   error=error)
Пример #2
0
def register():
    if current_user.is_authenticated:
        flash("You already logged in", "info")
        return redirect(url_for("home"))
    form = RegistrationForm()
    if request.method == "POST" and form.validate():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash(f"Account created for {form.username.data}! Try to log in!",
              "success")
        return redirect(url_for('login'))
    return render_template("register.html", title="Register", form=form)
def register():

    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()

    if form.validate_on_submit():
        user = User(username=form.username.data,
                    name=form.name.data,
                    surname=form.surname.data,
                    email=form.email.data,
                    address=form.address.data,
                    role_id=2)

        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash("GREAT your are now registered user!")
        return redirect(url_for('login'))

    return render_template('User/register.html', title='Register', form=form)
Пример #4
0
def register(creator_id, token):
    '''auth.register(creator_id, token)'''
    if current_user.is_authenticated:
        logout_user()
    creator = User.query.get_or_404(creator_id)
    if not creator.created or creator.deleted or not creator.register_user(token):
        flash('用户注册页面已过期', category='error')
        return redirect(request.args.get('next') or url_for('manage.student'))
    form = RegistrationForm()
    if form.validate_on_submit() and creator.register_user(token):
        user = User(
            email=form.email.data.strip().lower(),
            role_id=int(form.role.data),
            password=form.id_number.data.strip().upper()[-6:],
            name=form.name.data.strip(),
            id_type_id=int(form.id_type.data),
            id_number=form.id_number.data.strip().upper(),
            gender_id=int(form.gender.data),
            birthdate=form.birthdate.data,
            mobile=form.mobile.data,
            wechat=form.wechat.data,
            qq=form.qq.data,
            address=form.address.data,
            emergency_contact_name=form.emergency_contact_name.data,
            emergency_contact_relationship_id=int(form.emergency_contact_relationship.data),
            emergency_contact_mobile=form.emergency_contact_mobile.data,
            worked_in_same_field=form.worked_in_same_field.data,
            deformity=form.deformity.data,
            application_specialty=form.application_specialty.data,
            application_degree=form.application_degree.data,
            application_country=form.application_country.data,
            application_rank=form.application_rank.data,
            application_agency=form.application_agency.data
        )
        db.session.add(user)
        db.session.commit()
        # education
        if form.high_school.data:
            user.add_education_record(
                education_type=EducationType.query.filter_by(name='高中').first(),
                school=form.high_school.data,
                year=form.high_school_year.data
            )
        if form.bachelor_school.data and form.bachelor_school.data != '无':
            user.add_education_record(
                education_type=EducationType.query.filter_by(name='本科').first(),
                school=form.bachelor_school.data,
                major=form.bachelor_major.data,
                gpa=form.bachelor_gpa.data,
                full_gpa=form.bachelor_full_gpa.data,
                year=form.bachelor_year.data
            )
            if '北京大学' in form.bachelor_school.data:
                user.add_tag(tag=Tag.query.filter_by(name='北大').first())
            elif '清华' in form.bachelor_school.data:
                user.add_tag(tag=Tag.query.filter_by(name='清华').first())
            elif '北京邮电大学' in form.bachelor_school.data:
                user.add_tag(tag=Tag.query.filter_by(name='北邮').first())
            if form.bachelor_full_gpa.data and \
                form.bachelor_gpa.data and \
                float(form.bachelor_full_gpa.data) == 100 and \
                float(form.bachelor_gpa.data) >= 90:
                user.add_tag(tag=Tag.query.filter_by(name='GPA90+').first())
        if form.master_school.data:
            user.add_education_record(
                education_type=EducationType.query.filter_by(name='硕士').first(),
                school=form.master_school.data,
                major=form.master_major.data,
                gpa=form.master_gpa.data,
                full_gpa=form.master_full_gpa.data,
                year=form.master_year.data
            )
            if '北京大学' in form.master_school.data:
                user.add_tag(tag=Tag.query.filter_by(name='北大').first())
            elif '清华' in form.master_school.data:
                user.add_tag(tag=Tag.query.filter_by(name='清华').first())
            elif '北京邮电大学' in form.master_school.data:
                user.add_tag(tag=Tag.query.filter_by(name='北邮').first())
            if form.master_full_gpa.data and \
                form.master_gpa.data and \
                float(form.master_full_gpa.data) == 100 and \
                float(form.master_gpa.data) >= 90:
                user.add_tag(tag=Tag.query.filter_by(name='GPA90+').first())
        if form.doctor_school.data:
            user.add_education_record(
                education_type=EducationType.query.filter_by(name='博士').first(),
                school=form.doctor_school.data,
                major=form.doctor_major.data,
                gpa=form.doctor_gpa.data,
                full_gpa=form.doctor_full_gpa.data,
                year=form.doctor_year.data
            )
            if '北京大学' in form.doctor_school.data:
                user.add_tag(tag=Tag.query.filter_by(name='北大').first())
            elif '清华' in form.doctor_school.data:
                user.add_tag(tag=Tag.query.filter_by(name='清华').first())
            elif '北京邮电大学' in form.doctor_school.data:
                user.add_tag(tag=Tag.query.filter_by(name='北邮').first())
            if form.doctor_full_gpa.data and \
                form.doctor_gpa.data and \
                float(form.doctor_full_gpa.data) == 100 and \
                float(form.doctor_gpa.data) >= 90:
                user.add_tag(tag=Tag.query.filter_by(name='GPA90+').first())
        # employment
        if form.employer_1.data:
            user.add_employment_record(
                employer=form.employer_1.data,
                position=form.position_1.data,
                year=form.job_year_1.data
            )
        if form.employer_2.data:
            user.add_employment_record(
                employer=form.employer_2.data,
                position=form.position_2.data,
                year=form.job_year_2.data
            )
        # scores
        if form.cee_total.data and int(form.cee_total.data):
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='高考总分').first(),
                score=form.cee_total.data,
                full_score=form.cee_total_full.data
            )
        if form.cee_math.data and int(form.cee_math.data):
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='高考数学').first(),
                score=form.cee_math.data,
                full_score=form.cee_math_full.data
            )
            if int(form.cee_math_full.data) == 150 and int(form.cee_math.data) >= 135:
                user.add_tag(tag=Tag.query.filter_by(name='高考数学135+').first())
        if form.cee_english.data and int(form.cee_english.data):
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='高考英语').first(),
                score=form.cee_english.data,
                full_score=form.cee_english_full.data
            )
        if form.cet_4.data:
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='大学英语四级').first(),
                score=form.cet_4.data
            )
        if form.cet_6.data:
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='大学英语六级').first(),
                score=form.cet_6.data
            )
            if int(form.cet_6.data) >= 600:
                user.add_tag(tag=Tag.query.filter_by(name='六级600+').first())
        if form.tem_4.data:
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='专业英语四级').first(),
                score=form.tem_4.data
            )
        if form.tem_8.data:
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='专业英语八级').first(),
                score=form.tem_8.data
            )
        # competition scores
        has_competition_score = False
        if form.math_competition.data:
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='数学竞赛').first(),
                remark=form.math_competition.data
            )
            has_competition_score = True
        if form.physics_competition.data:
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='物理竞赛').first(),
                remark=form.physics_competition.data
            )
            has_competition_score = True
        if form.chemistry_competition.data:
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='化学竞赛').first(),
                remark=form.chemistry_competition.data
            )
            has_competition_score = True
        if form.biology_competition.data:
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='生物竞赛').first(),
                remark=form.biology_competition.data
            )
            has_competition_score = True
        if form.computer_competition.data:
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='计算机竞赛').first(),
                remark=form.computer_competition.data
            )
            has_competition_score = True
        if form.science_competition.data:
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='科技竞赛').first(),
                remark=form.science_competition.data
            )
            has_competition_score = True
        if form.english_competition.data:
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='英语竞赛').first(),
                remark=form.english_competition.data
            )
            has_competition_score = True
        if has_competition_score:
            user.add_tag(tag=Tag.query.filter_by(name='竞赛').first())
        # other score
        if form.other_score.data:
            user.add_score_record(
                score_type=ScoreType.query.filter_by(name='其它').first(),
                remark=form.other_score.data
            )
        # TOEFL score
        if form.toefl_total.data:
            test_id = None
            if form.toefl_test_date.data and int(form.toefl_test_date.data):
                test_id = int(form.toefl_test_date.data)
            toefl_test_score = TOEFLTestScore(
                user_id=user.id,
                test_id=test_id,
                label_id=ScoreLabel.query.filter_by(name='TOEFL 初始').first().id,
                total_score=form.toefl_total.data,
                reading_score=form.toefl_reading.data,
                listening_score=form.toefl_listening.data,
                speaking_score=form.toefl_speaking.data,
                writing_score=form.toefl_writing.data,
                registered=True,
                modified_by_id=creator.id
            )
            db.session.add(toefl_test_score)
        # registration
        for purpose_type_id in form.purposes.data:
            user.add_purpose(purpose_type=PurposeType.query.get(int(purpose_type_id)))
        if form.other_purpose.data:
            user.add_purpose(
                purpose_type=PurposeType.query.filter_by(name='其它').first(),
                remark=form.other_purpose.data
            )
        for referrer_type_id in form.referrers.data:
            user.add_referrer(referrer_type=ReferrerType.query.get(int(referrer_type_id)))
        if form.other_referrer.data:
            user.add_referrer(
                referrer_type=ReferrerType.query.filter_by(name='其它').first(),
                remark=form.other_referrer.data
            )
        if form.inviter_email.data:
            inviter = User.query.filter_by(
                email=form.inviter_email.data.strip().lower(),
                created=True,
                deleted=False
            ).first()
            if inviter is not None:
                inviter.invite_user(user=user, grant_credit=True)
            else:
                flash('需联系工作人员进行核对云社区推荐人邮箱:{}'\
                    .format(form.inviter_email.data.strip().lower()), category='error')
        if form.partner.data:
            partner = Partner.query.filter_by(name=form.partner.data).first()
            if partner is not None:
                partner.refer_user(user=user, commission=partner.default_commission)
        db.session.commit()
        flash('完成注册,请联系工作人员进行资料审核', category='success')
        add_user_log(user=user, event='注册账户', category='auth')
        return redirect(url_for(
            'manage.confirm_user_registration',
            id=user.id,
            next=request.args.get('next')
        ))
    return minify(render_template(
        'auth/register.html',
        form=form,
        creator=creator,
        token=token
    ))
Пример #5
0
def register():
    form = RegistrationForm()
    if request.method == "POST" and form.validate():
        flash(f"Account created for {form.username.data}!", "success")
        return redirect(url_for('home'))
    return render_template("register.html", title="Register", form=form)