Skip to content

Commit

Permalink
Merge pull request #4 from angrybrad/master
Browse files Browse the repository at this point in the history
Fix a bug where new user accounts couldn't be activated because they lose their unverified email value.
  • Loading branch information
hashtagerrors committed Apr 30, 2019
2 parents 5eafc02 + 3ea31bd commit 8fd1df8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/services/UserInitialsPhotoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,21 @@ class UserInitialsPhotoService extends Component

public function assignPhoto($element)
{
$id = $element->id;
$newUser = $element;
$id = $newUser->id;
$users = Craft::$app->getUsers();
$user = $users->getUserById($id);
$existingUser = $users->getUserById($id);
// If user already has a photo do nothing
if($user->getPhoto()){
if ($existingUser && $existingUser->getPhoto()){
return true;
}
$imageUrl = $this->generatePhoto($element);
$email = $user->email;
$imageUrl = $this->generatePhoto($newUser);
$email = $newUser->email;
$filename = strstr($email, '@', true).'.png';
$fileLocation = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename;
$fileContents = file_get_contents($imageUrl);
file_put_contents($fileLocation, $fileContents);
$users->saveUserPhoto($fileLocation, $user, $filename);
$users->saveUserPhoto($fileLocation, $newUser, $filename);
return true;
}

Expand Down

0 comments on commit 8fd1df8

Please sign in to comment.