Ejemplo n.º 1
0
def get_events():
    
    sparm = request.args.get('start', None, type=float)
    eparm = request.args.get('end', None, type=float)
    
    if sparm == None or eparm == None:
        flash("Invalid Request", "Error")
        return default_view()
    
    sdate = datetime.fromtimestamp(sparm)
    edate = datetime.fromtimestamp(eparm)
    
    events = Event.query.filter(Event.date_start >= sdate).\
                        filter(Event.date_end <= edate).all()
    
    json_str = "[ "
    
    for event in events:
        jsobj = {
            'id': event.id,
            'title': event.get_title(),
            'start': event.get_start_date(),
            'end': event.get_end_date(),
            'info': event.get_info(),
            'location': event.get_location(),
            'allDay': event.allday
        }
        
        json_str = json_str + jsonify(jsobj).data + ","
        
    json_str += "{}]"
    
    return Response(json_str, mimetype="application/json")
Ejemplo n.º 2
0
def view_post(postid):
    post = NewsPost.query.get(postid)

    if post == None:
        return default_view()
    
    return render_template('show_post.html', post=post)
Ejemplo n.º 3
0
def add_post():
    error = None;
    npost = NewsPost("<input id=\"post-title\" style=\"font-size: 24px; font-weight: bold; padding: 2px; width: 95%;height: 32px;\" type=text name=\"posttitle\" value=\"Post Title\">",
                    "<textarea style=\"width:100%;\" id=\"post-body-textbox\" name=\"postbody\">Post Body</textarea>",
                    current_user.id)
    if request.method == 'POST':
        
        ptitle  = request.form['posttitle']
        pbody   = request.form['postbody']
        
        if( ptitle != None and pbody != None ):
            
            npost.set_title(ptitle)
            npost.set_body(pbody)
            db.session.add(npost)
            db.session.commit()
            
            flash('New entry was successfully posted', 'Message')
            
            return redirect(url_for('.default'))

        flash("Invalid Request", "Error")
        return default_view()

    return render_template('post_form.html', 
                           post=npost, 
                           form_action=url_for('.add_post'),
                           form_name='addpost')
Ejemplo n.º 4
0
def auth_register():
    error = None
    # #############################################################
    # TODO: Add form input validation and sanitize everything and 
    #        add bcrypt support
    if request.method == 'POST':
        uname       = str(request.form['username'])
        pw          = str(request.form['password'])
        pw2         = str(request.form['password2'])
        email       = str(request.form['email'])
        unc_email   = str(request.form['uncc_email'])
        fname       = str(request.form['firstname'])
        lname       = str(request.form['lastname'])
        nick        = str(request.form['nickname'])
        degree_prog = int(request.form['degree_program'])

        if len(uname) < 5:
            flash('Username is too short: must be longer than five characters', 'Error')
            return render_template('register.html', 
                    error=error,
                    degrees=app.config['DEGREE_PROGRAMS'])

        quser = User.query.filter_by(username = uname).first()
        qemail = User.query.filter_by(uncc_email = unc_email).first()
        
        if (quser is None) and (qemail is None):
            if pw == pw2: # basic password validation
                # generate password hash 
                passwd = hashpw(pw, gensalt())
                
                usr = User(uname, passwd, email)
                usr.set_fullname(fname,lname)
                usr.set_uncc_email(unc_email)
                usr.set_nickname(nick)
                usr.set_degree_program(degree_prog)

                db.session.add(usr)
                db.session.commit()

                flash('User created: You may now login.', 'Message')

                return default_view()
            else:
                flash('Passwords do not math', 'Error')
        else:
            flash('Username or Email already in use.', 'Error')
    return default_view('user/register.html')
Ejemplo n.º 5
0
def update_event():
    eid         = request.form.get('eventid', None, type=int)
    etitle      = request.form.get('eventtitle', None)
    einfo       = request.form.get('eventinfo', None)
    elocation   = request.form.get('eventlocation', None)
    estr_start  = request.form.get('eventstart', None)
    estr_end    = request.form.get('eventend', None)
    estr_allday = request.form.get('eventallday', None)
    
    if eid == None:
        flash("Invalid Request", "Error")
        return default()
    
    evobj = Event.query.get(eid);
    
    if evobj == None:
        flash("Invalid Request", "Error")
        return default_view()
    
    if etitle != None:
        evobj.set_title(etitle)
    
    if einfo != None:
        evobj.set_info(einfo)
    
    if elocation != None:
        evobj.set_location(elocation)
    
    if estr_allday == 'on':
        evobj.set_allday(True)
    else:
        evobj.set_allday(False)
    
    if estr_start != None and estr_end != None:
        estart = datetime.strptime(estr_start, '%m/%d/%Y %I:%M %p')
        eend   = datetime.strptime(estr_end, '%m/%d/%Y %I:%M %p')
        
        evobj.set_start_date(estart)
        evobj.set_end_date(eend)
    else:
        flash("Invalid Request", "Error")
        return default_view()
    
    db.session.commit()
    
    return default()
Ejemplo n.º 6
0
def delete_post(postid):
    pst = NewsPost.query.get(postid)
    
    if pst == None:
        flash("Invalid Request", "Error")
        return default_view();
    
    if current_user == pst.user:
        for comment in pst.comments:
            db.session.delete(comment)
        
        db.session.delete(pst)
        db.session.commit()
    else:
        flash("Insufficient Premissions", "Error")
        return default_view()
    return default_view()
Ejemplo n.º 7
0
def mailer():

    msg = Message("client test")
    msg.add_recipient("*****@*****.**")

    msg.body = "Yo, shoot me a message"

    base_app.mailer.send(msg)
    
    return default_view()
Ejemplo n.º 8
0
def edit_post():

    pid = int(request.form['postid'])
    ptitle = str(request.form['posttitle'])
    pnbody = str(request.form['postbody'])
    
    newspost = NewsPost.query.get(pid)
    
    if(newspost == None):
        flash("Invalid Request", "Error")
        return default_view()
    
    if current_user.id != newspost.author:
        flash("Invalid User Premissions", "Error")
        return default_view()
    
    newspost.body  = pnbody
    newspost.title = ptitle
    
    db.session.commit()
    
    return default_view()
Ejemplo n.º 9
0
def add_post_comment(postid):
    post = NewsPost.query.get(postid)
    
    if post == None:
        return default_view("Invalid Request")

    pbody = request.form['comment-body']
    pauth = current_user.id
    
    if( pbody != None ):
        ncmt = NewsPostComment( post.id, pbody, pauth )
        db.session.add(ncmt)
        db.session.commit()
    
    return render_template('show_post.html', post=post)
Ejemplo n.º 10
0
def auth_login():
    if request.method == 'POST':
        
        uname = str(request.form['username'])
        pw    = str(request.form['password'])
        quser = User.query.filter_by(username = uname).first()
        
        if( quser != None ):
            
            pw_hash = hashpw(pw, quser.password)

            if( pw_hash == quser.password ):
                login_user(quser)
            else:
                flash('Invalid Username or password', 'Error')
        else:
            flash('Invalid Username or password', 'Error')
    
    return default_view()
Ejemplo n.º 11
0
def auth_logout():
    logout_user()
    return default_view()
Ejemplo n.º 12
0
def forum_wrap():
    if g.sijax.is_sijax_request:
        return g.sijax.process_request()
    
    return default_view()