These are chat archives for FreeCodeCamp/Help

27th
Feb 2018
Skylar
@skyboy1997
Feb 27 2018 01:10
I need help with this section of code. When you hit the login button it redirects that's good but I can type anything in the input field and it will redirect. I just want it to redirect if it matches a username in the database. Thanks for any help!
app.post('/login', function(req, res){
  const client = new Client();
  client.connect()
  .then(() => {
    console.log('Connection Complete');
    const sql = 'SELECT * FROM users WHERE username = $1'
    const params = [req.body.username];
    return client.query(sql, params);
  })
  .then((results) => {
   console.log("User Logged In!");
    res.redirect('/todos');
  })
  .catch((err) => {
    console.log('err', err);
    res.redirect('/login');
   });
});
Stephen James
@sjames1958gm
Feb 27 2018 01:23
@skyboy1997 Are you getting into the second then with just empty results? You might need to check if your results for no match.
An empty query is likely not going to throw an error that is catch'ed
Skylar
@skyboy1997
Feb 27 2018 01:33
@sjames1958gm how would I do this?
Stephen James
@sjames1958gm
Feb 27 2018 01:34
@skyboy1997 I would console.log(results) and see what the contents are when the user is not in the database.
Skylar
@skyboy1997
Feb 27 2018 01:43
@sjames1958gm thats exactly where I get confused at
Stephen James
@sjames1958gm
Feb 27 2018 02:08
@skyboy1997 do the console.log and show the results here and we can go through it
Darren
@DarrenfJ
Feb 27 2018 05:58
evening fCC
Eric Miller
@ericmiller777
Feb 27 2018 06:01
How do you add - Person Prototype - or ---------- to schema for the mongodb challenges?
is it a string?
Eric Miller
@ericmiller777
Feb 27 2018 08:07
well this is what i have
if anyone knows tag me :)
tyvm in advance
var Schema = mongoose.Schema;



var Person = new Schema({
    name:  {type: String, required: true},
    age: Number,
    favoriteFoods: {type: [String]} 
  });
Mukesh Kumar Angrish
@MukeshAngrish
Feb 27 2018 16:33
Hello everyone, I need some help in the Recipe Box app. I'm getting no error in the console or dev tools and I have checked the code multiple times. These are the two problems I'm facing :
  1. The add button on the bottom-left has stopped working. It was working just fine before.
  2. While editing the text, it is not setting the state.
    Please help!
Max
@maxiwer
Feb 27 2018 17:14
Hi coders.
How can I fit these three pictures in prime div?
https://codepen.io/maxiwer/full/Moavoa/
@MukeshAngrish I wish I could help you but I'm 4ukkin' idiot :/
Mukesh Kumar Angrish
@MukeshAngrish
Feb 27 2018 17:21
@Max Haha! why so?
Aditya
@ezioda004
Feb 27 2018 17:22
@maxiwer Quick solution
a, img {
    width: inherit;
}
Max
@maxiwer
Feb 27 2018 17:44
@MukeshAngrish Why am I an idiot?
I don't know dude
@ezioda004 someone said to me to use overflow: hidden;
Aditya
@ezioda004
Feb 27 2018 17:49
@maxiwer That'll only hide the overflowed part of img, so they'll get like cut. Try it yourself.
Christopher McCormack
@cmccormack
Feb 27 2018 17:50
@maxiwer you can simply add width: 100%; to your img css
img {
  width: 100%;
}
Max
@maxiwer
Feb 27 2018 17:50
@ezioda004 @cmccormack thanks
CamperBot
@camperbot
Feb 27 2018 17:50
maxiwer sends brownie points to @ezioda004 and @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 483 | @ezioda004 |http://www.freecodecamp.org/ezioda004
:star2: 1345 | @cmccormack |http://www.freecodecamp.org/cmccormack
Max
@maxiwer
Feb 27 2018 17:52
And now gentlemen, should I consider myself like I've done my challenge?
https://codepen.io/maxiwer/pen/Moavoa
Christopher McCormack
@cmccormack
Feb 27 2018 17:53
@maxiwer check off the user stories, if you have fulfilled then move on :)
Daniel
@dkapexhiu
Feb 27 2018 18:06
why on localhost the redirect if the user is not logged in functions and in online server it does not function?
session_start(); 

$emri = $_SESSION['emri'];
if (!isset($_SESSION['emri'])) {
    $_SESSION['msg'] = "Duhet te logohesh me pare";
    header('location: ../login/login-user.php');
}
Jacob French
@Wingcraftian
Feb 27 2018 19:57

