Visman 7 年 前
コミット
e37a827baf

+ 4 - 0
app/Controllers/Routing.php

@@ -92,6 +92,10 @@ class Routing
                 $r->add(['GET', 'POST'], '/user/{id:' . $user->id . '}/edit/config',  'Profile:config', 'EditBoardConfig');
                 $r->add(['GET', 'POST'], '/user/{id:' . $user->id . '}/edit/config',  'Profile:config', 'EditBoardConfig');
                 $r->add(['GET', 'POST'], '/user/{id:' . $user->id . '}/change/email', 'Profile:email',  'ChangeUserEmail');
                 $r->add(['GET', 'POST'], '/user/{id:' . $user->id . '}/change/email', 'Profile:email',  'ChangeUserEmail');
             }
             }
+            // смена своего email
+            if (! $user->isGuest) {
+                $r->add('GET', '/user/{id:' . $user->id . '}/{email}/{key}/{hash}', 'Profile:setEmail',  'SetNewEmail');
+            }
             // пометка разделов прочитанными
             // пометка разделов прочитанными
             if (! $user->isGuest) {
             if (! $user->isGuest) {
                 $r->add('GET', '/forum/{id:\d+}/markread/{token}', 'Misc:markread', 'MarkRead');
                 $r->add('GET', '/forum/{id:\d+}/markread/{token}', 'Misc:markread', 'MarkRead');

+ 1 - 0
app/Models/Pages/Auth.php

@@ -257,6 +257,7 @@ class Auth extends Page
         // что-то пошло не так
         // что-то пошло не так
         if (! \hash_equals($args['hash'], $this->c->Secury->hash($args['email'] . $args['key']))
         if (! \hash_equals($args['hash'], $this->c->Secury->hash($args['email'] . $args['key']))
             || ! ($user = $this->c->users->load($args['email'], 'email')) instanceof User
             || ! ($user = $this->c->users->load($args['email'], 'email')) instanceof User
+            || empty($user->activate_string)
             || ! \hash_equals($user->activate_string, $args['key'])
             || ! \hash_equals($user->activate_string, $args['key'])
         ) {
         ) {
             return $this->c->Message->message('Bad request', false);
             return $this->c->Message->message('Bad request', false);

+ 1 - 0
app/Models/Pages/Install.php

@@ -922,6 +922,7 @@ class Install extends Page
             'PRIMARY KEY' => ['id'],
             'PRIMARY KEY' => ['id'],
             'UNIQUE KEYS' => [
             'UNIQUE KEYS' => [
                 'username_idx' => ['username(25)'],
                 'username_idx' => ['username(25)'],
+                'email_idx'    => ['email'],
             ],
             ],
             'INDEXES' => [
             'INDEXES' => [
                 'registered_idx' => ['registered'],
                 'registered_idx' => ['registered'],

+ 64 - 2
app/Models/Pages/Profile.php

@@ -4,6 +4,7 @@ namespace ForkBB\Models\Pages;
 
 
 use ForkBB\Core\Image;
 use ForkBB\Core\Image;
 use ForkBB\Core\Validator;
 use ForkBB\Core\Validator;
+use ForkBB\Core\Exceptions\MailException;
 use ForkBB\Models\Page;
 use ForkBB\Models\Page;
 use ForkBB\Models\User\Model as User;
 use ForkBB\Models\User\Model as User;
 
 
@@ -235,9 +236,41 @@ class Profile extends Page
                     $this->c->users->update($this->curUser);
                     $this->c->users->update($this->curUser);
 
 
                     return $this->c->Redirect->page('EditUserProfile', ['id' => $this->curUser->id])->message('Email changed redirect');
                     return $this->c->Redirect->page('EditUserProfile', ['id' => $this->curUser->id])->message('Email changed redirect');
-                }
-
+                } else {
+                    $key  = $this->c->Secury->randomPass(33);
+                    $hash = $this->c->Secury->hash($this->curUser->id . $v->new_email . $key);
+                    $link = $this->c->Router->link('SetNewEmail', ['id' => $this->curUser->id, 'email' => $v->new_email, 'key' => $key, 'hash' => $hash]);
+                    $tplData = [
+                        'fRootLink' => $this->c->Router->link('Index'),
+                        'fMailer'   => \ForkBB\__('Mailer', $this->c->config->o_board_title),
+                        'username'  => $this->curUser->username,
+                        'link'      => $link,
+                    ];
 
 
+                    try {
+                        $isSent = $this->c->Mail
+                            ->reset()
+                            ->setFolder($this->c->DIR_LANG)
+                            ->setLanguage($this->curUser->language)
+                            ->setTo($v->new_email, $this->curUser->username)
+                            ->setFrom($this->c->config->o_webmaster_email, \ForkBB\__('Mailer', $this->c->config->o_board_title))
+                            ->setTpl('activate_email.tpl', $tplData)
+                            ->send();
+                    } catch (MailException $e) {
+                        $isSent = false;
+                    }
+
+                    if ($isSent) {
+                        $this->curUser->activate_string = $key;
+                        $this->curUser->last_email_sent = \time();
+
+                        $this->c->users->update($this->curUser);
+
+                        return $this->c->Message->message(\ForkBB\__('Activate email sent', $this->c->config->o_admin_email), false, 200);
+                    } else {
+                        return $this->c->Message->message(\ForkBB\__('Error mail', $this->c->config->o_admin_email), true, 200);
+                    }
+                }
             }
             }
 
 
             $this->fIswev = $v->getErrors();
             $this->fIswev = $v->getErrors();
@@ -293,6 +326,35 @@ class Profile extends Page
         return $this;
         return $this;
     }
     }
 
 
