def check_username_exist(): data = request.args username = data["username"] user = userClass.get_by_username(username) if user: return jsonify({"status":"Error", "message":"User already exist!"}) else: return jsonify({"status":"OK", "message":"OK"})
def login_donor(): data = request.args username, password = data["username"],data["password"] user = userClass.get_by_username(username) if not user or not user.check_password(password): return jsonify(status="auth fail") token = Functions.create_session(user) return jsonify(status="OK", token=token)
def login_Page(): if request.method == "POST": userName = request.form["username"] password = request.form["password"] u = user.get_by_username(userName) if u and u.check_password(password): login_user(u) return redirect("/") return render_template('login.html')
def login_Page(): if request.method == "POST": useName = request.form["username"] password = request.form["password"] u = user.get_by_username(useName) if u and u.check_password(password): login_user(u) return redirect("/") return render_template('login.html', user=current_user)
def set_blood_type(username): blod_type =request.form["bloodType"] RH = "-" if "-" in blod_type else "+" AB0 = blod_type.rstrip('-').rstrip('+') user = userClass.get_by_username(username) user.document["AB0"]= AB0 user.document["RH"] = RH user.save() return redirect("/events/donations/%s"%username)
def rest_push_event(): token = request.args["token"] username = Functions.get_username_from_token(token) user = userClass.get_by_username(username) doc = mongo.EventDocument() doc["username"] = user.get_username() doc["institutionID"] = None doc["type"] = request.args["type"] doc["info"] = {} return jsonify(status="OK")
def update_donor(username): data = request.form worker = userClass.get_by_username(username) worker.setUsername(data["username"]) worker.setName(data["name"]) worker.setSurname(data["surname"]) worker.setCountry(data["country"]) worker.setCity(data["city"]) worker.setAddress(data["address"]) worker.setAB0(data["AB0"]) worker.setRh(data["Rh"]) worker.save() return redirect('/super/admin/editDonors/%s' % data["username"])
def rest_profile(): try: token = request.args["token"] username = Functions.get_username_from_token(token) user = userClass.get_by_username(username) if request.method == "POST": data = json.loads(request.args["data"]) for key in data.keys(): if not "token" in key: user.document[key] = data[key] user.save() return jsonify(status="OK") return jsonify(status="OK",profile=user.getProfileJson()) except Exception as e: return jsonify(status=e.message)
def do_donation(username): user = userClass.get_by_username(username) data = request.form institutionId = current_user['institution'] doc = mongo.EventDocument() doc['institutionID'] = institutionId doc['username'] = username doc["type"] = "donation" info = {} for key in data.keys(): if key in ["tatoo","pierce"] : info[key] = True else: info[key] = data[key] doc["info"] = info doc.save() dose = mongo.DoseDocument() dose["institutionID"] = institutionId dose["AB0"] = user["AB0"] dose["RH"] = user["RH"] dose["donationId"] = doc["id"] dose.save() return redirect("/")
def rest_unsubscribe(): token = request.args["token"] username = Functions.get_username_from_token(token) user = userClass.get_by_username(username) user.clearNotificationToken(True) return jsonify(status="OK")
def load_user(userId): u = user.get_by_username(userId) return u
def edit_donor(username): return render_template("admin/editDonor.html", donor=user.get_by_username(username), user=current_user, l=loc.get)
def edit_worker(username): return render_template("admin/editWorker.html", worker=user.get_by_username(username), institutions=institution.get_all_institutions_array(), user=current_user, l=loc.get)
def do_donatinon(username): donator = userClass.get_by_username(username) return render_template("userDonating.html", donator = donator, l=loc.get, user = current_user)
def user_profile(username): usr = userClass.get_by_username(username) return render_template("userProfile.html", user = current_user, l=loc.get, editedUser = usr)