Esempio n. 1
0
def reg():
    if request.method == "POST":
        if RegisteredUser.query.filter(
                RegisteredUser.email == request.form["email"]).first() != None:
            flash("Error: that email is already registered.", "danger")
            return redirect('/')
        reguuid = uuid.uuid1()
        mail = """From: [email protected]\r\nTo: %s\r\nSubject: CSH 5K Email Confirmation\r\n\r\nWelcome to the CSH 5K for charity: water!

To confirm your email address, please click here: http://5k.csh.rit.edu/verify?key=%s&user=%s""" % (
            request.form["email"], reguuid, urllib.quote(
                request.form["email"]))
        try:
            server = smtplib.SMTP("mail.csh.rit.edu")
            server.sendmail("*****@*****.**", [request.form["email"]], mail)
            server.quit()
        except:
            flash(
                "An error occurred sending you an email. Please try again or contact [email protected].",
                "danger")
            return redirect('/')
        newuser = RegisteredUser(email=request.form["email"],
                                 date=datetime.datetime.now(),
                                 reg_uuid=str(reguuid))
        db_session.add(newuser)
        db_session.commit()
        flash("Successfully registered. Please check your email.", "success")
        return redirect('/')
Esempio n. 2
0
def create_user(oauth_token):
    udata = ghobject.get('user', params={'access_token': oauth_token})
    user = User.query.filter(User.username == udata['login']).first()
    if user is None:
        user = User(email=udata.get('email',None), username=udata['login'],
                    github_access_token=None)
        db_session.add(user)
        db_session.commit()
    return user
Esempio n. 3
0
def add_phone():
    if "username" not in session:
        return redirect("/")
    phone = fix_phone(request.form["phone"])
    code = str(random.randint(0, 1000000)).zfill(6)
    project.utils.twilioutil.send_text(phone, "Your queri confirmation code is %s" % code)
    phon = Phone(session["user_id"], phone, code)
    db_session.add(phon)
    db_session.commit()
    flash("Check your phone for a confirmation code.", "success")
    return redirect("/account/phones/")
Esempio n. 4
0
def superadmin_create():
    if request.method == "POST":
        if Admin.query.filter(Admin.username == request.form["username"]).first() != None:
            flash("User already exists.", "danger")
            return redirect('/admin/superadmin/')
        nadmin = Admin(uname=request.form["username"],
                       pwhash=hashlib.sha256(request.form["password"]).hexdigest(),
                       superadmin=("superadmin" in request.form))
        db_session.add(nadmin)
        db_session.commit()
        flash("User successfully created.", "success")
        return redirect('/admin/superadmin/')
    return redirect('/admin/superadmin/')
Esempio n. 5
0
def superadmin_create():
    if request.method == "POST":
        if Admin.query.filter(
                Admin.username == request.form["username"]).first() != None:
            flash("User already exists.", "danger")
            return redirect('/admin/superadmin/')
        nadmin = Admin(uname=request.form["username"],
                       pwhash=hashlib.sha256(
                           request.form["password"]).hexdigest(),
                       superadmin=("superadmin" in request.form))
        db_session.add(nadmin)
        db_session.commit()
        flash("User successfully created.", "success")
        return redirect('/admin/superadmin/')
    return redirect('/admin/superadmin/')
Esempio n. 6
0
def addalias():
    if "username" not in session:
        return redirect("/")
    if request.method == "POST":
        if not "from" in request.form or not "to" in request.form:
            return redirect("/account/alias/")
        if len(request.form["from"]) > 64 or len(request.form["to"]) > 64:
            flash("Alias field too long - max length is 64 characters.", "danger")
            return redirect("/account/alias/")
        if Alias.query.filter((Alias._from == request.form["from"]) & (Alias.uid == session["user_id"])).first() != None:
            flash("Alias 'from' field already used.", "danger")
            return redirect("/account/alias/")
        nalias = Alias(uid=session["user_id"], _from=request.form["from"], to=request.form["to"])
        db_session.add(nalias)
        db_session.commit()
        flash("Your alias was added.", "success")
    return redirect("/account/alias/")
Esempio n. 7
0
def registerrunner():
    if request.method == "POST":
        if not ("name" in request.form and "email" in request.form and "paid" in request.form and "rtype" in request.form):
            flash("Please fill out all the fields.", "danger")
            return render_template("admin_register.html")
        if RegisteredUser.query.filter(RegisteredUser.email == request.form["email"]).first() != None:
            flash("Runner already registered.", "warning")
            return render_template("admin_register.html")
        nrunner = RegisteredUser(date = datetime.datetime.now(),
                name=request.form["name"], email=request.form["email"],
                phone=''.join(c for c in request.form["phone"] if c.isdigit()),
                paid=100*int(request.form["paid"]), verified = True,
                rtype =request.form["rtype"])
        db_session.add(nrunner)
        db_session.commit()
        flash("User successfully created.")
    return render_template("admin_register.html")
