Example #1
0
def users_new():
    form = UserAddForm(request.form)

    if form.validate_on_submit():
        user = User()
        form.populate_obj(user)
        user.registered = 'NOW()'
        User.query.add(user)
        flash(messages['added']+' ('+str(user)+')')
        return redirect(url_for('admin.users'))

    return render_template('admin/users_new.html', title=gettext('New - User'),  form=form)
Example #2
0
def users_edit(id_user=None):
    if not id_user:
        id_user = request.args.get('id')

    user = User.get(User.id == id_user)
    if g.user.status == 4:
        form = UserEditFormAdmin(obj=user)
    else:
        form = UserEditForm(obj=user)

    if form.validate_on_submit():
        status = user.status
        form.populate_obj(user)

        # don't allow to change status unless admin.
        if g.user.status != 4:
            user.status = status

        if g.user.status == 4 or g.user.id == user.id:
            user.save()
            flash(messages['updated'] + ' (' + str(user) + ')')

        if g.user.status == 4:
            return redirect(url_for('admin.users'))
        else:
            return redirect(url_for('admin.users_me'))

    return render_template('admin/users_edit.html',
                           title=gettext('Edit - User'),
                           user=user,
                           form=form)
Example #3
0
File: views.py Project: Fy-/FyPress
def users_edit(id_user=None):
    if not id_user:
        id_user = request.args.get('id')

    user = User.get(User.id == id_user)
    if g.user.status == 4:
        form = UserEditFormAdmin(obj=user)
    else:
        form = UserEditForm(obj=user)

    if form.validate_on_submit():
        status = user.status
        form.populate_obj(user)

        # don't allow to change status unless admin.
        if g.user.status != 4:
            user.status = status

        if g.user.status == 4 or g.user.id == user.id:
            user.save()
            flash(messages['updated'] + ' (' + str(user) + ')')

        if g.user.status == 4:
            return redirect(url_for('admin.users'))
        else:
            return redirect(url_for('admin.users_me'))

    return render_template('admin/users_edit.html', title=gettext('Edit - User'), user=user, form=form)
Example #4
0
def init_fypress(login='', email='', passwd=''):
    if not passwd or not email or not login:
        print '*** /!\ Usage: python manager.py --login=name [email protected] --passwd=yourpass'
        return False

    user = User.add(login, email, passwd)
    if user:
        user.status   = 4
        user.nicename = user.login
        User.query.update(user)
        print '*** Added user: '******'*** /!\ Invalid user (Duplicate entry)'

    exist = Folder.query.get(1)
    if not exist:
        folder = Folder()
        folder.name     = 'Uncategorized'
        folder.created  = 'NOW()'
        folder.modified = 'NOW()'
        folder.id       = 1
        folder.guid     = ''
        
        Folder.query.add(folder)
        print '*** Added Folder: '+str(folder)

    options = [
        ['name', 'FyPress Site'],
        ['url',  Config.URL],
        ['slogan', 'Welcome to FyPress'],
        ['theme', 'Nyx']
    ]
    for option in options:
        opt = Option.update(option[0], option[1])
        print '*** Added Option: '+str(opt)
Example #5
0
def init_fypress(login="", email="", passwd=""):
    if not passwd or not email or not login:
        print "*** /!\ Usage: python manager.py --login=name [email protected] --passwd=yourpass"
        return False

    user = User.add(login, email, passwd)
    if user:
        user.status = 4
        user.nicename = user.login
        User.query.update(user)
        print "*** Added user: "******"*** /!\ Invalid user (Duplicate entry)"

    exist = Folder.query.get(1)
    if not exist:
        folder = Folder()
        folder.name = "Uncategorized"
        folder.created = "NOW()"
        folder.modified = "NOW()"
        folder.id = 1
        folder.guid = ""

        Folder.query.add(folder)
        print "*** Added Folder: " + str(folder)

    options = [["name", "FyPress Site"], ["url", Config.URL], ["slogan", "Welcome to FyPress"], ["theme", "Nyx"]]
    for option in options:
        opt = Option.update(option[0], option[1])
        print "*** Added Option: " + str(opt)
Example #6
0
def render_template(template, **kwargs):
    g.user = None
    if session.get('user_id'):
        g.user = User.get(User.id == session['user_id'])

    render = flask_render_template(template, **kwargs)
    if session.get('user_id') and g.user.status >= 4:
        render = render.replace('</html>', '')
        render += admin_render_template('admin/bar.html')
        render += '</html>'

    return render
Example #7
0
File: views.py Project: Fy-/FyPress
def login():
    if 'user_id' in session:
        return redirect('/admin/')

    form = UserLoginForm(request.form, next=request.args.get('next'))

    if form.validate_on_submit():
        login = User.connect(form.data['login'], form.data['password'])
        if login:
            if form.data['next'] != '':
                return redirect(form.data['next'])
            else:
                return redirect('/admin/')
        else:
            pass

    return render_template('admin/login.html', form=form, title=gettext('Please sign in'))
Example #8
0
def login():
    if 'user_id' in session:
        return redirect('/admin/')

    form = UserLoginForm(request.form, next=request.args.get('next'))

    if form.validate_on_submit():
        login = User.connect(form.data['login'], form.data['password'])
        if login:
            if form.data['next'] != '':
                return redirect(form.data['next'])
            else:
                return redirect('/admin/')
        else:
            pass

    return render_template('admin/login.html',
                           form=form,
                           title=gettext('Please sign in'))
Example #9
0
def users():
    paginator = Paginator(query=User.select(), page=request.args.get('page'))
    return render_template('admin/users.html',
                           title=gettext('Users'),
                           users=paginator.items,
                           pages=paginator.links)
Example #10
0
def before_request():
    g.user = None
    if 'user_id' in session:
        g.user = User.get(User.id == session['user_id'])

    fypress.options = Option.auto_load()
Example #11
0
File: views.py Project: Fy-/FyPress
def users():
    paginator = Paginator(
        query=User.select(),
        page=request.args.get('page')
    )
    return render_template('admin/users.html', title=gettext('Users'), users=paginator.items, pages=paginator.links)
Example #12
0
File: views.py Project: Fy-/FyPress
def before_request():
    g.user = None
    if 'user_id' in session:
        g.user = User.get(User.id == session['user_id'])

    fypress.options = Option.auto_load()