示例#1
0
def page(page_url):
    """Generic Page View"""
    profile = Profile()
    profile.database = db
    profile.load_admin()
    
    page = Page("/%s" % page_url)
    page.database = db
    try:
        page.load()
    except PageNotFound:
        abort(404)
    html = markdown.markdown(page.content)
    
    return render_template('page.html', page=page, html=html, profile=profile)
示例#2
0
def index():
    """Home page of the profile"""
    profile = Profile()
    profile.database = db
    try:
        profile.load_admin()
    except AdminNotFound:
        return redirect(url_for("installation_index"))
    page = Page("/")
    page.database = db
    try:
        page.load()
    except PageNotFound:
        abort(500)
    html = markdown.markdown(page.content)
    return render_template('homepage.html', html=html, profile=profile)
示例#3
0
def installation_api_create_profile():
    """Create the Profile via API"""
    username = request.args.get('username')
    password = request.args.get('password')
    profile = Profile()
    profile.database = db
    profile.is_admin = True
    profile.username = username
    profile.set_userhash(password)
    profile.save()
    return jsonify(done=True)
示例#4
0
def api_show_profile(userhash=None):
    """
        Returns the openprofile in json format: used by other installations
        it contains also the key (or a sort of ) to verify messages. If the key change,
        the owner must re-authorize the other friend.
    """
    profile = Profile()
    profile.database = db
    if not userhash:
        profile.load_admin()
    else:
        profile.userhash = userhash
        profile.load()
    jsoned = profile.__dict__()
    del jsoned['is_admin']
    return json.dumps(jsoned)
示例#5
0
def login():
    next = request.args.get('next', '/admin', type=str)
    if 'auth' in session:
        return redirect(next)
        
    if request.method == 'POST':
        try:
            username = request.form['username']
            password = request.form['password']
        except KeyError:
            flash(u"Invalid Username or Password", "error")
            return render_template("auth/login.html", next=next)
            
        profile = Profile()
        profile.database = db
        profile.load_admin()
            
        if profile.verify_login(username, password):
            flash(u"Welcome back %s" % profile.username, "info" )
            session['auth'] = profile.userhash
            return redirect(next)
        else:
            flash(u"Invalid Username or Password", "error")
    return render_template("auth/login.html", next=next)