Exemple #1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        #hash the value of the password and add new User class's instance 
        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)
        #add the newly created user instance to the db
        db.session.add(user)
        db.session.commit()
        flash('Account created for {}'.format(form.username.data), 'success')
        return redirect(url_for('users.login'))
    return render_template("register.html", title = 'Register', form=form)
Exemple #2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        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)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created, you can now login', 'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Join Today', form=form)
Exemple #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        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)
        db.session.add(user)
        db.session.commit()
        flash('Váš účet bol vytvorený! Teraz sa môžete prihlásiť', 'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Registrácia', form=form)
def register():
    if current_user.is_authenticated:
        return redirect('/')
    form = RegistrationForm()
    if form.validate_on_submit():
        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)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You can now login.', 'success')
        return redirect('/login')
    return render_template('register.html', title='Register', form=form)
Exemple #5
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        # Saving and getting name for picture
        picture_name = get_and_save_picture(form.picture.data)
        # Generating Hash Password
        hash_password = bcrypt.generate_password_hash(form.password.data)
        Insert_Data(form.userName.data, form.email.data, hash_password,
                    picture_name)
        flash(
            f"{form.userName.data} with {form.email.data} Added successfully !!! ",
            "success")
        return redirect(url_for('users.login'))

    return render_template("register.html", title="Register", form=form)
Exemple #6
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        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)
        db.session.add(user)
        db.session.commit()
        flash('Conta criada com sucesso! Você já pode efetuar o login',
              'success')

        return redirect(url_for('users.login'))

    return render_template('register.html', title='Cadastrar', form=form)
Exemple #7
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))

    form = RegistrationForm()
    # and form.validate()  # envoyer un message flash de succes et retour a la page d'accueil
    if request.method == 'POST' and form.validate_on_submit():
        password_hash = bcrypt.generate_password_hash(
            form.password.data).decode('utf8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=password_hash)
        db.session.add(user)
        db.session.commit()
        flash(f' Welcome you are registered in!', 'is-success')
        return redirect(url_for('users.login'))
    return render_template('pages/register.html', title='Register', form=form)
Exemple #8
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('core.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = Account(email=form.email.data,
                       login=form.login.data,
                       password=form.password.data)
        data_login = user.login
        data_email = user.email
        data_password = user.password
        db.engine.execute(
            "INSERT INTO accounts(login, email, password) VALUES(%s, %s, %s)",
            data_login, data_email, data_password)
        db.session.commit()
        flash('Thanks for registering! Now you can login!')
        return redirect(url_for('users.login'))
    return render_template('register.html', form=form)
def register():
    form = RegistrationForm()
    PatientFinder = ResourceFinder.build('Patient', smart.server)

    if form.validate_on_submit():
        patient = PatientFinder.find_by_identifier(
            form.identifier_system.data,
            form.identifier_value.data,
            first=True
        )

        if not patient:
            flash(f'No patient record found, please check again. If you keep failing the verification, please contact your provider.')

        else:
            check_patient_duplicated = UserModel.query.filter_by(patient_id=patient.id).first()
            check_dob_matched = patient.birthDate.date == form.date_of_birth.data
            check_family_matched = patient.name[0].family == form.family_name.data

            if check_patient_duplicated:
                flash(f'The patient has been registered already.')
            elif not (check_dob_matched or check_family_matched):
                flash(f'No patient record found, please check again. If you keep failing the verification, please contact your provider.')
            else:
                user = UserModel(
                    given_name=patient.name[0].given[0],
                    family_name=form.family_name.data,
                    date_of_birth= form.date_of_birth.data,
                    identifier_system=form.identifier_system.data,
                    identifier_value=form.identifier_value.data,
                    patient_id=patient.id,
                    email=form.email.data,
                    password=form.password.data
                )

                db.session.add(user)
                db.session.commit()
                flash(f'Welcome {patient.name[0].given[0]}! Please login now.')
                return redirect(url_for('users_bp.login'))

    return render_template('register.html', form=form)
Exemple #10
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('posts.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        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)
        db.session.add(user)
        db.session.commit()

        user_id = User.query.filter_by(email=form.email.data).first()
        user_info = User_info(user_id=user.id,
                              food_preference=form.food_preference.data,
                              semester=form.semester.data,
                              gender=form.gender.data)
        db.session.add(user_info)
        db.session.commit()

        return redirect(url_for('user.login'))
    return render_template('register.html', form=form)
Exemple #11
0
def register():

    form = RegistrationForm()
    if form.validate_on_submit():
        if form.password.data.startswith("a#"):
            role = ROLE_ADMIN
        elif form.password.data.startswith("i#"):
            role = ROLE_INSTRUCTOR
        else:
            role = ROLE_STUDENT

        # if a user with this username already exists, return error message
        if not User.query.filter_by(username=form.username.data).first():
            user = User(username=form.username.data,
                        password=form.password.data,
                        role=role)
            user.add()
            return redirect(url_for('index'))

        else:
            flash("A user with same username already exists!")

    return render_template('register.html', form=form)
Exemple #12
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    
    form = RegistrationForm()
    if form.validate_on_submit():
        admin_key = False
        if form.admin.data and current_app.config['INVITE_KEY'] == form.invite_key.data:
            with current_app.open_resource('admin_codes.txt', 'r') as f:
                lines = f.readlines()
                for line in lines:
                    if form.admin_key.data == line.rstrip():
                        admin_key = True
            if admin_key:
                with open('./admin_codes.txt', 'w') as f:
                    for line in lines:
                        if line.rstrip() != form.admin_key.data:
                            f.write(line)
                hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
                user = User(username=form.username.data, email=form.email.data.lower(), password=hashed_password, biography="Default Bio", admin=True)
                db.session.add(user)
                db.session.commit()
                flash(f'Your admin account has been created! You are now able to log in', 'success')
                return redirect(url_for('users.login'))
            else:
                flash("Admin key incorrect!", 'danger')
        elif current_app.config['INVITE_KEY'] == form.invite_key.data:
            hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
            user = User(username=form.username.data, email=form.email.data.lower(), password=hashed_password, biography="Default Bio")
            db.session.add(user)
            db.session.commit()
            flash(f'Your account has been created! You are now able to log in', 'success')
            return redirect(url_for('users.login'))
        else:
            flash('Invite Key Incorrect! (Access is limited to club members) ', 'danger')
    return render_template('register.html', title='Register', form=form)
Exemple #13
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('users.login'))

    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
                            form.password.data).decode('utf-8')
        user = User(user_firstname = form.first_name.data, 
                    user_lastname = form.last_name.data, 
                    user_email = form.email.data,
                    user_password = hashed_password,
                    user_location = form.location.data,
                    user_organisation = form.organisation.data,
                    user_affilication = form.afflication.data,
                    user_receive_notification = form.receive_notification.data,
                    user_private = form.private_account.data)
        db.session.add(user)
        db.session.commit()

        ##flash(f'Your account has been created!', 'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', 
                            form=form)
Exemple #14
0
def register():
    if current_user.is_authenticated:  #if the user is already logged in
        return redirect(
            url_for("main.home"))  #redirect the user back to the home page

    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data.encode("utf-8")).decode("utf-8")
        user = User(
            username=form.username.data,
            email=form.email.data,
            password=hashed_password,
            bio="",
            gender="",
            role="Member"
        )  #pass in the UTF-8 hashed password, not the plain text nor binary
        db.session.add(user)
        db.session.commit()

        flash(f"Account created for {form.username.data}!",
              "success")  #bootstrap class category: success, danger, etc
        return redirect(url_for("users.login"))
    return render_template("register.html", title="Register", form=form)