示例#1
0
def process_search():
    form = forms.SearchForm(request.form)
    if form.validate() == False:
        flash("You didn't search for anything silly.")
        return render_template('search.html', user=current_user)
    else:
        posts = []
        ids_no_posts = []
        search_terms = form.search_term.data.split()
        for search_term in search_terms:
            user_ids = model.search_user(search_term)
            if user_ids == []:
                flash("Oh no!  That person doesn't exist.")
                return render_template('search.html', user=current_user)
            for user_id in user_ids:
                post = model.get_last_post(user_id)
                if post:
                    posts.append(post)
                else:
                    ids_no_posts.append(user_id)
        users_no_posts = []
        for user_id in ids_no_posts:
            user = model.get_user_by_id(user_id)
            users_no_posts.append(user)
        posts = list(set(posts))
        users_no_posts = list(set(users_no_posts))
        return render_template('searchresults.html',
                               user=current_user,
                               posts=posts,
                               no_posts=users_no_posts)
示例#2
0
def process_search():
	form = forms.SearchForm(request.form)
	if form.validate() == False: 
		flash("You didn't search for anything silly.")
		return render_template('search.html', user=current_user)
	else:
		posts = []
		ids_no_posts = []
		search_terms = form.search_term.data.split()
		for search_term in search_terms:
			user_ids = model.search_user(search_term)
			if user_ids == []:
				flash("Oh no!  That person doesn't exist.")
				return render_template('search.html', user=current_user)
			for user_id in user_ids:
				post = model.get_last_post(user_id)
				if post:
					posts.append(post)
				else: 
					ids_no_posts.append(user_id)
		users_no_posts = []
		for user_id in ids_no_posts:
			user = model.get_user_by_id(user_id)
			users_no_posts.append(user)
		posts = list(set(posts))
		users_no_posts = list(set(users_no_posts))
		return render_template('searchresults.html', user=current_user, posts=posts, no_posts=users_no_posts)
示例#3
0
def show_user():
    model.connect()
    user_id = request.args.get("id")
    user = model.get_user_by_id(user_id)
    # user_profile = model.user_name.get_posts()

    return render_template("user_profile.html", user= user)
示例#4
0
def post_to_wall():
    model.connect_to_db()
    user_id = session['user_id']
    author_name = model.get_user_by_id(user_id[0])
    content = request.form.get("content")
    username = request.form.get("username")
    model.create_wallpost(author_name, content, username)
    return redirect(url_for("view_user", username = username))
示例#5
0
 def is_logged(self):
     user_cookie = self.get_cookie('user')
     try:
         if user_cookie and stuff.check_secure_val(user_cookie):
             user_id = stuff.get_val_from_secure_val(user_cookie)
             return model.get_user_by_id(int(user_id))
     except ValueError, e:
         logging.error('Error checking if is logged\n ValueError: %s' % e)
         return
示例#6
0
 def is_logged(self):
     user_cookie = self.get_cookie('user')
     try:
         if user_cookie and stuff.check_secure_val(user_cookie):
             user_id = stuff.get_val_from_secure_val(user_cookie)
             return model.get_user_by_id(int(user_id))
     except ValueError, e:
         logging.error('Error checking if is logged\n ValueError: %s' % e)
         return
示例#7
0
 def get(self):
     try:
         user_cookie = self.get_cookie('user')
         user_id = int(stuff.get_val_from_secure_val(user_cookie))
         user = model.get_user_by_id(user_id)
         self.logout(user)
         self.redirect('/')
     except TypeError:
         self.logout()
         self.redirect('/')
示例#8
0
 def get(self):
     try:
         user_cookie = self.get_cookie('user')
         user_id = int(stuff.get_val_from_secure_val(user_cookie))
         user = model.get_user_by_id(user_id)
         self.logout(user)
         self.redirect('/')
     except TypeError:
         self.logout()
         self.redirect('/')
示例#9
0
文件: code.py 项目: Tangdongle/CHESS
 def POST(self, uid,cin, key):
     i = web.input()
     user = model.get_user_by_id(cin, uid)[0]
     form = self.form()
     if form.validates():
         pwd = bcrypt.hashpw(i.password, bcrypt.gensalt(BCRYPT_WLOAD))
         model.update_user(cin, uid, pwd, user.email, user.privilege)
         raise web.seeother('/login')
     else:
         raise web.seeother('/passwordchange/%d/%d/%s') %(uid, cin, key)
