Example #1
0
def api_list_vote_profile(username):
    """Get votes Profile"""
    author = get_user(session['user'], db)
    user = get_user(username, db)
    
    if author.username not in user.vote_received:
        user.vote_received.append(author.username)
        user.save()
        
    return json.dumps({"status":"ok"})
def homepage():
    """Homepage"""
    user = None
    if session.has_key('user'):
        user = get_user(session['user'], db)
    
    return render_template("homepage.html", user=user)
Example #3
0
def show_profile(username):
    """Show user Profile"""
    user = get_user(session['user'], db)
    profile = User(username)
    profile.database = db
    if not profile.already_exist():
        flash("Username not exists")
        redirect(url_for("homepage"))

    profile.load(username)
    return render_template("profile.html", user=user, profile=profile)
Example #4
0
def edit_profile():
    """Edit Profile"""
    profile = get_user(session['user'], db)
    return render_template("edit_profile.html", user=profile, profile=profile)
Example #5
0
def profile():
    the_user = None
    old_user = None
    already_registered = False
    username_editable = True
    
    if 'user' in session:
        already_registered = True
        old_user = get_user(session['user'], db)
        the_user = old_user
        if old_user:
            username_editable = False
        
    if request.method == 'POST':
        error = False
        username = request.form['username']
        
        if not old_user:
            the_user = User(username)
            the_user.database = db
            the_user.username = username
            username_editable = True
    
            the_user.registration_date = datetime.datetime.now()
            if the_user.already_exist():
                flash(u"Username already taken", "error")
                error = True
        else:
            the_user = old_user
            
        the_user.first_name = request.form['first_name']
        the_user.second_name = request.form['second_name']

        if len(request.form['email']) >= 9 and "@" in request.form['email']:
            the_user.email = request.form['email']
        else:
            flash(u"Insert a valid password", "error")
            error = True

        if request.form.has_key("blog_url"):
            if request.form['blog_url']:
                the_user.blog_url = request.form['blog_url']

        if request.form.has_key("twitter_url"):
            if request.form['twitter_url']:
                the_user.twitter_url = request.form['twitter_url']

        if request.form.has_key("facebook_url"):
            if request.form['facebook_url']:
                the_user.facebook_url = request.form['facebook_url']

        if request.form.has_key("linkedin_url"):
            if request.form['linkedin_url']:
                the_user.linkedin_url = request.form['linkedin_url']

        if request.form.has_key("avatar_url"):
            if request.form['avatar_url']:
                the_user.avatar_url = request.form['avatar_url']

        if request.form.has_key("password"):
            if len(request.form['password']) >= 6:
                the_user.change_password(request.form['password'])
            elif len(request.form['password']) == 0 and not username_editable:
                pass
            else:
                flash(u"The password must have more than 5 characters", "error")
                error = True
                
        if error:
            return render_template('auth/profile.html', user=old_user, puser=the_user, page="profile", username_editable=username_editable)
        
        the_user.save()
        if already_registered:
            flash(u"Profile updated", "success")
        else:
            flash(u"Registration complete! An email has sent to %s to verify your account." % the_user.email, "success")
            return redirect(url_for('homepage'))
            
        return render_template('auth/profile.html', user=old_user, puser=the_user, page="profile", username_editable=username_editable)

    return render_template('auth/profile.html', user=old_user, puser=the_user, page="profile", username_editable=username_editable)