def show_entries(): """ It displays a list of users :return: """ user = Users() entries = user.get_all_users() return render_template('show_entries.html', entries=entries)
def rpc_verification_email(): """ Checks the existence of the entered email :return: OK or ERROR """ user = Users() if request.method == 'POST': if not user.verification_email(request.form['email']): return jsonify({"result": "ERROR"}) return jsonify({"result": "OK"})
def home(): if request.method == "GET": return render_template("home.html") elif request.method == "POST": form = request.form firstname = form["First name"] lastname = form["Last name"] email = form["Email"] yob = form["Yob"] gender = form["gender"] city = form["City"] u = Users(firstname = firstname, lastname = lastname, email = email, yob = yob, gender = gender, city = city) u.save() return "OK"
def login(): """ user Login :return: """ error = None if request.method == 'POST': user = Users() login_user = user.login() if login_user: session['logged_in'] = request.form['username'] flash('You were logged in') return redirect(url_for('show_entries')) else: error = 'The data is not correct, or that user does not exist' return render_template('login.html', error=error)
def registration(): """ Registration via the website :return: """ error = None if request.method == 'POST': if not request.form['username'] or not request.form['email'] \ or not request.form['pass'] or not request.form['phone']: error = 'Not all fields are completed' else: user = Users() user.add_user() session['logged_in'] = request.form['username'] flash('you have registered and are logged in as %s' % request.form['username']) return redirect(url_for('show_entries')) return render_template('registration.html', error=error)
def api_filter(): """ It accepts any key - values and searches the them /[email protected] or /api_filter?username=myname :return: dict in json """ user = Users() if request.args.keys(): filter = request.args.keys()[0] value = request.args[filter] result = user.get_on_filter(filter, value) if result: return jsonify({i: value for i, value in enumerate(result)}) else: return jsonify({"result": "Empty"}) return jsonify({"result": "ERROR"})
def api_registration(): """ Upon receipt of the data creates a user /api_registration?username=mynameIS&[email protected]&pass=0000&phone=380665551122 :return: OK or ERROR """ user = Users() more = {} if not user.verification_email(email = request.args.get("email")): return jsonify({"result": "ERROR"}) if request.args.get("username") and request.args.get("email") and \ request.args.get("pass")and request.args.get("phone"): for i in request.args: if i != "username" and i != "email" and i != "pass" and i != "phone": more[i] = request.args[i] more = pickle.dumps(more) login_user = user.add_user(metod='get', more = more) if login_user: return jsonify({"result": "OK"}) return jsonify({"result": "ERROR"})