示例#10
0
文件: app.py 项目: zachwick/hwpc
    def PUT(self, user_id):
        data = json.loads(web.data())
        updated_user = model.update_user(data)

        if updated_user:
            user = model.get_user_by_id(data['id'])
            user['registerDate'] = str(user['registerDate'])
            return json.dumps(user)
        else:
            web.ctx.status = '500 Internal Server Error'
            return
示例#11
0
    def PUT(self, user_id):
        data = json.loads(web.data())
        updated_user = model.update_user(data)

        if updated_user:
            user = model.get_user_by_id(data['id'])
            user['registerDate'] = str(user['registerDate'])
            return json.dumps(user)
        else:
            web.ctx.status = '500 Internal Server Error'
            return
示例#12
0
def get_card():
    user_id = request.cookies.get('user_id')
    user = model.get_user_by_id(user_id)

    appointments = user.unpaid_appointments()

    total_appointments = len(appointments)

    total_payment = total_appointments * 2600

    return render_template("payment.html", total_appointments=total_appointments, total_payment=total_payment)
示例#13
0
文件: wrg.py 项目: benshen/wrg
    def POST(self, userid):
        today = datetime.date.today().strftime('%Y%m%d')
        form = self.form()
        if not form.validates():
            return render.new(userid, form, today)

        user = model.get_user_by_id(userid)
        if user == None:
            raise web.seeother('/')

        model.new_report(form.d.job, form.d.risk, form.d.plan, user.name)
        raise web.seeother('/')
示例#14
0
def user_profile():
    user_id = request.cookies.get('user_id')
    user = model.get_user_by_id(user_id)
    if model.User.query.get(user_id) is not None:
        user_dogs = model.session.query(model.User_Dog).filter_by(user_id=user.id)
        nicknames = []
        for user_dog in user_dogs:
            dog = model.session.query(model.Dog).get(user_dog.dog_id)
            nicknames.append(dog.nickname)
            

        return render_template('profile.html', display_user = user, nicknames = nicknames)
    else:
        return redirect('/login')
示例#15
0
def profile(user_id):
    profile_link = my_profile_link()
    user = model.get_user_by_id(user_id)
    movie_ratings = model.view_movie_list(user_id)
    if session.get('id'):
        if session['id'] == int(user_id):
            return render_template("profile.html", user_id=user_id, email = user.email,
                                    movie_ratings=movie_ratings, profile_link=profile_link)
        else:
            return render_template("user_profile.html", user_id=user_id, email = user.email,
                        movie_ratings=movie_ratings, profile_link=profile_link)
    else:
        return render_template("user_profile.html", user_id=user_id, email = user.email,
                        movie_ratings=movie_ratings, profile_link=profile_link)
示例#16
0
    def GET(self, user_id):
        user = model.get_user_by_id(user_id)
        if user is not None:
            accept_header = web.ctx.env.get("HTTP_ACCEPT")

            if "text/html" in accept_header:
                # Show an HTML table
                return render.user()
            elif "application/json" in accept_header:
                # Return a JSON string
                user['registerDate'] = str(user['registerDate'])
                return json.dumps(user)
        else:
            web.ctx.status = '404 Not Found'
            return
示例#17
0
def create_user(update: Update, context):
    """
    Check if User is db, create if not, update is yes
    """
    user_id = update.effective_user.id
    user_name = update.effective_user.username
    user = get_user_by_id(id=user_id)

    if not user:
        user = User(name=user_name, id=user_id)
    else:
        #Adding this check because user can change the name
        user.name = user_name
    user.save_user()
    return user
示例#18
0
文件: app.py 项目: zachwick/hwpc
    def GET(self, user_id):
        user = model.get_user_by_id(user_id)
        if user is not None:
            accept_header = web.ctx.env.get("HTTP_ACCEPT")

            if "text/html" in accept_header:
                # Show an HTML table
                return render.user()
            elif "application/json" in accept_header:
                # Return a JSON string
                user['registerDate'] = str(user['registerDate'])
                return json.dumps(user)
        else:
            web.ctx.status = '404 Not Found'
            return
