JezerM / web-greeter

A modern, visually appealing greeter for LightDM.
https://web-greeter-page.vercel.app
GNU General Public License v3.0
216 stars 12 forks source link

user.image returning undefined #46

Closed MajliTech closed 2 years ago

MajliTech commented 2 years ago

So, the title says it all. Maybe I will give you my code for refrence.

function getPicOf(user) {
  for (let i in lightdm.users) {
    if (lightdm.users[i].username == user){
      return lightdm.users[i].picture
    }
  }
  return "placeholder.png"
}

So, I runned alert(getPicOf("majlitech")) and it gave me undefined. Can someone tell me what I'm doing wrong? Thanks. Yes, I have a picture on my account.

JezerM commented 2 years ago

You shouldn't use user.picture anymore; this property was deprecated in lightdm-webkit2-greeter and now it's removed from web-greeter and nody-greeter.

Instead, use user.image.

JezerM commented 2 years ago

Also, you should check if the image does actually exists. Some users may not have an image, so your code will always return undefined in those cases.

You could have something like this:

function getPicOf(user) {
  for (let i in lightdm.users) {
    if (lightdm.users[i].username == user && lightdm.users[i].image){
      return lightdm.users[i].image
    }
  }
  return "placeholder.png"
}
MajliTech commented 2 years ago

Thanks for quick response, it's working now.