Can anyone help me with this problem Create a function called isAdmin that takes in an object as a parameter. If the object has a property called "admin" that equals true, return a string that equals "Is admin". If the object has a property called "admin" that equals false, return a string that equals "Not admin".
My code atm
function isAdmin(obj){
if("admin"===true){
return "Is admin"
} else if ("admin"===false){
return "Not admin"
};

};

Kyle Holm
@thekholm80
Feb 27 2018 19:59

if your object looks like

obj = {
  admin: true/false
}

then you need to access the admin key, like if (obj.admin)

Christopher McCormack
@cmccormack
Feb 27 2018 20:02
@Wingcraftian also if your properties value is a boolean, you don't need to do a comparison within your if statement, you can just do something like
if (obj.admin) {
    ...
}
Jacob French
@Wingcraftian
Feb 27 2018 20:09
Ok Kyle I don't think I've learned what you're trying to say yet, if you want to expand I would love to listen. Christopher I change the value of the if statement to what you said and it worked. Thank you both
Christopher McCormack
@cmccormack
Feb 27 2018 20:13
@Wingcraftian it only worked because any non-empty string will be true:
> Boolean('admin')
true
> Boolean('')
false
Jacob French
@Wingcraftian
Feb 27 2018 20:15
So does that mean its not working correctly? and its just giving a false positive? @cmccormack
Christopher McCormack
@cmccormack
Feb 27 2018 20:16
@Wingcraftian most likely. As @thekholm80 says - you're not using the obj parameter passed to your function, you're just using the string "admin" in your if statement
Jacob French
@Wingcraftian
Feb 27 2018 20:49
How do you make the black box?
Christopher McCormack
@cmccormack
Feb 27 2018 20:56
@Wingcraftian
```
code
```
Jacob French
@Wingcraftian
Feb 27 2018 20:57
function isAdmin(obj){
if(obj==="admin"){
return "Is admin"
} else if (obj===false){
return "Not admin"
};

};
is this closer?
still wrong obviously but closer?
Christopher McCormack
@cmccormack
Feb 27 2018 21:22
@Wingcraftian we don't really know what you're trying to do nor how you are calling isAdmin
@Wingcraftian if obj is supposed to be an object then this is not correct
Jacob French
@Wingcraftian
Feb 27 2018 21:23
Create a function called isAdmin that takes in an object as a parameter. If the object has a property called "admin" that equals true, return a string that equals "Is admin". If the object has a property called "admin" that equals false, return a string that equals "Not admin". was the problem I was given, was the first thing I linked
Does that help?
Christopher McCormack
@cmccormack
Feb 27 2018 21:28
@Wingcraftian you'll need to review how to access properties of an object again. What you're doing in your code is comparing an object directly with a string
Kyle Holm
@thekholm80
Feb 27 2018 21:29

also, this

If the object has a property

leads me to believe you should be checking for the property, not assuming it will always be there
Jacob French
@Wingcraftian
Feb 27 2018 21:30
isnt that what the if else statement is for?
if its there true if its not false?
Christopher McCormack
@cmccormack
Feb 27 2018 21:30
> var obj = { admin: true }
> obj.admin === true
true
> obj['admin'] === true
true
Daniel
@dkapexhiu
Feb 27 2018 22:07
please someone can help me with this code in php? the page reloads and store the user in db but doesnt redirects the user to the dashboard
<?php include('../server.php') ?>
<?php

// variable declaration
$emri = "";
$password = "";
$errors = array(); 

// LOGIN USER
if (isset($_POST['login'])) {
    $emri = mysqli_real_escape_string($db, $_POST['emri']);
    $password = mysqli_real_escape_string($db, $_POST['password']);

    if (empty($emri)) {
        array_push($errors, "Emri eshte i kerkuar");
    }
    if (empty($password)) {
        array_push($errors, "Passwordi eshte i kerkuar");
    }

    if (count($errors) == 0) {
        $password = md5($password);
        $query = "SELECT * FROM admins WHERE emri='$emri' AND password='$password'";
        $results = $db->query($query);

        if (mysqli_num_rows($results) == 1) {
            $_SESSION['emri'] = $emri;
            if(!isset($_SESSION)) 
            { 
                session_start(); 
            }
            header('location: ../admin-dashboard/admin.php');
        }else {
            array_push($errors, "Kombinim i gabuar i emrit dhe passwordit");
        }
    }
}

?>