示例#19
0
class Users:
    def POST(self):
        data = json.loads(web.data())

        try:
            new_user = model.new_user(data)
        except Exception, e:
            web.ctx.status = '400 Bad Request'
            return

        user = model.get_user_by_id(new_user)

        user['registerDate'] = str(user['registerDate'])

        web.ctx.status = '201 Created'
        return json.dumps(user)
示例#20
0
 def POST(self, uid,cin, key):
     i = web.input()
     user = model.get_user_by_id(cin, uid)[0]
     form = self.form
     if form.validates():
         pwd = bcrypt.hashpw(i.password, bcrypt.gensalt(BCRYPT_WLOAD))
         model.update_user(cin, uid, pwd, user.email, user.privilege)
         raise web.seeother('/login')
     else:
         try:
             recovery = model.get_recovery_time(cin, userid, key)[0]
             t = timedelta(days=1)
             d1, d2 = datetime.utcnow(), datetime.utcfromtimestamp(recovery.timestamp)
             if d2 + t > d1:
                 return render.passwordchange(form, user, key, d2+t)
             else:
                 raise web.notfound('Link has expired')
         except IndexError:
             raise web.notfound()
示例#21
0
 def GET(self, uid, cin, key=None):
     r"""
     Retrieves UID,CIN and key from HTML GET query and uses the values
     to generate a page where the
     """
     if key is not None:
         form = self.form
         try:
             recovery = model.get_recovery_time(cin, uid, key)[0]
             user = model.get_user_by_id(cin, uid)[0]
             t = timedelta(days=1)
             d1, d2 = datetime.utcnow(), datetime.utcfromtimestamp(recovery.timestamp)
             if d2 + t > d1:
                 return render.passwordchange(form, user, key, d2+t)
             else:
                 raise web.notfound('Link has expired')
         except IndexError:
             raise web.notfound()
     else:
         raise web.notfound()
示例#22
0
def edit_attendee():
    aid = request.args.get('id', None)
    attendee = find_attendee_by_id(aid)
    reg_data = None
    r_id = attendee.get('registered_by', None)
    if r_id:
        reg_data = {
            'registrator': model.get_user_by_id(get_db(), r_id),
            'registered_on': attendee['registered_on'],
        }
    if aid and not attendee:
        return redirect('/index')
    if not flask_login.current_user.is_admin \
            and attendee and attendee.get('registered', False):
        return redirect('/index')
    return render_template('attendee.html',
        fields = fields.INFO_FIELDS,
        user = flask_login.current_user,
        events = get_all_events(),
        reg_data = reg_data,
        attendee_id = aid)
示例#23
0
def editprofile():
    first = request.form.get("first_name")
    last = request.form.get("last_name")
    email_in = request.form.get("email")
    password_in = request.form.get("password")
    age = request.form.get("age")
    cell = request.form.get("cell_phone")
    zipcode = request.form.get("zip_code")
    dairy = request.form.get("dairy")
    wheat = request.form.get("wheat")
    soy = request.form.get("soy")
    caffeine = request.form.get("caffeine")
    alcohol = request.form.get("alcohol")
    health = request.form.get("health")
    drug = request.form.get("drug")
    about = request.form.get("about")
    notes = request.form.get("notes")

    u = model.get_user_by_id(session['id'])
    u.first_name = first
    u.last_name = last
    u.email = email_in
    u.password = password_in
    u.cell_phone = cell
    u.baby_dob = datetime.strptime(age, "%Y-%m-%d")
    u.zip_code = zipcode
    u.no_dairy = (dairy == "on")
    u.no_wheat = (wheat == "on")
    u.no_soy = (soy == "on")
    u.no_caffeine = (caffeine == "on")
    u.no_alcohol = (alcohol == "on")
    u.drug_info = drug
    u.has_health_info = (health == "on")
    u.about_me = about
    u.notes = notes
    model.session.commit()
    flash("Profile changes saved.")
    return redirect("/dashboard")
