Example #1
0
 def add_to_list(old_list, option):
     if not option:
         return old_list
     elif not option.price:
         return old_list
     option.price = "{:.2f}".format(float(option.price))
     if option.isLocalSeller:
         local_seller = User.get(id=option.local_seller_id)
         old_list.append({
             'seller': local_seller.username,
             'price': option.price,
             'rental': option.isRental,
             'book_type': option.type,
             'link': option.link,
             'purchaseID': option.id
         })
     else:
         old_list.append({
             'seller': option.remoteSellerName,
             'price': option.price,
             'rental': option.isRental,
             'book_type': option.type,
             'link': option.link,
             'purchaseID': option.id
         })
     return old_list
Example #2
0
def create_user():
    if request.method == 'POST':
        form = CreateUserForm(request.form)
        if form.validate():
            username = form.username.data
            password = form.password.data
            verify_password = form.verify_password.data
            if password == verify_password:
                u = User(username=username, password=password)
                try:
                    u.save()
                except IntegrityError:
                    flash(u'Username already taken', 'error')
                    form = CreateUserForm()
                    return render_template('login/create_user.html', form=form)
                login_user(u)
                flash(u'Welcome {un}'.format(un=username), 'success')
                return redirect('')
            else:
                flash(u'Passwords did not match', 'error')
                return render_template('login/create_user.html', form=form)
    form = CreateUserForm()
    return render_template('login/create_user.html', form=form)
Example #3
0
def login():
    if request.method == 'POST':
        form = LoginForm(request.form)
        if form.validate():
            username = form.username.data
            password = form.password.data
            # Authenticate user
            u = User.get(username=username)
            if not u:
                flash('Incorrect Username', 'error')
                return redirect('/login')
            if u.check_password(password):
                login_user(u)
                return redirect('')
            else:
                flash('Incorrect Password', 'error')
                return redirect('/login')

    else:
        form = LoginForm()
        return render_template('login/login.html', form=form)
Example #4
0
def delete_user():
    u = User.get(id=current_user.id)
    logout_user()
    User.delete(u)
    flash('User {u} has been deleted'.format(u=u.username), 'success')
    return redirect('')