Ejemplo n.º 1
0
def update_details():
    email = request.form['email'].strip()
    standard = request.form['standard'].strip()
    section = request.form['section'].strip()
    school = request.form['school'].strip()

    if email != "" and emails.is_valid_email(email) and g.user.email != email:
        g.user.email = email
        g.user.emailconf = False
        confkey = misc.generate_confirmation_key()
        g.user.conf_key = confkey
        emails.send_confirmation_email(g.user.email, g.user.name, confkey)
        g.user.save()
        flash("Email changed!")
    if standard != "" and g.user.standard != standard:
        g.user.standard = standard
        g.user.save()
        flash("standard changed!")

    if section != "" and g.user.section != section:
        g.user.section = section
        g.user.save()
        flash("Section changed!")
    if school != "" and g.user.school != school:
        g.user.school = school
        g.user.save()
        flash("School name changed")

    return redirect(url_for('dashboard'))
Ejemplo n.º 2
0
def dashboard():
    if request.method == "GET":
        team_solves = ChallengeSolve.select(ChallengeSolve, Challenge).join(Challenge).where(ChallengeSolve.team == g.team)
        team_adjustments = ScoreAdjustment.select().where(ScoreAdjustment.team == g.team)
        team_score = sum([i.challenge.points for i in team_solves] + [i.value for i in team_adjustments])
        first_login = False
        if g.team.first_login:
            first_login = True
            g.team.first_login = False
            g.team.save()
        return render_template("dashboard.html", team_solves=team_solves, team_adjustments=team_adjustments, team_score=team_score, first_login=first_login)

    elif request.method == "POST":
        if g.redis.get("ul{}".format(session["team_id"])):
            flash("You're changing your information too fast!")
            return redirect(url_for('dashboard'))

        team_name = request.form["team_name"].strip()
        team_email = request.form["team_email"].strip()
        affiliation = request.form["affiliation"].strip()
        team_elig = "team_eligibility" in request.form

        if len(team_name) > 50 or not team_name:
            flash("You must have a team name!")
            return redirect(url_for('dashboard'))

        if not (team_email and "." in team_email and "@" in team_email):
            flash("You must have a valid team email!")
            return redirect(url_for('dashboard'))

        if not affiliation or len(affiliation) > 100:
            affiliation = "No affiliation"

        email_changed = (team_email != g.team.email)

        g.team.name = team_name
        g.team.email = team_email
        g.team.affiliation = affiliation
        if not g.team.eligibility_locked:
            g.team.eligible = team_elig

        g.redis.set("ul{}".format(session["team_id"]), str(datetime.now()), 120)

        if email_changed:
            if not email.is_valid_email(team_email):
                flash("You're lying")
                return redirect(url_for('dashboard'))

            g.team.email_confirmation_key = misc.generate_confirmation_key()
            g.team.email_confirmed = False

            email.send_confirmation_email(team_email, g.team.email_confirmation_key, g.team.key)
            flash("Changes saved. Please check your email for a new confirmation key.")
        else:
            flash("Changes saved.")
        g.team.save()


        return redirect(url_for('dashboard'))
Ejemplo n.º 3
0
def dashboard():
    if request.method == "GET":
        return render_template("dashboard.html")

    else:
        if g.redis.get("ul{}".format(session["user_id"])):
            flash("too fast!")
            return redirect(url_for('dashboard'))

        user_name = request.form["user_name"].strip()
        user_email = request.form["user_email"].strip()
        email_changed = (user_email != g.user.email)
        name_changed = (user_name != g.user.username)
        if not email_changed and not name_changed:
            flash("nothing changed!")
            return redirect(url_for('dashboard'))
        if name_changed:
            try:
                if (User.get(User.username == user_name)):
                    flash("The name has been used!")
                    return redirect(url_for('dashboard'))
            except User.DoesNotExist:
                pass

            if len(user_name) > 50 or not user_name:
                flash("wrong name format.")
                return redirect(url_for('dashboard'))
        g.user.username = user_name
        g.user.email = user_email

        g.redis.set("ul{}".format(session["user_id"]), str(datetime.now()), config.interval)

        if email_changed:
            if not sendemail.is_valid_email(user_email):
                flash("You are lying")
                return redirect(url_for('dashboard'))
            if not (user_email and "." in user_email and "@" in user_email):
                flash("wrong email format.")
                return redirect(url_for('dashboard'))
            try:
                if (User.get(User.email == user_email)):
                    flash("The email has been used!")
                    return redirect(url_for('dashboard'))
            except User.DoesNotExist:
                pass

            g.user.email_confirmation_key = misc.generate_confirmation_key()
            g.user.email_confirmed = False

            sendemail.send_confirmation_email(user_email, g.user.email_confirmation_key)
            flash("please confirme email")
        else:
            app.logger.info(g.user.username+" changed its infomation.")
            flash("save change.")
        g.user.save()
        return redirect(url_for('dashboard'))
