Esempio n. 1
0
def register():

    if not app.config.get('ALLOW_REGISTRATIONS'):
        abort(404)

    form = NewUserForm()

    if form.validate_on_submit():

        try:
            exists = User.query.filter(User.email == form.email.data).first()

            if exists:
                flash(gettext('Email address already registered'))
            else:
                user = User(
                    login=form.login.data,
                    email=form.email.data,
                    password = hash_password(form.login.data, form.password.data),
                    active = ACCOUNT_DISABLED
                )

                user.first_name = form.first_name.data
                user.last_name = form.last_name.data

                user.locale = str(get_locale())
                user.timezone = str(get_timezone())

                db.session.add(user)
                db.session.commit()

                # Send email
                sent = send_email(
                    gettext('Welcome to %(appname)s', appname = app.config.get('APP_TITLE')),
                    app.config.get('MAIL_SENDER'),
                    [form.email.data],
                    render_template('users/mail_register.txt', user=user),
                    render_template('users/mail_register.html', user=user),
                )

                if sent:
                    flash(gettext('Account created successfully. Please check your email for instructions on activating your account'))
                else:
                    flash(gettext('Account created successfully but there were server-side errors while sending the email activation code. Your account needs to be manually activated.'))

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

        except OperationalError:
            if app.config.get('DEBUG'):
                flash(gettext('Error creating user. Database not set'))
                return redirect(url_for('users.login'))
            else:
                abort(500)

    return render_template('users/register.html', form=form, hide_sidebar=True, hide_header=True, class_body='bg-black', class_html ='bg-black')
Esempio n. 2
0
def add():

    if not current_user.is_admin:
        abort(401)

    form = NewUserForm()

    if form.validate_on_submit():

        user = User(login=form.login.data,
                    email=form.email.data,
                    password=hash_password(form.login.data,
                                           form.password.data))

        user.active = form.active.data
        user.account_type = form.account_type.data

        user.locale = form.locale.data
        user.timezone = form.timezone.data

        user.first_name = form.first_name.data
        user.last_name = form.last_name.data

        db.session.add(user)
        db.session.commit()

        flash(gettext(u'User added successfully'))

        return redirect(url_for('users.index'))
    else:
        form.timezone.data = str(get_timezone())
        form.locale.data = str(get_locale())

    return render_template('users/new.html', form=form)
Esempio n. 3
0
def add():

    if not current_user.is_admin:
        abort(401)

    form = NewUserForm()

    if form.validate_on_submit():

        user = User(
            login=form.login.data,
            email=form.email.data,
            password = hash_password(form.login.data, form.password.data)
        )

        user.active = form.active.data
        user.account_type = form.account_type.data

        user.locale = form.locale.data
        user.timezone = form.timezone.data

        user.first_name = form.first_name.data
        user.last_name = form.last_name.data

        db.session.add(user)
        db.session.commit()

        flash(gettext(u'User added successfully'))

        return redirect(url_for('users.index'))
    else:
        form.timezone.data = str(get_timezone())
        form.locale.data = str(get_locale())

    return render_template('users/new.html', form=form)
Esempio n. 4
0
def register():

    if not app.config.get('ALLOW_REGISTRATIONS'):
        abort(404)

    form = NewUserForm()

    if form.validate_on_submit():

        try:
            exists = User.query.filter(User.email == form.email.data).first()

            if exists:
                flash(gettext('Email address already registered'))
            else:
                user = User(login=form.login.data,
                            email=form.email.data,
                            password=hash_password(form.login.data,
                                                   form.password.data),
                            active=ACCOUNT_DISABLED)

                user.first_name = form.first_name.data
                user.last_name = form.last_name.data

                user.locale = str(get_locale())
                user.timezone = str(get_timezone())

                db.session.add(user)
                db.session.commit()

                # Send email
                sent = send_email(
                    gettext('Welcome to %(appname)s',
                            appname=app.config.get('APP_TITLE')),
                    app.config.get('MAIL_SENDER'),
                    [form.email.data],
                    render_template('users/mail_register.txt', user=user),
                    render_template('users/mail_register.html', user=user),
                )

                if sent:
                    flash(
                        gettext(
                            'Account created successfully. Please check your email for instructions on activating your account'
                        ))
                else:
                    flash(
                        gettext(
                            'Account created successfully but there were server-side errors while sending the email activation code. Your account needs to be manually activated.'
                        ))

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

        except OperationalError:
            if app.config.get('DEBUG'):
                flash(gettext('Error creating user. Database not set'))
                return redirect(url_for('users.login'))
            else:
                abort(500)

    return render_template('users/register.html',
                           form=form,
                           hide_sidebar=True,
                           hide_header=True,
                           class_body='bg-black',
                           class_html='bg-black')