Example #1
0
def login():
    if loggedin():
        return redirect('/')
        
    unique = {
        "login_saying" : "Welcome to {0}".format(COURSE_NAME),
        "login_details" : "Please log into your profile",
        "extra_class" : ''
    }

    page = generate_page("Login", "login", "")

    if request.method == 'GET':
        redirect_url = request.args.get('redirect', '/')
        return render_template('login.html',**locals())
    else:
        netid = request.form['username']
        uin = request.form['password']
        if not db.verify_user(netid, uin):
            funnies = ['Nuts', 'Good grief', 'Goodness gracious', 'Holy guacamole', 'Aw snap', 'Wholly smokes', 'Dagnabbit']
            second_funny = ['that didn\'t work', 'try again', 'that\'s wrong']
            unique['login_details'] = "{0}; {1}! Please <a href='problems'>fill this out</a> if you cannot log in and <i>are officially registered</i>".format(random.choice(funnies),random.choice(second_funny))
            unique['extra_class'] = 'warning'
            return render_template('login.html', **locals())
        session['netid'] = netid
        redirect_url = request.form['redirect']
        return redirect(redirect_url)
Example #2
0
def request_loader(request):
    if request.form:
        username = request.form["username"]
        if not db.verify_user(username, request.form["password"]):
            # Authenticated failed
            return
        u = db.get_user_by("name", username)
        user = User()
        user.id = u["name"]
        return user
Example #3
0
 def click_login(self):
     db.create_table()
     user = self.lineEdit
     password = self.lineEdit_2
     if db.verify_user(user.text(), password.text(), True):
         redirect_window(self, "MainWindow")
     else:
         self.label_4.setText(
             "Your credentials, are incorrect.\nTry Again.")
         user.setText("")
         password.setText("")
def profile():
    if request.method == "GET":
        username = session['username']
        password = session['password']
        user=db.User(username,{'password':password})
        authenticated = db.verify_reg(user)

        #Authenticate using mongodb
        #if db.users.find({"username": username,"password":password}).count()==1:
        #    authenticated=db.users.find({"username": username,"password":password})[0]["username"]

        if authenticated:
            return render_template("profile.html",loggedin="logged in as: "+authenticated)
        else:
            return redirect("http://localhost:5000/login-register")


    if request.method == "POST":
        username = session['username']
        password = session['password']
        print "username: "******"password: "******"username": username,"password":password}).count()==1:
        #authenticated=db.users.find({"username": username,"password":password})[0]["username"]

        if not authenticated:
            return redirect("http://localhost:5000/login-register")
        else:
            if len(request.form["password"])>1:
                password = request.form["password"]
                user.set_password(user)
                db.users.update_reg(user,False)

                w='''            name=request.form["name"]
            if len(name)>1:
                db.users.update({"username":username,"password":password},{ "$set": { "name": name } })

            state=request.form["state"]
            if len(state)>1:
                db.users.update({"username":username,"password":password},{ '$set': { "state": state } })

            email=request.form["email"]
            if len(email)>1:
                db.users.update({"username":username,"password":password},{ "$set": { "email": email } })'''

            #resp = make_response(redirect("http://localhost:5000/home"))
            session["password"]=password
            return redirect("http://localhost:5000/home")
Example #5
0
 def login(self, environ, start_response):
         content_type = 'text/html'
         formdata = environ['QUERY_STRING']
         results = urlparse.parse_qs(formdata)
         try:
                 name = results['user'][0].strip()
                 passw = results['passw'][0].strip()
         except KeyError:
                 name = ""
                 passw = ""
         if db.verify_user(name,passw)!=False:
             k = str(db.verify_user(name,passw))
             usernames[k] = name
             headers = list(html_headers)
             headers.append(('Location', '/index'))
             headers.append(('Set-Cookie', 'Name=%s' % k))
             start_response('302 Found', headers)
             return ["Redirect to /index..."]
         else:
             headers = list(html_headers)
             headers.append(('Location', '/login'))
             start_response('302 Found', headers)
             return ["Redirect to /login..."]
def home():
    username = session['username']
    password = session['password']
    user=db.User(username,{'password':password})
    authenticated = db.verify_user(user)

    #Authenticate using mongodb
    #if db.users.find({"username": username,"password":password}).count()==1:
    #   authenticated=db.users.find({"username": username,"password":password})[0]["username"]

    if authenticated:
        return render_template("home.html", loggedin="logged in as: "+authenticated)
    else:
        return render_template("home.html",error="You need to be logged in to view this page.")