Esempio n. 8
0
def get_user_priv(user_name, repo_name):
    if 'username' not in session:
        return 'JHON_DOE'
    priv = db_session.query(UserPrivilege).join(User).join(Project).filter(Project.name == repo_name, User.username == user_name).first()
    if priv is None:
        req_string = 'repos/%s/%s/contributors' % (user_name, repo_name)
        contributors = project.utils.ghobject.get(req_string)
        contributor_unames = [i['login'] for i in contributors]
        project_id = db_session.query(Project).join(User).filter(User.username == user_name).filter(Project.name == repo_name).first().id
        user_id = db_session.query(User).filter(User.username == session['username']).first().id
        if session['username'] in contributor_unames:
            priv = UserPrivilege(project_id, user_id,'CONTRIBUTER')
        else:
            priv = UserPrivilege(project_id, user_id,'JHON_DOE')
        db_session.add(priv)
        db_session.commit()
    return priv.level
Esempio n. 9
0
def process_register():
    if request.method == "POST":
        if request.form["email"] != request.form["email-confirm"]:
            flash("Error: your emails didn't match.", "danger")
        elif request.form["password"] != request.form["password-confirm"]:
            flash("Error: your passwords didn't match.", "danger")
        else:
            if User.query.filter(User.username == request.form["username"]).first() != None:
                flash("Error: that username is already taken.", "danger")
            elif User.query.filter(User.email == request.form["email"]).first() != None:
                flash("Error: that email is already in use.", "danger")
            else:
                for ch in request.form["username"]:
                    if ch not in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_':
                        flash("Error: usernames may only use A-Z, a-z, 0-9, _, and -.", "danger")
                        return redirect("/login/")
                reguuid = uuid.uuid1()
                regmail = sendgrid.Mail()
                regmail.add_to(request.form["email"])
                regmail.set_subject("queri.me registration confirmation")
                regmail.set_from('*****@*****.**')
                regmail.set_text("""Welcome to queri.me!

In order to complete your registration and activate your account, please click
this link to verify your email address: http://queri.me/verifyemail?user=%s&key=%s

-- the queri.me team
""" % (request.form["username"], reguuid))
                try:
                    sgclient.send(regmail)
                except:
                    flash("An error occurred sending your confirmation email. Please try again.", "danger")
                    return render_template("login.html")
                newuser = User(username=request.form["username"], email=request.form["email"],
                        pwhash=hashlib.sha256(request.form["password"]).hexdigest(),
                        reg_uuid=str(reguuid), enabled=False)
                db_session.add(newuser)
                db_session.commit()
                flash("Account successfully created. Please check your email for activation instructions.", "success")
                return redirect('/')
    return render_template("login.html")
Esempio n. 10
0
def registerrunner():
    if request.method == "POST":
        if not ("name" in request.form and "email" in request.form
                and "paid" in request.form and "rtype" in request.form):
            flash("Please fill out all the fields.", "danger")
            return render_template("admin_register.html")
        if RegisteredUser.query.filter(
                RegisteredUser.email == request.form["email"]).first() != None:
            flash("Runner already registered.", "warning")
            return render_template("admin_register.html")
        nrunner = RegisteredUser(date=datetime.datetime.now(),
                                 name=request.form["name"],
                                 email=request.form["email"],
                                 phone=''.join(c for c in request.form["phone"]
                                               if c.isdigit()),
                                 paid=100 * int(request.form["paid"]),
                                 verified=True,
                                 rtype=request.form["rtype"])
        db_session.add(nrunner)
        db_session.commit()
        flash("User successfully created.")
    return render_template("admin_register.html")
Esempio n. 11
0
def reg():
    if request.method == "POST":
        if RegisteredUser.query.filter(RegisteredUser.email ==
                request.form["email"]).first() != None:
            flash("Error: that email is already registered.", "danger")
            return redirect('/')
        reguuid = uuid.uuid1()
        mail = """From: [email protected]\r\nTo: %s\r\nSubject: CSH 5K Email Confirmation\r\n\r\nWelcome to the CSH 5K for charity: water!

To confirm your email address, please click here: http://5k.csh.rit.edu/verify?key=%s&user=%s""" % (request.form["email"], reguuid, urllib.quote(request.form["email"]))
        try:
            server = smtplib.SMTP("mail.csh.rit.edu")
            server.sendmail("*****@*****.**", [request.form["email"]], mail)
            server.quit()
        except:
            flash("An error occurred sending you an email. Please try again or contact [email protected].", "danger")
            return redirect('/')
        newuser = RegisteredUser(email=request.form["email"],
                date=datetime.datetime.now(), reg_uuid = str(reguuid))
        db_session.add(newuser)
        db_session.commit()
        flash("Successfully registered. Please check your email.", "success")
        return redirect('/')
Esempio n. 12
0
def create_organization(orgname):
    org = User.query.filter(User.username == orgname).first()
    if org is None:
        udata = ghobject.get('orgs/%s' % (orgname))
        org = User(email=udata.get('email',None), username=udata['login'], github_access_token=None)
        db_session.add(org)