Esempio n. 1
0
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"})
Esempio n. 2
0
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)
Esempio n. 3
0
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')
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
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")
Esempio n. 7
0
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"])
Esempio n. 8
0
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)
Esempio n. 9
0
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("/")
Esempio n. 10
0
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")
Esempio n. 11
0
def load_user(userId):
    u = user.get_by_username(userId)
    return u
Esempio n. 12
0
def edit_donor(username):
    return render_template("admin/editDonor.html",
                           donor=user.get_by_username(username),
                           user=current_user,
                           l=loc.get)
Esempio n. 13
0
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)
Esempio n. 14
0
def load_user(userId):
    u = user.get_by_username(userId)
    return u
Esempio n. 15
0
def do_donatinon(username):
    donator = userClass.get_by_username(username)
    return render_template("userDonating.html",
                           donator = donator,
                           l=loc.get,
                           user = current_user)
Esempio n. 16
0
def user_profile(username):
    usr = userClass.get_by_username(username)
    return render_template("userProfile.html",
                           user = current_user,
                           l=loc.get,
                           editedUser = usr)