Ejemplo n.º 4
0
def register():
    if not config.registration:
        if "admin" in session and session["admin"]:
            pass
        else:
            return "Registration is currently disabled. Email [email protected] to create an account."

    if request.method == "GET":
        return render_template("register.html")
    elif request.method == "POST":
        error, message = captcha.verify_captcha()
        if error:
            flash(message)
            return render_template("register.html")

        team_name = request.form["team_name"].strip()
        team_email = request.form["team_email"].strip()
        team_elig = "team_eligibility" in request.form
        affiliation = request.form["affiliation"].strip()

        if len(team_name) > 50 or not team_name:
            flash("You must have a team name!")
            return render_template("register.html")

        if not (team_email and "." in team_email and "@" in team_email):
            flash("You must have a valid team email!")
            return render_template("register.html")

        if not affiliation or len(affiliation) > 100:
            affiliation = "No affiliation"

        if not email.is_valid_email(team_email):
            flash("You're lying")
            return render_template("register.html")

        team_key = misc.generate_team_key()
        confirmation_key = misc.generate_confirmation_key()

        team = Team.create(name=team_name,
                           email=team_email,
                           eligible=team_elig,
                           affiliation=affiliation,
                           key=team_key,
                           email_confirmation_key=confirmation_key)
        TeamAccess.create(team=team, ip=misc.get_ip(), time=datetime.now())

        email.send_confirmation_email(team_email, confirmation_key, team_key)

        session["team_id"] = team.id
        flash("Team created.")
        return redirect(url_for('dashboard'))
Ejemplo n.º 5
0
def register():
    if not config.registration:
        if "admin" in session and session["admin"]:
            pass
        else:
            return "Registration is currently disabled. Email [email protected] to create an account."

    if request.method == "GET":
        return render_template("register.html")
    elif request.method == "POST":
        error, message = captcha.verify_captcha()
        if error:
            flash(message)
            return render_template("register.html")

        team_name = request.form["team_name"].strip()
        team_email = request.form["team_email"].strip()
        team_elig = "team_eligibility" in request.form
        affiliation = request.form["affiliation"].strip()

        if len(team_name) > 50 or not team_name:
            flash("You must have a team name!")
            return render_template("register.html")

        if not (team_email and "." in team_email and "@" in team_email):
            flash("You must have a valid team email!")
            return render_template("register.html")

        if not affiliation or len(affiliation) > 100:
            affiliation = "No affiliation"

        if not email.is_valid_email(team_email):
            flash("You're lying")
            return render_template("register.html")

        team_key = misc.generate_team_key()
        confirmation_key = misc.generate_confirmation_key()

        team = Team.create(name=team_name, email=team_email, eligible=team_elig, affiliation=affiliation, key=team_key,
                           email_confirmation_key=confirmation_key)
        TeamAccess.create(team=team, ip=misc.get_ip(), time=datetime.now())

        email.send_confirmation_email(team_email, confirmation_key, team_key)

        session["team_id"] = team.id
        flash("Team created.")
        return redirect(url_for('dashboard'))
