예제 #1
0
파일: app.py 프로젝트: vfabi/authportal
def login():
    form = LoginForm()

    if request.method == 'GET':
        return render_template('login.html',
                               form=form,
                               variables=variables,
                               captcha=captcha.create())

    if form.validate_on_submit():
        username = request.form.get('username')
        password = request.form.get('password')
        captcha_hash = request.form.get('captcha-hash')
        captcha_text = request.form.get('captcha_text')
        redirect_url = request.args.get(variables['redirect_url_param_name'],
                                        default='/')
        if not captcha.verify(captcha_text, captcha_hash):
            flash('Captcha is not valid.', 'error')
            return redirect(
                f'{url_for("login")}?{variables["redirect_url_param_name"]}={redirect_url}'
            )
        user = User.get(username=username, password=password)
        if user:
            if login_user(user):
                return redirect(redirect_url)
        flash('Username or password is invalid.', 'error')
        return redirect(
            f'{url_for("login")}?{variables["redirect_url_param_name"]}={redirect_url}'
        )
예제 #2
0
def ajax():
    username = request.form["username"]
    exists = False

    if User.get(username):
        exists = True
    else:
        exists = False

    return jsonify({"exists": exists})
 def update(self, id):
     data = json.loads(request.data)
     u = User.get(Key(id))
     if 'current_cells' in data:
         u.current_cells = data['current_cells']
     if 'is_admin' in data:
         if data['is_admin']:
             u.role = "admin"
         else:
             u.role = "editor"
     u.put()
     return Response(u.as_json(), mimetype='application/json')
예제 #4
0
 def update(self, id):
     data = json.loads(request.data)
     u = User.get(Key(id))
     if 'current_cells' in data:
         u.current_cells = data['current_cells']
     if 'is_admin' in data:
         if data['is_admin']:
             u.role = "admin"
         else:
             u.role = "editor"
     u.put()
     return Response(u.as_json(), mimetype='application/json')
예제 #5
0
def buy():

    user = User.get(user_id=session["user_id"])
    stock = None
    setSessionStock("buystock")

    if "symbol" in session["buystock"]:
        stock = Stock.get(session["buystock"]["symbol"])
        print("stock set to: {}".format(stock.name))

    # Stock will be None unless search has been made. But user won't get option to do anything with stock unless there's been a search.
    form = BuyForm(user=user, stock=stock)

    if request.method == "POST":

        if form.validate_on_submit():
            return redirect(url_for("transactions.buy"))

        print(form.errors)

    return render_template("/buy.html", form=form)
 def get(self, id):
     u = User.get(Key(id))
     return Response(u.as_json(), mimetype='application/json')
예제 #7
0
def uniqueUser(form, field):
    if User.get(field.data):
        raise ValidationError('Username is already taken')
예제 #8
0
def existingUser(form, field):
    if not User.get(field.data):
        raise ValidationError('User does not exist')
예제 #9
0
 def get(self, id):
     u = User.get(Key(id))
     return Response(u.as_json(), mimetype='application/json')
def load_user(user_id):
    return User.get(int(user_id))