Ejemplo n.º 1
0
Archivo: auth.py Proyecto: OReznyk/MHA
def signup():
    if current_user.is_authenticated:
        flash('בבקשה תתנתקו לצורך רישום משתמש חדש', 'error')
        return redirect(url_for("views.dashboard"))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pwd = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        # TODO: check permissions: create regular user for all types of permissions
        # if not regular permission ->  flash msg as: user created & send for permission approval
        user = User(email=form.email.data, first_name=form.firstname.data,
                        second_name=form.name.data, birth_date=form.birthdate.data, password=hashed_pwd)
        if form.permissions.data == "נחקר":
            user.permission_confirmation = True
        # Saving user to db
        db.session.add(user)
        g = db.session.query(Gender).filter_by(gender=form.gender.data).first()
        p = Permissions.query.filter_by(permission=form.permissions.data).first()
        g.users.append(user)
        p.users.append(user)
        db.session.commit()
        flash('משתמש נוצר בהצלחה', 'success')
        # TODO: send email verificathion if needed
        # TODO: redirect to verification page/popup?
        return redirect(url_for("auth.login"))

    return render_template('signup.html', form=form)
Ejemplo n.º 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')
        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 are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 3
0
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('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 4
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    registration_form = RegistrationForm()
    if registration_form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            registration_form.password.data).decode('UTF-8')
        new_user = User(username=registration_form.username.data,
                        email=registration_form.email.data,
                        password=hashed_password)
        db.session.add(new_user)
        db.session.commit()
        return redirect(url_for('login'))
    return render_template('sign-up-page.html', form=registration_form)
Ejemplo n.º 5
0
def register():
    print(count)
    if current_user.is_authenticated:
        flash(
            'You are already logged in. Please log out to create a new account.',
            'danger')
        return redirect(url_for('home'))
    form = RegistrationForm()
    title = 'Register'
    if form.validate_on_submit():
        #Generate a hashed-password, and store user + hashed pw in db
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = user_list(username=form.username.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(
            'Account created successfully. You can now log in with your username and password.',
            'success')
        return redirect(url_for('login'))
    return render_template('register.html', title=title, form=form)
Ejemplo n.º 6
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = RegistrationForm()
    if form.validate_on_submit():
        users = getDBData()
        userFoundRow = None
        if users:
            for row in users:
                if row.username.lower() == form.username.data.lower():
                    userFoundRow = row
                    break

        if not userFoundRow:
            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode("utf-8")

            addUser(form.username.data, hashed_password)
            flash("User successfully created!")
            return redirect(url_for("login"))
        flash("The specified household nickname already exists")
    return render_template("register.html", form=form)
Ejemplo n.º 7
0
def register():
    context = global_context()
    if current_user:
        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')
        email = form.email.data
        token = serializer.dumps(email, salt='email-confirmation')
        confirmation_link = url_for('confirm_email',
                                    token=token,
                                    _external=True)
        user_data = {
            'firstname': form.firstname.data,
            'lastname': form.lastname.data,
            'email': form.email.data,
            'password': hashed_password,
            'confirmation_link': confirmation_link,
        }
        user = User(**user_data)
        msg = Message('NBDF Anmeldung - Email bestätigen',
                      sender=app.config['MAIL_USERNAME'],
                      recipients=[email])
        msg.body = f'Willkommen auf der NBDF Seite.\n\nBitte benutze diesen Link um deinen Account zu bestätigen: {confirmation_link.replace("localhost",server_IP)}\n\nBitte antworte nicht direkt auf diese Email.'
        mail.send(msg)
        db.session.add(user)
        db.session.commit()
        flash(
            f'Willkommen {form.firstname.data}, bitte bestätige die Email für deinen Account.',
            'success')
        #context['user_email'] = form.email.data
        return redirect(url_for('login', **context))
    context['form'] = form
    context['title'] = 'Registrieren'
    return render_template('register.html', **context)
Ejemplo n.º 8
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)