Esempio n. 1
0
def login():
    defenses.setup(request, response)
    csrftoken = defenses.csrfDefense.init(request, response)
    defenses.csrfDefense.validate(request, csrftoken)
    username = request.forms.get("username")
    password = request.forms.get("password")
    if not database.validateUser(username, password):
        raise HTTPError(403, "Login unsuccessful")
    response.set_cookie("authuser", username, authSecret, httponly=True)
    redirect("./")
Esempio n. 2
0
 def login(self):
     if database.validateUser(self.txt_username.get(),
                              self.txt_password.get()):
         print("Logged in as : ", self.txt_username.get(),
               self.txt_password.get())
         dash = dashboard.Dashboard()
         dash.mainloop()
     else:
         print("Not a user.")
         msg.showerror(messages.login_error[0], messages.login_error[1])
Esempio n. 3
0
def login():
    error = None
    if request.method == "POST":
        username = request.form["username"]
        password = request.form["password"]
        if(database.validateUser(username,password) == False):
            error = 'Unregistered username or incorrect password'
            return redirect(url_for('login'))
        session['username'] = request.form['username']
        return redirect(url_for('home'))
    return render_template("login.html")
Esempio n. 4
0
def login():
    error = None
    if request.method == "POST":
        username = request.form["username"]
        password = request.form["password"]
        if (database.validateUser(username, password) == False):
            error = 'Unregistered username or incorrect password'
            return redirect(url_for('login'))
        session['username'] = request.form['username']
        return redirect(url_for('home'))
    return render_template("login.html")
Esempio n. 5
0
def authenticate():
    content = request.json
    if all(keys in content
           for keys in ('username', 'password')) and len(content) == 2:
        auth = db.validateUser(content)
        return jsonify({
            'status':
            'success' if auth['found'] and auth['auth'] else 'failure',
            'userId':
            auth['userID']
        })
    # jsonify({'status': 'unable to create account'}),
    return Response(status=400)
Esempio n. 6
0
def login():
    try:
        email = request.form['email']
        password = request.form['password']
    except:
        return response('', 400)

    if not database.validateUser(email, password):
        error = 'Error: Incorrect username or password'
    else:
        session['user'] = email
        flash('Success: Logging in')
        return redirect(url_for('mysite.index'))

    return render_template('login.html', error=error)
Esempio n. 7
0
def login():
    if request.method=="GET":
        return render_template("login.html")
    else:
        username = request.form["username"]
        password = request.form["password"]
        button = request.form["b"]
        if button == "Login":
            if(database.validateUser(username,password) == False):
                error = 'Unregistered username or incorrect password'
                return redirect(url_for('login'))
            flash("You've logged in successfully")
            session['username'] = request.form['username']
            gender = "male"
            age = 42
            return render_template("user.html", username = username, gender = gender, age = age)
        else:
            return redirect(url_for('register'))
Esempio n. 8
0
def create():
    defenses.setup(request, response)
    csrftoken = defenses.csrfDefense.init(request, response)
    defenses.csrfDefense.validate(request, csrftoken)
    username = request.forms.get("username")
    password = request.forms.get("password")
    if not username or not password:
        raise HTTPError(400, "Required field is empty")
    if not re.match("[A-Za-z0-9]+$", username):
        raise HTTPError(400, "Invalid username")
    if database.fetchUser(username):
        raise HTTPError(400, "User already exists")
    if len(password) < 4:
        raise HTTPError(400, "Password too short")
    database.createUser(username, password)
    if not database.validateUser(username, password):
        raise HTTPError(403, "Account creation unsuccessful")
    response.set_cookie("authuser", username, authSecret, httponly=True)
    redirect("./")
Esempio n. 9
0
def login(create=False):
    defenses.setup(request, response)
    csrftoken = defenses.csrfDefense.init(request, response)
    defenses.csrfDefense.validate(request, csrftoken)
    username = request.forms.get("username")
    password = request.forms.get("password")
    if not username or not password:
        raise HTTPError(400, "Required field is empty")
    if not re.match("[A-Za-z0-9]+$", username):
        raise HTTPError(400, "Invalid username")
    if create:
        if database.fetchUser(username):
            raise HTTPError(400, "User already exists")
        if len(password) < 4:
            raise HTTPError(400, "Password too short")
        database.createUser(username, password)
    if not database.validateUser(username, password):
        raise HTTPError(403, "Login unsuccessful")
    response.set_cookie("authuser", username, authSecret, httponly=True)
    redirect("./")
Esempio n. 10
0
    def post(self):
        try:
            payload = json.loads(request.data)
            username = payload["username"]
            password = payload["password"]

            data = database.validateUser(username)
            if data:
                print("data role..", data['roleid'])
                if data['password'] == password:
                    role = database.getRole(data['roleid'])
                    token = jwt.encode({'user': username, 'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=30), 'role':role['role']},app.config['SECRET_KEY'])
                    # return jsonify({'token':jwt.decode(token,app.config['SECRET_KEY'],algorithms="HS256")})
                    return jsonify({'token':token})


            return make_response('could not verify!', 401, {'WWW-Authenticate': 'Basic realm="Login Required" '})


        except Exception as e:
            return  make_response('error: ',e)