Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- craft()->on('userGroups.onAssignUserToGroups',function(Event $event){
- $user_id = $event->params['userId'];
- $user = craft()->users->getUserById($user_id);
- $userId = craft()->request->getPost('userId');
- $isNewUser = !$userId;
- $email = new EmailModel();
- $emailSettings = craft()->email->getSettings();
- $email->fromEmail = $emailSettings['emailAddress'];
- $email->sender = $emailSettings['emailAddress'];
- if ($isNewUser){
- /* generate random password */
- $randomPassword = $this->getRandomString(8,false);
- /* set random password to user */
- $user->newPassword = $randomPassword;
- if (craft()->users->saveUser($user)){
- $result = "success";
- }else{
- $result = "fail";
- }
- $email->subject = 'confirm created email'
- $email->body = "Text to user".$result;
- $email->toEmail = $user->email;
- craft()->email->sendEmail($email);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement