julianlam / nodebb-plugin-gravatar

Exposes Gravatars to NodeBB users
MIT License
7 stars 9 forks source link

Add md5 for username #13

Closed tony199555 closed 6 years ago

tony199555 commented 6 years ago

Hi, I am using this plugin to fetch avatar from adorable.io. The problem is adorable does not recognize Chinese. Some of our users use Chinese as their username. It would be nice if you could add md5 hash for the username so it is all alphanumeric. Thanks in advance.

julianlam commented 6 years ago

According to this commit https://github.com/julianlam/nodebb-plugin-gravatar/commit/1f0dc07c40b24b1f158be6c2a29dee6eccf8ef2c

It is already available when you specify a custom default. Just use %md5. It will use the email, but it doesn't matter whether you use email or username as the identifier.

tony199555 commented 6 years ago

I am sorry. Can you elaborate a little bit more? Based on the code (I think) it will only md5 hash the email but not the username. Hence if I just put %md5 it will hash email not username. But I want username md5 hash as the identifier. Is something I am missing? Thank you for helping.

julianlam commented 6 years ago

My argument is that it does not matter whether you md5 the username or md5 the email, does it?

tony199555 commented 6 years ago

It is true. But my forum allow user to change email but not username, so the username is the uid as email can be anything. At that case, username would be more preferred to have the consistency. I mean I could PR that changes but I do not have a dev nodebb to test it. It probably look like this:

if (customDefault.indexOf('http') == 0) { //Use explicit check for increased readability.
            customDefault = customDefault.replace(/%umd5/i, sum(username));
        baseUrl += '&d=' + encodeURIComponent(customDefault);

function sum(username) {
    var md5sum = crypto.createHash('md5');
    md5sum.update(username);
    md5sum = md5sum.digest('hex');
    return md5sum;
}
julianlam commented 6 years ago

v2.1.0

tony199555 commented 6 years ago

Super! Thank you very much.

P.S. It seems like it is matching %user than add hash after it... maybe use another variable or make %userhash higher priority?