Beispiel #1
0
    def register_view(self):
        form = RegistrationForm(request.form)
        if helpers.validate_form_on_submit(form):
            user = User()

            form.populate_obj(user)
            # we hash the users password to avoid saving it as plaintext in the db,
            # remove to use plain text:
            user.password = generate_password_hash(form.password.data)

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

            login.login_user(user)
            return redirect(url_for('.index'))
        link = '<p>Already have an account? <a href="' + url_for('.login_view') + '">Click here to log in.</a></p>'
        self._template_args['form'] = form
        self._template_args['link'] = link
        return super(MyAdminIndexView, self).index()
Beispiel #2
0
    def register_view(self):
        print("route-register-admin");
        form = RegistrationForm(request.form)
        
        if helpers.validate_form_on_submit(form):
            Session = sessionmaker(bind=pg.obtem_engine())
            session = Session()
            usuario = tables.Usuario()
            form.populate_obj(usuario)
            usuario.senha = generate_password_hash(form.senha.data)
            session.add(usuario)
            session.commit()
            login.login_user(usuario)
            return redirect(url_for('.index'))

        link = '<p>ja tem uma conta? <a href="' + url_for('.login_view') + '">acesse</a></p>'
        self._template_args['form'] = form
        self._template_args['link'] = link
        return super(MyAdminIndexView, self).index()