+    /**
+     * Изменяет почтовый адрес пользователя по ссылке активации
+     *
+     * @param array $args
+     * @param string $method
+     *
+     * @return Page
+     */
+    public function setEmail(array $args, $method)
+    {
+        if ($this->user->id !== (int) $args['id']
+            || ! \hash_equals($args['hash'], $this->c->Secury->hash($args['id'] . $args['email'] . $args['key']))
+            || empty($this->user->activate_string)
+            || ! \hash_equals($this->user->activate_string, $args['key'])
+        ) {
+            return $this->c->Message->message('Bad request', false);
+        }
+
+        $this->c->Lang->load('profile');
+
+        $this->user->email           = $args['email'];
+        $this->user->email_confirmed = 1;
+        $this->user->activate_string = '';
+
+        $this->c->users->update($this->user);
+
+        return $this->c->Redirect->url($this->user->link)->message('Email changed redirect');
+    }
+
     /**
     /**
      * Дополнительная проверка signature
      * Дополнительная проверка signature
      *
      *

+ 2 - 1
app/Models/Pages/Register.php

@@ -81,7 +81,7 @@ class Register extends Page
             $key     = $this->c->Secury->randomPass(31);
             $key     = $this->c->Secury->randomPass(31);
         } else {
         } else {
             $groupId = $this->c->config->o_default_user_group;
             $groupId = $this->c->config->o_default_user_group;
-            $key     = null;
+            $key     = '';
         }
         }
 
 
         $user = $this->c->users->create();
         $user = $this->c->users->create();
@@ -187,6 +187,7 @@ class Register extends Page
     {
     {
         if (! \hash_equals($args['hash'], $this->c->Secury->hash($args['id'] . $args['key']))
         if (! \hash_equals($args['hash'], $this->c->Secury->hash($args['id'] . $args['key']))
             || ! ($user = $this->c->users->load($args['id'])) instanceof User
             || ! ($user = $this->c->users->load($args['id'])) instanceof User
+            || empty($user->activate_string)
             || ! \hash_equals($user->activate_string, $args['key'])
             || ! \hash_equals($user->activate_string, $args['key'])
         ) {
         ) {
             return $this->c->Message->message('Bad request', false);
             return $this->c->Message->message('Bad request', false);

+ 3 - 3
app/lang/English/mail/activate_email.tpl

@@ -2,11 +2,11 @@ Subject: Change email address requested
 
 
 Hello <username>,
 Hello <username>,
 
 
-You have requested to have a new email address assigned to your account in the discussion forum at <base_url>. If you didn't request this or if you don't want to change your email address you should just ignore this message. Only if you visit the activation page below will your email address be changed. In order for the activation page to work, you must be logged in to the forum.
+You have requested to have a new email address assigned to your account in the discussion forum at <fRootLink>. If you didn't request this or if you don't want to change your email address you should just ignore this message. Only if you visit the activation page below will your email address be changed. In order for the activation page to work, you must be logged in to the forum.
 
 
 To change your email address, please visit the following page:
 To change your email address, please visit the following page:
-<activation_url>
+<link>
 
 
 --
 --
-<board_mailer> Mailer
+<fMailer> Mailer
 (Do not reply to this message)
 (Do not reply to this message)

+ 2 - 1
app/lang/English/mail/welcome.tpl

@@ -4,7 +4,8 @@ Thank you for registering in the forums at <fRootLink>.
 
 
 Your username: <username>
 Your username: <username>
 
 
-Go <link> to activate your account.
+Go link to activate your account:
+<link>
 
 
 --
 --
 <fMailer> Mailer
 <fMailer> Mailer

+ 1 - 1
app/lang/English/profile.po

@@ -91,7 +91,7 @@ msgid "Email updated"
 msgstr "Your email address has been updated."
 msgstr "Your email address has been updated."
 
 
 msgid "Activate email sent"
 msgid "Activate email sent"
-msgstr "An email has been sent to the specified address with instructions on how to activate the new email address. If it doesn\"t arrive you can contact the forum administrator at"
+msgstr "An email has been sent to the specified address with instructions on how to activate the new email address. If it does not arrive you can contact the forum administrator at <a href=\"mailto:%1$s\">%1$s</a>."
 
 
 msgid "Email legend"
 msgid "Email legend"
 msgstr "Enter your new email address"
 msgstr "Enter your new email address"

+ 6 - 6
app/lang/Russian/mail/activate_email.tpl

@@ -1,12 +1,12 @@
-Subject: Запрос на смену e-mail
+Subject: Запрос на смену почтового адреса
 
 
-Здравствуйте <username>,
+Здравствуйте, <username>.
 
 
-Кто-то, возможно вы, сделал запрос на смену e-mail вашего аккаунта на <base_url>. Если это не вы или если вы не хотите менять e-mail, просто проигнорируйте это письмо. Ваш регистрационный e-mail поменяется только если вы посетите активационную ссылку. Чтобы активационная ссылка сработала, необходимо зарегистрироваться на форуме.
+Кто-то, возможно вы, сделал запрос на смену почтового адреса аккаунта на форуме <fRootLink>. Если это не ваш запрос или вы передумали менять почтовый адрес аккаунта, то ни чего не делайте. Ваш почтовый адрес на форуме поменяется только, если вы посетите активационную ссылку. Чтобы активационная ссылка сработала, необходимо войти на форум под своими регистрационными данными.
 
 
-Чтобы поменять адрес e-mail, пожалуйста пройдите по этой ссылке:
-<activation_url>
+Чтобы сменить email адрес, вам нужно перейти по ссылке:
+<link>
 
 
 --
 --
-Отправитель <board_mailer>
+Отправитель <fMailer>
 (Не отвечайте на это сообщение)
 (Не отвечайте на это сообщение)

+ 2 - 1
app/lang/Russian/mail/welcome.tpl

@@ -4,7 +4,8 @@ Subject: Добро пожаловать на <fTitle>!
 
 
 Ваше имя пользователя: <username>
 Ваше имя пользователя: <username>
 
 
-Перейдите по ссылке <link> чтобы активировать аккаунт.
+Перейдите по ссылке, чтобы активировать аккаунт:
+<link>
 
 
 --
 --
 Отправитель <fMailer>
 Отправитель <fMailer>

+ 1 - 1
app/lang/Russian/profile.po

@@ -91,7 +91,7 @@ msgid "Email updated"
 msgstr "Ваш почтовый адрес изменён."
 msgstr "Ваш почтовый адрес изменён."
 
 
 msgid "Activate email sent"
 msgid "Activate email sent"
-msgstr "На указанный почтовый адрес было отправлено письмо с инструкциями по активации новой почты. Если вы не получите письмо, то свяжитесь с администрацией; почтовый адрес для связи"
+msgstr "На указанный почтовый адрес было отправлено письмо с инструкциями по активации новой почты. Если вы не получите его, свяжитесь с администрацией форума по адресу <a href=\"mailto:%1$s\">%1$s</a>."
 
 
 msgid "Email legend"
 msgid "Email legend"
 msgstr "Ввод нового почтового адреса"
 msgstr "Ввод нового почтового адреса"