示例#24
0
def editprofile():
    first = request.form.get("first_name")
    last = request.form.get("last_name")
    email_in = request.form.get("email")
    password_in = request.form.get("password")
    age = request.form.get("age")
    cell = request.form.get("cell_phone")
    zipcode = request.form.get("zip_code")
    dairy = request.form.get("dairy")
    wheat = request.form.get("wheat")
    soy = request.form.get("soy")
    caffeine = request.form.get("caffeine")
    alcohol = request.form.get("alcohol")
    health = request.form.get("health")
    drug = request.form.get("drug")
    about = request.form.get("about")
    notes = request.form.get("notes")

    u = model.get_user_by_id(session['id'])
    u.first_name = first
    u.last_name = last
    u.email = email_in
    u.password = password_in
    u.cell_phone = cell
    u.baby_dob = datetime.strptime(age, "%Y-%m-%d")
    u.zip_code = zipcode
    u.no_dairy = (dairy == "on")
    u.no_wheat = (wheat == "on")
    u.no_soy = (soy == "on")
    u.no_caffeine = (caffeine == "on")
    u.no_alcohol = (alcohol == "on")
    u.drug_info = drug
    u.has_health_info = (health == "on")
    u.about_me = about
    u.notes = notes
    model.session.commit()
    flash("Profile changes saved.")
    return redirect("/dashboard")
示例#25
0
def donor_profile(user_id):
    user = model.get_user_by_id(user_id)
    return render_template("donorprofile.html",user=user)
示例#26
0
def register():
    if session.get("user_id"):
        username = model.get_user_by_id(session.get("user_id"))
        return redirect(url_for("view_user", username=username))
    return render_template("register.html")
示例#27
0
def index():
    if session.get("id"):
        user = model.get_user_by_id(session["id"])
        return redirect(url_for("profile", user_id =user.id))
    else:
        return render_template("index.html", user_id=None)
示例#28
0
def get_past_due_users():
    users = model.session.query(model.User).all()
    for user in users:
        user = model.get_user_by_id(user.id)
        if user.total_payment() != 0:
            yield user
示例#29
0
def load_user(user_id):
    return model.get_user_by_id(user_id)
示例#30
0
def load_user(user_id):
	return model.get_user_by_id(user_id)
示例#31
0
def go_home():
    model.connect_to_db()
    user_id = session['user_id']
    username = model.get_user_by_id(user_id[0])
    return redirect(url_for("view_user", username=username))
示例#32
0
def myprofile():
    user_info = model.get_user_by_id(session['id'])
    return render_template("userprofile.html", user=user_info)
示例#33
0
def donor_profile(user_id):
    user = model.get_user_by_id(user_id)
    return render_template("donorprofile.html",user=user)
示例#34
0
def load_editprofile():
    user = model.get_user_by_id(session['id'])
    return render_template("edituserprofile.html", user=user)
示例#35
0
def index():
    session_user_id = session.get('session_user_id')
    if session_user_id:
        user = model.get_user_by_id(session_user_id)
        return render_template("main.html", user_id = session_user_id, user = user)
    return render_template("index.html")
示例#36
0
def private_message(user_id):
    user = model.get_user_by_id(user_id)
    session['lookingat_id'] = user.id
    return render_template("message.html",user=user)
示例#37
0
def private_message(user_id):
    user = model.get_user_by_id(user_id)
    session['lookingat_id'] = user.id
    return render_template("message.html",user=user)
示例#38
0
def load_editprofile():
    user = model.get_user_by_id(session['id'])
    return render_template("edituserprofile.html", user=user)
示例#39
0
def myprofile():
    user_info = model.get_user_by_id(session['id'])
    return render_template("userprofile.html", user=user_info)
示例#40
0
 def get(self, *args, **kwargs):
     user = model.get_user_by_id(self.get_secure_cookie('user'))
     new_movies = self.recommend(user)
     self.render('index1.html', rec_movies=new_movies)
示例#41
0
    try:
        charge = stripe.Charge.create(
            amount=total_payment, # amount in cents, again
            currency="usd",
            card=token,
            description="*****@*****.**")

    except stripe.CardError, e:
        return "error"
  # The card has been declined
        pass
    return redirect('/profile')

    user_id = request.cookies.get('user_id')
    user = model.get_user_by_id(user_id)

    #make this a helper function
    new_payment = model.Payment(payment_date=datetime.datetime.today(),
                                payment_amount=total_payment)

    model.session.add(new_payment)
    model.session.commit()

    #helper function
    appointments = user.unpaid_appointments()
    for appointment in appointments:
        appointment.payment = new_payment

        model.session.add(appointment)
        model.session.commit()