示例#1
0
def register_account():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        #also check that account does not exist already
        password = pwd_context.hash(form.password.data)
        try:
            hotp_secret = duo.activate(form.qr_url.data)
            # hotp_secret = 'a85adc3516351791c05ef40bde772c24'
            db.insert_user(form.email.data, password, hotp_secret)
        except UniqueViolationException as e:
            flash(
                "An account with that email already exists. Try another one.")
            return redirect(url_for('register_account'))
        except Exception as e:
            flash(
                "I\'m sorry. Try again later. Let the adminstrator know about the error: {} {}"
                .format(type(e), e))
            return redirect(url_for('register_account'))
        else:
            flash("Thanks for registering.")
            app.logger.debug("Received {} {}:{}".format(
                form.email.data, form.password.data, password))
            return redirect(url_for('generate_passcode'))
    else:
        return render_template('register.html',
                               title='Register New Account',
                               form=form,
                               urls={r: url_for(r)
                                     for r in routes})
示例#2
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')  # hash the user password
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        created_user = form.username.data
        element = created_user.split(".")
        display_name = [n.capitalize() for n in element]
        if len(display_name) == 1:
            flash(
                f'{display_name[0]} - {user.id} account created, please log in',
                'success')
        else:
            flash(
                f'{display_name[0]} {display_name[1]} - {user.id} account created, please log in',
                'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
示例#3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('welcome'))
    form = RegistrationForm()
    if form.validate_on_submit():
        try:
            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            user = User(username=form.username.data,
                        email=form.email.data,
                        password=hashed_password)
            user.set_user_role(form.user_role.data)
            db.session.add(user)
            db.session.commit()
            flash('Your account has been created', 'success')
            user1 = User.query.filter_by(username=form.username.data).first()
            if user1.is_a_coordinator == True:
                return redirect(url_for('coordinator_update'))
            elif user1.is_assuranceboard == True:
                return redirect(url_for('assurance_update'))
            return redirect(url_for('login'))
        except:
            db.session.rollback()
        finally:
            db.session.close()

    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(form.password.data).decode('utf-8')
        user_1=User(username=form.username.data,email=form.email.data,password=hashed_password)
        db.session.add(user_1)
        db.session.commit()
        flash('Your account has been created. You can login now!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html',form=form)
示例#5
0
def index():
    form = RegistrationForm()
    if form.validate_on_submit():
        regForm = Registration(username=form.username.data,email=form.email.data,\
                                    first_name=form.first_name.data,last_name=form.last_name.data,\
                                    company=form.company.data,contact_no=form.contact_no.data)
        db.session.add(regForm)
        db.session.commit()
        flash('Successfully submitted your user')
        return redirect(url_for('index'))
    return render_template('home.html', form=form)
示例#6
0
文件: routes.py 项目: csWendy/TodoApp
def register():
    if current_user.is_authenticated:
        return redirect(url_for('login'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        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('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, college=form.college_name.data, password=hashed_pw)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created successfully','success')
        return redirect(url_for('login'))
    return render_template('register.html',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, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulation, you are a new registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title="Register Now", form=form)
示例#9
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')
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    phone_number=form.phone_number.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created for {form.first_name.data} successfully',
              'success')
        return redirect(url_for('home'))
    return render_template('register.html', title='Sign Up', form=form)
示例#10
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        email = form.email.data
        username = form.username.data
        password = form.password.data
        user = User(email=email, username=username, password=password)
        db.session.add(user)
        db.session.commit()
        login_user(user)
        token = user.generate_confirmation_token()
        user.send_email(user.email,
                        'Confirm Your Account',
                        'email/confirm',
                        token=token)
        flash('验证邮件已发送,请登录邮箱以完成注册')
        return redirect(url_for('auth.login'))

    return render_template('register.html', form=form)
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/login')
        else:
            return redirect('/register/')
    else:
        form = RegistrationForm()
        args = {'form': form}
        return render(request, 'accounts/reg_form.html', args)