Ejemplo n.º 6
0
def forget_pwd():
    if request.method == "GET":
        return render_template("forget_pwd.html")
    else:
        user_name =request.form['user_name']
        try:
            user = User.get(User.username==user_name)
            if user.email_confirmed:
                confirmation_key = misc.generate_confirmation_key()
                #sendemail.send_confirmation_email(user.email, confirmation_key)
                user.email_confirmation_key = confirmation_key
                user.save()
                app.logger.info(user_name+" forgot pwd!")
                flash("The confirmed code has been send to your email")
                return render_template("forget_pwd.html")
            else:
                flash("Your email has not confirmed,you can input the confirmed code in your email")
                return render_template("forget_pwd.html")
        except User.DoesNotExist:
            flash("Not exist!")
            return render_template("forget_pwd.html")
Ejemplo n.º 7
0
def reset_password():
    if "user_id" in session:
        flash("You are already logged in!")
        return redirect(url_for('dashboard'))
    if request.method == "GET":
        return render_template('reset_password.html')

    elif request.method == "POST":
        email = request.form['email'].strip()

    try:
        user = User.get(User.email == email)
        conf_key = misc.generate_confirmation_key()
        user.conf_key = conf_key
        emails.send_reset_email(user.email, user.name, user.conf_key)
        user.save()
        flash("An email with the instructions has been sent to your mail id!")
        return redirect(url_for('reset_password'))

    except User.DoesNotExist:
        flash("No account associated with this email address!")
        return redirect(url_for('reset_password'))
Ejemplo n.º 8
0
def facebook_authorized(resp):
    if resp is None:
        flash("You denied our website access to your facebook data!")
        return render_template('login.html')

    session['oauth_token'] = (resp['access_token'], '')
    me = facebook.get('/me?fields=name,email,verified')
    name = me.data['name'].strip()
    email = me.data['email'].strip()
    verified = me.data['verified']
    try:
        user = User.get(User.email == email)
        session["user_id"] = user.id
        if user.firstsociallogin:
            flash("Please enter all the required details!")
            return redirect(url_for('first_social'))

        flash("So you're back using facebook!")
        return redirect(url_for("dashboard"))

    except User.DoesNotExist:
        if not verified:
            key = misc.generate_confirmation_key()
            emails.send_confirmation_email(email, name, key)
            user = User.create(name=name, email=email, conf_key=key)
            session['user_id'] = user.id
            flash(
                "Ahoy! You're in the system please enter these important details"
            )
            return redirect(url_for('first_social'))
        else:
            user = User.create(name=name, email=email, emailconf=verified)
            session["user_id"] = user.id
            flash(
                "Ahoy! You're in the system please enter these important details"
            )
            return redirect(url_for('first_social'))
Ejemplo n.º 9
0
def register():
    if not config.registration:
        if "admin" in session and session["admin"]:
            pass
        else:
            return "抱歉,现在暂时无法注册。有问题请联系[email protected]"

    if request.method == "GET":
        return render_template("user_register.html")
    else:
        #error, message = captcha.verify_captcha()
        #if error:
            #flash(message)
            #return render_template("user_register.html")

        user_name = request.form["user_name"].strip()
        user_email = request.form["user_email"].strip()
        user_pwd = request.form["user_pwd"].strip()
        pwd_confirmed = request.form["pwd_confirmed"].strip()
        if user_pwd != pwd_confirmed:
            flash("Entered passwords differs")
            return render_template("user_register.html")

        elif not utils.user.check_Password(user_pwd):
            flash("wrong pwd format.")
            return render_template("user_register.html")
		

        try:
            if(User.get(User.username == user_name)):
			    flash("The name has been used!")
			    return render_template("user_register.html")		
        except User.DoesNotExist:		
				pass

        try:
            if(User.get(User.email == user_email)):
			    flash("The email has been used!")
			    return render_template("user_register.html")		
        except User.DoesNotExist:		
				pass
				
        if len(user_name) > 50 or not user_name:
            flash("wrong name format.")
            return render_template("user_register.html")

        if not (user_email and "." in user_email and "@" in user_email):
            flash("wrong email format.")
            return render_template("user_register.html")


        if not sendemail.is_valid_email(user_email):
            flash("You are lying")
            return render_template("user_register.html")
			
        confirmation_key = misc.generate_confirmation_key()
        pwhash = utils.user.create_password(user_pwd.encode())
		
        user = User.create(username=user_name, email=user_email, password=pwhash, 
                           email_confirmation_key=confirmation_key)

        sendemail.send_confirmation_email(user_email, confirmation_key)

        session["user_id"] = user.id
        app.logger.info(user_name+" register successfully.")
        flash("register successfully.")
        return redirect(url_for('dashboard'))
