コード例 #1
0
ファイル: routes.py プロジェクト: mickremedi/mikeyblog
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 + "Mikey",
                    email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congradulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
コード例 #2
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(name=form.name.data, pwd=form.pwd.data)
        # 获取该用户下的图片
        user.pic = files.file_save(form)
        try:
            db.session.add(user)
            db.session.commit()
        except Exception as e:
            msg = "未知错误{}".format(e)
            db.session.rollback()
            abort(500, msg)
        return redirect(url_for("first.login"))
    return render_template("register.html", form=form)
コード例 #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        worker = Worker(username=form.username.data,
                        email=form.email.data,
                        password=hashed_password)
        db.session.add(worker)
        db.session.commit()
        flash('Your account has been created! You are now able to log in',
              'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
コード例 #4
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            password=form.password.data).decode(encoding='utf-8')
        user = User(
            firstname=form.firstname.data,
            lastname=form.lastname.data,
            username=form.username.data,
            email=form.email.data,
            password=hashed_password
        )
        db.session.add(user)
        db.session.commit()
        flash(message="ثبت نام شما با موفقیت انجام شد!", category='success')
        return redirect(location=url_for(endpoint='home'))

    return render_template(template_name_or_list='register.html', form=form)
コード例 #5
0
def add_users():
    if not current_user.isAdmin: abort(403)
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            flash(
                f"This email is already registered. Please try with another email id",
                "info")
        else:
            password = secrets.token_hex(8)
            hashed_password = bcrypt.generate_password_hash(password)
            user = User(first_name=form.first_name.data,
                        last_name=form.last_name.data,
                        email=form.email.data,
                        password=hashed_password)
            db.session.add(user)
            db.session.commit()
            flash(f"User Added", "success")
            send_create_user_email(user, password)
            return redirect(url_for('display_users'))
    return render_template('register.html', title='Register', form=form)
コード例 #6
0
def register():
    """ Get data for the recent activity sidebar (in base.html) """
    recent = utils.get_recent_activity()
    """ If user is logged in, these routes are unnecessary and so redirect to home page"""
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    """ Instantiate form """
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    bio=form.bio.data,
                    location=form.location.data,
                    level=form.level.data,
                    password=form.password.data)
        user.add_to_db()
        flash(f'Account created for {form.username.data}! You can now log in.',
              'success')
        return redirect(url_for('login'))
    return render_template('register.html',
                           title='Register',
                           form=form,
                           recent=recent)
コード例 #7
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        flash(f'Account created for {form.username.data}!', 'success')
        return redirect(url_for('home'))
    return render_template('register.html', title='Register', form=form)