doAuthMailer.php 2.87 KB
Newer Older
Яков's avatar
first  
Яков committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
 * Listener for doAuthActions, recives notifies and sends emails
 *
 * @author Davert
 */
class doAuthMailer {

  public static function sendActivation(sfEvent $event) {

    $controller = $event->getSubject();
    $user = $controller->user;

    // already activated
    if ($user->getIsActive()) return;

    // save password to send in register email
    $controller->getUser()->setAttribute('user_password',$event['password'],'doPreUser');

    $activation = new UserActivationCode();
    $activation->setUserId($user->getId());
    $activation->setCode(doAuthTools::activationCode($user));
    $activation->save();

    $subject = 'Активация аккаунта';

    // message should be sent immediately 
    $controller->getMailer()->composeAndSend(
      sfConfig::get('app_doAuth_email_from','do-not-reply@'.$controller->getRequest()->getHost()),
      array($user->getEmail()),
      $subject,
      $controller->getPartial(sfConfig::get('app_doAuth_email_module',$controller->getModuleName()).'/mail_activation', array('code'=> $activation->getCode())),'text/plain');
  }

  public static function sendRegistration(sfEvent $event) {

    $controller = $event->getSubject();
    $user = $controller->user;
    $password = $event->offsetExists('password') ? $event['password'] : $controller->getUser()->getAttribute('user_password',null,'doPreUser');

    $subject = 'Спасибо за регистрацию';

    // message should be sent immediately
    $controller->getMailer()->composeAndSend(
      sfConfig::get('app_doAuth_email_from','do-not-reply@'.$controller->getRequest()->getHost()),
      array($user->getEmail()),
      $subject,
      $controller->getPartial(sfConfig::get('app_doAuth_email_module',$controller->getModuleName()).'/mail_registration', array('user'=> $controller->user, 'password'=> $password)),'text/plain');
  }

  public static function sendPasswordRequest($controller, User $user) {

    $subject = 'Сброс пароля';

    $code = doAuthTools::passwordResetCode($user);

    $controller->getMailer()->composeAndSend(
      sfConfig::get('app_doAuth_email_from','do-not-reply@'.$controller->getRequest()->getHost()),
      array($user->getEmail()),
      $subject,
      $controller->getPartial(sfConfig::get('app_doAuth_email_module',$controller->getModuleName()).'/mail_reset_password', array('user'=> $user, 'code'=> $code)),'text/plain');
  }

  public static function sendNewPassword($controller, User $user, $password) {

    $subject = 'Новый пароль';

    $controller->getMailer()->composeAndSend(
      sfConfig::get('app_doAuth_email_from','do-not-reply@'.$controller->getRequest()->getHost()),
      array($user->getEmail() ),
      $subject,
      $controller->getPartial(sfConfig::get('app_doAuth_email_module',$controller->getModuleName()).'/mail_new_password', array('user'=> $user, 'password'=> $password)),'text/plain');
  }
  
}
?>