Advertisement
Guest User

Untitled

a guest
Jul 13th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. craft()->on('userGroups.onAssignUserToGroups',function(Event $event){
  2. $user_id = $event->params['userId'];
  3. $user = craft()->users->getUserById($user_id);
  4. $userId = craft()->request->getPost('userId');
  5. $isNewUser = !$userId;
  6.  
  7. $email = new EmailModel();
  8. $emailSettings = craft()->email->getSettings();
  9. $email->fromEmail = $emailSettings['emailAddress'];
  10. $email->sender = $emailSettings['emailAddress'];
  11.  
  12. if ($isNewUser){
  13. /* generate random password */
  14. $randomPassword = $this->getRandomString(8,false);
  15. /* set random password to user */
  16. $user->newPassword = $randomPassword;
  17. if (craft()->users->saveUser($user)){
  18. $result = "success";
  19. }else{
  20. $result = "fail";
  21. }
  22. $email->subject = 'confirm created email'
  23. $email->body = "Text to user".$result;
  24. $email->toEmail = $user->email;
  25. craft()->email->sendEmail($email);
  26. }
  27. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement