Exemplo n.º 1
0
def login():
    error = None
    if request.method == "POST":
        username = request.form['username']
        password = request.form['password']
        coupon_code = request.form['coupon_code']
        user_coupon = Coupon.query.filter_by(username=username).first()

        if username == "" or password == "" or coupon_code == "":
            flash('Invalid username/password/coupon combination', 'error')
            return render_template("login.html")

        elif coupon_code == "ec" and username == "ec" and \
            ldap_helper.ldap_authenticate(username, password):
            session['logged_in'] = True
            session['is_admin'] = True
            session['username'] = username
            flash("Welcome EC", "success")
            return redirect(url_for('admin'))

        elif user_coupon and user_coupon.is_valid == False:
            flash(
                "This coupon has been invalidated. You can only vote once with a coupon",
                "error")
            return render_template("login.html")

        elif username == app.config['USERNAME'] and password == app.config['PASSWORD'] \
                and coupon_code == app.config['ADMIN_COUPON']:
            session['logged_in'] = True
            session['is_admin'] = True
            session['username'] = "******"
            flash('Welcome Admin', "success")
            return redirect(url_for('admin'))

        elif ldap_helper.ldap_authenticate(username, password) and \
                user_coupon and user_coupon.value == coupon_code:

            user_hostel = ldap_helper.ldap_fetch_detail(username, ["hostel"])
            user_dept = ldap_helper.ldap_fetch_detail(
                username, ["departmentNumber"]).get("departmentNumber")
            if user_hostel:
                if user_dept == "PGDM":
                    session["is_pgpex"] = True
                session['hostel'] = user_hostel["hostel"]
                session['logged_in'] = True
                session['username'] = username
                flash('You have logged in', "success")
                return redirect(url_for('voting_page'))
            else:
                flash(
                    "We could not retrieve your hostel. Please try login again"
                )
                return render_template('login.html')

        else:
            flash('Invalid username/password/coupon combination', "error")
            return render_template("login.html")

    return render_template("login.html")
Exemplo n.º 2
0
def login():
    error = None
    if request.method == "POST":
        username = request.form['username']
        password = request.form['password']
        coupon_code = request.form['coupon_code']
        user_coupon = Coupon.query.filter_by(username=username).first()

        if username == "" or password == "" or coupon_code =="" :
            flash('Invalid username/password/coupon combination', 'error')
            return render_template("login.html")

        elif coupon_code == "ec" and username == "ec" and \
            ldap_helper.ldap_authenticate(username, password):
                session['logged_in'] = True
                session['is_admin'] = True
                session['username'] = username
                flash("Welcome EC", "success")
                return redirect(url_for('admin'))

        elif user_coupon and user_coupon.is_valid == False:
            flash("This coupon has been invalidated. You can only vote once with a coupon", "error")
            return render_template("login.html")

        elif username == app.config['USERNAME'] and password == app.config['PASSWORD'] \
                and coupon_code == app.config['ADMIN_COUPON']:
            session['logged_in'] = True
            session['is_admin'] = True
            session['username'] = "******"
            flash('Welcome Admin', "success")
            return redirect(url_for('admin'))

        elif ldap_helper.ldap_authenticate(username, password) and \
                user_coupon and user_coupon.value == coupon_code:

            user_hostel = ldap_helper.ldap_fetch_detail(username, ["hostel"])
            user_dept = ldap_helper.ldap_fetch_detail(username,
                            ["departmentNumber"]).get("departmentNumber")
            if user_hostel:
                if user_dept == "PGDM":
                    session["is_pgpex"] = True
                session['hostel'] = user_hostel["hostel"]
                session['logged_in']= True
                session['username'] = username
                flash('You have logged in', "success")
                return redirect(url_for('voting_page'))
            else:
                flash("We could not retrieve your hostel. Please try login again")
                return render_template('login.html')

        else:
            flash('Invalid username/password/coupon combination', "error")
            return render_template("login.html")

    return render_template("login.html")
Exemplo n.º 3
0
def save_candidate():
    username = request.form['username']
    post_select = request.form['post_select']
    if "binary_vote" in request.form:
        add_yesno = True
    else:
        add_yesno = False
    user_details = ldap_helper.ldap_fetch_detail(username,
                   ["hostel", "displayName", "departmentNumber", "regNo"])
    if username:
        candidate_post = Post.query.filter_by(name=post_select).first()
        if username.lower() == 'abstain':
            hostel = "All"
            full_name = username.capitalize()
            dept = "None"
            regNo = "NA"
        elif username.lower() == "blank":
            hostel = "All"
            full_name = username.capitalize()
            dept = "None"
            regNo = "NA"
        else:
            hostel = user_details["hostel"]
            full_name = user_details["displayName"]
            dept = user_details["departmentNumber"]
            regNo = user_details["regNo"]

        c1 = Candidate(username, full_name, hostel, candidate_post.id, dept, add_yesno, regNo)
        db.session.add(c1)
        db.session.commit()
        # app.logger.warning('Candidate - %s added to the database' % username)
        return jsonify(status_msg="Added %s" % username)
    else:
        return jsonify(status_msg="To add a blank user, enter blank in username field")
Exemplo n.º 4
0
def save_candidate():
    username = request.form['username']
    post_select = request.form['post_select']
    if "binary_vote" in request.form:
        add_yesno = True
    else:
        add_yesno = False
    user_details = ldap_helper.ldap_fetch_detail(username,
                                                ["hostel", "displayName", "departmentNumber"])
    if username:
        candidate_post = Post.query.filter_by(name=post_select).first()
        if username != 'abstain':
            if user_details:
                hostel = user_details["hostel"]
                full_name = user_details["displayName"]
                dept = user_details["departmentNumber"]
            else:  #its Blank or Abstain
                hostel = "All"
                full_name = username
                dept = "None" #TODO: Not to sure if this is how it should be
        else:
            full_name = "Abstain"
            hostel = "NA"
            dept = "NA"

        c1 = Candidate(username, full_name, hostel, candidate_post.id, dept, add_yesno)
        db.session.add(c1)
        db.session.commit()
        # app.logger.warning('Candidate - %s added to the database' % username)
        return jsonify(status_msg="Added %s" % username)
    else:
        return jsonify(status_msg="To add a blank user, enter blank in username field")
Exemplo n.º 5
0
def fetch_candidate_details(username):
    attr_list = ["departmentNumber", "displayName", "hostel", "regNo"]
    candidate_details = ldap_helper.ldap_fetch_detail(username, attr_list)
    img_url = "http://student.iimcal.ac.in/userimages/%s.jpg" % username
    if username == "abstain":
        img_url = "http://upload.wikimedia.org/wikipedia/en/thumb/7/78/Trollface.svg/200px-Trollface.svg.png"
        return jsonify(image_url=img_url,
                       dept="NA",
                       name="Abstain",
                       hostel="NA",
                       regno="NA")
    elif username == "blank":
        img_url = "http://www.wpclipart.com/blanks/shapes/star_with_blank_text_space..png"
        return jsonify(image_url=img_url,
                       dept="NA",
                       name="Blank",
                       hostel="NA",
                       regno="NA")

    if candidate_details:
        return jsonify(image_url=img_url,
                       dept=candidate_details["departmentNumber"],
                       name=candidate_details["displayName"],
                       hostel=candidate_details["hostel"],
                       regno=candidate_details["regNo"])
    else:
        return jsonify(name="No candidate found!")
Exemplo n.º 6
0
def fetch_candidate_details(username):
    attr_list = ["departmentNumber", "displayName", "hostel"]
    candidate_details = ldap_helper.ldap_fetch_detail(username, attr_list)
    img_url = "http://student.iimcal.ac.in/userimages/%s.jpg" % username
    if username == "abstain":
        img_url = "http://upload.wikimedia.org/wikipedia/en/thumb/7/78/Trollface.svg/200px-Trollface.svg.png"
        return jsonify(image_url=img_url, dept="NA",
                                    name="Abstain",
                                    hostel="NA")
    if candidate_details:
        return jsonify(image_url=img_url, dept=candidate_details["departmentNumber"],
                                    name=candidate_details["displayName"],
                                    hostel=candidate_details["hostel"])
    else:
        return jsonify(name="No candidate found!")
Exemplo n.º 7
0
        def generate():
            dept_dict = {}
            votes = Vote.query.all()
            yield "timestamp,voter_name,candidate_name, post_name,candidate_batch\n"
            for v in votes:
                if v.candidate_name == "blank" or v.candidate_name == "abstain":
                    yield "%s,%s,%s,%s,%s" % (v.timestamp, v.voter_name, \
                        v.candidate_name, v.post_name, "none") + '\n'

                else:
                    if v.candidate_name not in dept_dict:
                        dept = ldap_helper.ldap_fetch_detail(v.candidate_name,
                                ["departmentNumber"]).get("departmentNumber")
                        dept_dict[v.candidate_name] = dept
                    else:
                        dept = dept_dict[v.candidate_name]
                    yield "%s,%s,%s,%s,%s" % (v.timestamp, v.voter_name, \
                        v.candidate_name, v.post_name, dept) + '\n'
Exemplo n.º 8
0
        def generate():
            dept_dict = {}
            votes = Vote.query.all()
            yield "timestamp,voter_name,candidate_name, post_name,candidate_batch\n"
            for v in votes:
                if v.candidate_name == "blank" or v.candidate_name == "abstain":
                    yield "%s,%s,%s,%s,%s" % (v.timestamp, v.voter_name, \
                        v.candidate_name, v.post_name, "none") + '\n'

                else:
                    if v.candidate_name not in dept_dict:
                        dept = ldap_helper.ldap_fetch_detail(
                            v.candidate_name,
                            ["departmentNumber"]).get("departmentNumber")
                        dept_dict[v.candidate_name] = dept
                    else:
                        dept = dept_dict[v.candidate_name]
                    yield "%s,%s,%s,%s,%s" % (v.timestamp, v.voter_name, \
                        v.candidate_name, v.post_name, dept) + '\n'
Exemplo n.º 9
0
def save_candidate():
    username = request.form['username']
    post_select = request.form['post_select']
    if "binary_vote" in request.form:
        add_yesno = True
    else:
        add_yesno = False
    user_details = ldap_helper.ldap_fetch_detail(
        username, ["hostel", "displayName", "departmentNumber", "regNo"])
    if username:
        candidate_post = Post.query.filter_by(name=post_select).first()
        if username.lower() == 'abstain':
            hostel = "All"
            full_name = username.capitalize()
            dept = "None"
            regNo = "NA"
        elif username.lower() == "blank":
            hostel = "All"
            full_name = username.capitalize()
            dept = "None"
            regNo = "NA"
        else:
            hostel = user_details["hostel"]
            full_name = user_details["displayName"]
            dept = user_details["departmentNumber"]
            regNo = user_details["regNo"]

        c1 = Candidate(username, full_name, hostel, candidate_post.id, dept,
                       add_yesno, regNo)
        db.session.add(c1)
        db.session.commit()
        # app.logger.warning('Candidate - %s added to the database' % username)
        return jsonify(status_msg="Added %s" % username)
    else:
        return jsonify(
            status_msg="To add a blank user, enter blank in username field")