예제 #1
0
    def setUp(self):
        melange.database.drop_db()
        melange.database.init_db()

        user = User('api')
        user.password = '******'
        user.save()
예제 #2
0
    def test_user(self):
        admin = User('admin')
        admin.password = '******'
        db_session.add(admin)
        db_session.commit()

        admin = User.query.filter(User.name=='admin').one()
        assert admin.authenticate('123456')
        assert admin.authenticate('12345') == False
예제 #3
0
def login():
    if request.method == 'POST':
        user_name = request.form['user-name']
        user_password = request.form['user-password']
        user = User.find(user_name)
        if user and user.authenticate(user_password):
            session['username'] = user_name
        return redirect(session['url'])
    return render_template('login.html')
예제 #4
0
def show_user(name):
    user = User.find(name)
    if request.method == 'POST':
        if 'remove-user' in request.form:
            user.remove()
            return redirect(url_for('.list_users'))
        elif 'change-password' in request.form:
            user_password = request.form['user-password']
            user.password = user_password
            user.save()
    return render_template('user.html', user=user)
예제 #5
0
def list_users():
    if request.method == 'POST':
        if 'add-user' in request.form:
            user_name = request.form['user-name']
            user_password = request.form['user-password']
            user = User.find(user_name)
            if not user:
                user = User(user_name)
                user.password = user_password
                user.save()
    users = User.find_all()
    return render_template('users.html', users=users)
예제 #6
0
 def check_auth(auth):
     user = User.find(auth.username)
     if not user or not user.authenticate(auth.password):
         return False
     return True
예제 #7
0
파일: runserver.py 프로젝트: jhoekx/melange
import os

from optparse import OptionParser

parser = OptionParser()
parser.add_option('-i', '--initdb', default=None, action='store_true', dest='initdb')
parser.add_option('-d', '--dropdb', default=None, action='store_true', dest='dropdb')
options, args = parser.parse_args()

if options.initdb:
    from melange.database import init_db
    print('Initializing database')
    init_db()
    from melange import User
    admin = User('admin')
    admin.password = '******'
    admin.save()
elif options.dropdb:
    from melange.database import drop_db
    print('Dropping database')
    drop_db()
else:
    from melange import app
    app.run()