Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
♻️ Use Gravatar as user profile picture
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 3, 2020
1 parent 86a456d commit 43e8596
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { JwtService } from '@nestjs/jwt';
import { Authenticator } from '@otplib/core';
import { emails, MfaMethod, users } from '@prisma/client';
import { compare, hash } from 'bcrypt';
import { createHash } from 'crypto';
import got from 'got/dist/source';
import anonymize from 'ip-anonymize';
import { authenticator } from 'otplib';
import qrcode from 'qrcode';
Expand Down Expand Up @@ -169,6 +171,18 @@ export class AuthService {
luminosity: 'light',
})}&color=000000`;

for await (const emailString of [email, emailSafe]) {
const md5Email = createHash('md5').update(emailString).digest('hex');
try {
const img = await got(
`https://www.gravatar.com/avatar/${md5Email}?d=404`,
{ responseType: 'buffer' },
);
if (img.body.byteLength > 1)
data.profilePictureUrl = `https://www.gravatar.com/avatar/${md5Email}?d=mp`;
} catch (error) {}
}

const user = await this.prisma.users.create({
data: {
...data,
Expand Down

0 comments on commit 43e8596

Please sign in to comment.