Example #7
0
def login():
    if request.form:
        # If inputPassword2 field is not empty, this is a registration.
        name = request.form["username"]
        pwrd = request.form["password"]
        # Registration
        if request.form["password2"]:
            # Check for illegal characters in the name
            for x in name:
                if not re.match(r'[A-Za-z0-9_]+$', name):
                    flash(
                        "Your name has an illegal character! Only letters, numbers, and underscores are allowed."
                    )
                    return render_template('login.html')
            if (pwrd != request.form["password2"]):
                flash("Passwords do not match!")
                return render_template('login.html')
            if (len(pwrd) < 6):
                flash("Password must be at least 6 characters.")
                return render_template('login.html')
            if db.get_user_by("username", name):
                flash("User '{}' already exists!".format(name))
                return render_template('login.html')
            else:
                print("New user {} registered!".format(name))
                db.create_user(name, pwrd)
                flash("User created!")
                return render_template('login.html', newuser=True)
        # Validated user
        elif db.verify_user(name, pwrd):
            print(name, "has been verified!")
            user = User()
            user.id = name
            flask_login.login_user(user)
            return redirect("/profile/" + name)
        else:
            flash("Incorrect credentials!")
            return render_template('login.html', page_name="login")
    else:
        return render_template('login.html', page_name="login")
Example #8
0
 def click_signup(self):
     db.create_table()
     user = self.lineEdit.text()
     password = self.lineEdit_2.text()
     if user.isalpha() and password != "":
         if not db.verify_user(user, password):
             password = bcrypt.hashpw(password.encode(), bcrypt.gensalt())
             db.create_user(user, password)
             msg = """User successfully registered!\nYou will be redirected to login screen"""
             QtGui.QMessageBox.question(self, 'Application Message', msg,
                                        QtGui.QMessageBox.Yes)
             redirect_window(self, "LoginWindow")
             return True
         else:
             self.label_4.setText(
                 "This username already exists.\nTry again with other name."
             )
             return False
     else:
         self.label_4.setText(
             "This username can't have only numbers\nand can't be composed only spaces. The password can't be empty."
         )
Example #9
0
def login():
    if loggedin():
        return redirect('/')

    unique = {
        "login_saying": "Welcome to {0}".format(COURSE_NAME),
        "login_details":
        "<a href='go'>Fill out a <i>new</i> form</a> if you cannot log in and <u>are officially registered</u>",
        "extra_class": ''
    }

    page = generate_page(
        "Login", "login", "login",
        "Welcome to CS 196, {0}. You've never before taken a course like this."
        .format(COURSE_NAME))

    if request.method == 'GET':
        redirect_url = request.args.get('redirect', '/')
        return render_template('login.html', **locals())
    else:
        netid = request.form['username']
        uin = request.form['password']
        if not db.verify_user(netid, uin):
            funnies = [
                'Nuts', 'Good grief', 'Goodness gracious', 'Holy guacamole',
                'Aww snap', 'Wholly smokes', 'Dagnabbit'
            ]
            second_funny = ['that didn\'t work', 'try again', 'that\'s wrong']
            unique[
                'login_details'] = "{0}; {1}! Please fill <a href='go'>this</a> out if you can't log in and <b>are officially registered</b>".format(
                    random.choice(funnies), random.choice(second_funny))
            unique['extra_class'] = 'warning'
            return render_template('login.html', **locals())
        session['netid'] = netid
        redirect_url = request.form['redirect']
        return redirect(redirect_url)
Example #10
0
def index():
    if request.form:
        # If inputPassword2 field is not empty, this is a registration.
        name = request.form["username"]
        pwrd = request.form["password"]
        # Registration
        if request.form["password2"]:
            # Check for illegal characters in the name
            for x in name:
                if not re.match(r'[A-Za-z0-9_]+$', name):
                    flash(
                        "Your name has an illegal character! Only letters, numbers, and underscores are allowed."
                    )
                    return render_template('index.html',
                                           page_name="index",
                                           current_user=False)
            if (pwrd != request.form["password2"]):
                flash("Passwords do not match!")
                return render_template('index.html',
                                       page_name="index",
                                       current_user=False)
            if (len(pwrd) < 6):
                flash("Password must be at least 6 characters.")
                return render_template('index.html',
                                       page_name="index",
                                       current_user=False)
            if db.get_user_by("username", name):
                flash("User '{}' already exists!".format(name))
                return render_template('index.html',
                                       page_name="index",
                                       current_user=False)
            else:
                print("New user {} registered!".format(name))
                db.create_user(name, pwrd)
                flash("User created!")
                return render_template('index.html',
                                       page_name="index",
                                       newuser=True,
                                       current_user=False)
        # Validated user
        elif db.verify_user(name, pwrd):
            print(name, "has been verified!")
            user = User()
            user.id = name
            flask_login.login_user(user)
            return redirect("/")
        else:
            flash("Incorrect credentials!")
            return render_template('index.html',
                                   page_name="index",
                                   current_user=False)
    else:
        current_user = flask_login.current_user
        # Structure of threads
        thread = db.get_comments()
        # If the user isn't logged in the id isn't defined
        try:
            current_user.id
        except:
            current_user = None
        return render_template('index.html',
                               page_name="index",
                               current_user=current_user,
                               main_thread=thread)