Ejemplo n.º 10
0
def dashboard():
    if request.method == "GET":
        team_solves = ChallengeSolve.select(
            ChallengeSolve,
            Challenge).join(Challenge).where(ChallengeSolve.team == g.team)
        team_adjustments = ScoreAdjustment.select().where(
            ScoreAdjustment.team == g.team)
        team_score = sum([i.challenge.points for i in team_solves] +
                         [i.value for i in team_adjustments])
        first_login = False
        if g.team.first_login:
            first_login = True
            g.team.first_login = False
            g.team.save()
        return render_template("dashboard.html",
                               team_solves=team_solves,
                               team_adjustments=team_adjustments,
                               team_score=team_score,
                               first_login=first_login)

    elif request.method == "POST":
        if g.redis.get("ul{}".format(session["team_id"])):
            flash("You're changing your information too fast!")
            return redirect(url_for('dashboard'))

        team_name = request.form["team_name"].strip()
        team_email = request.form["team_email"].strip()
        affiliation = request.form["affiliation"].strip()
        team_elig = "team_eligibility" in request.form

        if len(team_name) > 50 or not team_name:
            flash("You must have a team name!")
            return redirect(url_for('dashboard'))

        if not (team_email and "." in team_email and "@" in team_email):
            flash("You must have a valid team email!")
            return redirect(url_for('dashboard'))

        if not affiliation or len(affiliation) > 100:
            affiliation = "No affiliation"

        email_changed = (team_email != g.team.email)

        g.team.name = team_name
        g.team.email = team_email
        g.team.affiliation = affiliation
        if not g.team.eligibility_locked:
            g.team.eligible = team_elig

        g.redis.set("ul{}".format(session["team_id"]), str(datetime.now()),
                    120)

        if email_changed:
            if not email.is_valid_email(team_email):
                flash("You're lying")
                return redirect(url_for('dashboard'))

            g.team.email_confirmation_key = misc.generate_confirmation_key()
            g.team.email_confirmed = False

            email.send_confirmation_email(team_email,
                                          g.team.email_confirmation_key,
                                          g.team.key)
            flash(
                "Changes saved. Please check your email for a new confirmation key."
            )
        else:
            flash("Changes saved.")
        g.team.save()

        return redirect(url_for('dashboard'))
Ejemplo n.º 11
0
def register():
    if request.method == "GET":
        return render_template('register.html')

    elif request.method == "POST":
        name = request.form['name'].strip()
        email = request.form['email'].strip()
        password = request.form['password'].strip()
        isAteacher = "teacher" in request.form
        standard = request.form["standard"].strip()
        section = request.form['section'].strip()
        school = request.form['school'].strip()
        key = misc.generate_confirmation_key()

        if not name:
            flash("Please enter a name smarty!")
            return render_template("register.html")

        if not email:
            flash("A valid email id would be appreciated!")
            return render_template("register.html")

        if not password or len(password) < 8:
            flash("Please select a password more than 8 characters!")
            return render_template("register.html")

        if not isAteacher:
            isAteacher = False

        if not standard:
            flash("Please select a standard!")
            return render_template('register.html')

        if not section or len(section) > 1:
            flash("Please enter a valid section!")
            return render_template('register.html')

        if not school:
            flash("Please enter a valid school matey!")
            return render_template('register.html')
        try:
            user = User.get(User.email == email)
            flash(
                "A user with this email id already exsists please login using your credentials"
            )
            return redirect(url_for('login'))

        except User.DoesNotExist:

            try:
                user = User.create(name=name,
                                   email=email,
                                   password=sha512(password).hexdigest(),
                                   isATeacher=isAteacher,
                                   standard=str(standard),
                                   section=section,
                                   school=school,
                                   conf_key=key,
                                   firstsociallogin=False)
                emails.send_confirmation_email(email, name, key)
                session['user_id'] = user.id
                flash("Ahoy! You're registered!")
                return redirect(url_for('dashboard'))

            except:

                return "There was an error in the system <br> Please contact the administrator with the details of the problem at [email protected]"