Browse Source

Update Login, Registration and Mail send page for log

Visman 4 years ago
parent
commit
a28e4552fe
3 changed files with 62 additions and 10 deletions
  1. 9 6
      app/Models/Pages/Auth.php
  2. 23 2
      app/Models/Pages/Email.php
  3. 30 2
      app/Models/Pages/Register.php

+ 9 - 6
app/Models/Pages/Auth.php

@@ -74,10 +74,6 @@ class Auth extends Page
             if ($v->validation($_POST, true)) {
             if ($v->validation($_POST, true)) {
                 $this->loginEnd($v);
                 $this->loginEnd($v);
 
 
-                $this->c->Log->info('Login', [
-                    'user' => $this->userAfterLogin->fLog(),
-                ]);
-
                 return $this->c->Redirect->url($v->redirect)->message('Login redirect');
                 return $this->c->Redirect->url($v->redirect)->message('Login redirect');
             }
             }
 
 
@@ -123,6 +119,12 @@ class Auth extends Page
 
 
         $this->c->Online->delete($this->user);
         $this->c->Online->delete($this->user);
         $this->c->Cookie->setUser($this->userAfterLogin, (bool) $v->save);
         $this->c->Cookie->setUser($this->userAfterLogin, (bool) $v->save);
+
+        $this->c->Log->info('Login', [
+            'user'    => $this->userAfterLogin->fLog(),
+            'form'    => $v->getData(false, ['token', 'password']),
+            'headers' => true,
+        ]);
     }
     }
 
 
     /**
     /**
@@ -229,8 +231,9 @@ class Auth extends Page
             $v       = $this->c->Test->beforeValidation($v);
             $v       = $this->c->Test->beforeValidation($v);
             $isValid = $v->validation($_POST, true);
             $isValid = $v->validation($_POST, true);
             $context = [
             $context = [
-                'user' => $this->user->fLog(), // ???? Guest only?
-                'form' => $v->getData(false, ['token']),
+                'user'    => $this->user->fLog(), // ???? Guest only?
+                'form'    => $v->getData(false, ['token']),
+                'headers' => true,
             ];
             ];
 
 
             if ($isValid) {
             if ($isValid) {

+ 23 - 2
app/Models/Pages/Email.php

@@ -30,13 +30,19 @@ class Email extends Page
     {
     {
         $this->curUser = $this->c->users->load((int) $args['id']);
         $this->curUser = $this->c->users->load((int) $args['id']);
 
 
-        if (! $this->curUser instanceof User || $this->curUser->isGuest) {
+        if (
+            ! $this->curUser instanceof User
+            || $this->curUser->isGuest
+        ) {
             return $this->c->Message->message('Bad request');
             return $this->c->Message->message('Bad request');
         }
         }
 
 
         $rules = $this->c->ProfileRules->setUser($this->curUser);
         $rules = $this->c->ProfileRules->setUser($this->curUser);
 
 
-        if (! $rules->viewEmail || ! $rules->sendEmail) {
+        if (
+            ! $rules->viewEmail
+            || ! $rules->sendEmail
+        ) {
             $message = null === $rules->sendEmail ? 'Form email disabled' : 'Bad request';
             $message = null === $rules->sendEmail ? 'Form email disabled' : 'Bad request';
 
 
             return $this->c->Message->message($message);
             return $this->c->Message->message($message);
@@ -86,9 +92,19 @@ class Email extends Page
                             $this->c->users->update($this->user);
                             $this->c->users->update($this->user);
                         }
                         }
 
 
+                        $this->c->Log->info('Email sent', [
+                            'user'      => $this->user->fLog(),
+                            'recipient' => $this->curUser->fLog(),
+                        ]);
+
                         return $this->c->Redirect->url($v->redirect)->message('Email sent redirect');
                         return $this->c->Redirect->url($v->redirect)->message('Email sent redirect');
                     }
                     }
                 } catch (MailException $e) {
                 } catch (MailException $e) {
+                    $this->c->Log->error('Email send MailException', [
+                        'user'      => $this->user->fLog(),
+                        'exception' => $e,
+                        'headers'   => false,
+                    ]);
                 }
                 }
 
 
                 return $this->c->Message->message('When sending email there was an error');
                 return $this->c->Message->message('When sending email there was an error');
@@ -96,6 +112,11 @@ class Email extends Page
 
 
             $this->fIswev = $v->getErrors();
             $this->fIswev = $v->getErrors();
             $data         = $v->getData();
             $data         = $v->getData();
+
+            $this->c->Log->warning('Email send form failed', [
+                'user'      => $this->user->fLog(),
+                'recipient' => $this->curUser->fLog(),
+            ]);
         }
         }
 
 
         $this->nameTpl   = 'email';
         $this->nameTpl   = 'email';

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

@@ -59,6 +59,11 @@ class Register extends Page
 
 
         $this->fIswev = $v->getErrors();
         $this->fIswev = $v->getErrors();
 
 
+        $this->c->Log->warning('Registration failed', [
+            'user' => $this->user->fLog(),
+            'form' => $v->getData(false, ['token', 'password']),
+        ]);
+
         // нет согласия с правилами
         // нет согласия с правилами
         if (isset($this->fIswev['cancel'])) {
         if (isset($this->fIswev['cancel'])) {
             return $this->c->Message->message('Reg cancel', true, 403);
             return $this->c->Message->message('Reg cancel', true, 403);
@@ -165,6 +170,12 @@ class Register extends Page
 
 
         $newUserId = $this->c->users->insert($user);
         $newUserId = $this->c->users->insert($user);
 
 
+        $this->c->Log->info('Registriaton', [
+            'user'    => $user->fLog(),
+            'form'    => $v->getData(false, ['token', 'password']),
+            'headers' => true,
+        ]);
+
         // уведомление о регистрации
         // уведомление о регистрации
         if (
         if (
             '1' == $this->c->config->o_regs_report
             '1' == $this->c->config->o_regs_report
@@ -197,7 +208,11 @@ class Register extends Page
                     ->setTpl('new_user.tpl', $tplData)
                     ->setTpl('new_user.tpl', $tplData)
                     ->send();
                     ->send();
             } catch (MailException $e) {
             } catch (MailException $e) {
-            //????
+                $this->c->Log->error('Registration notification to admins MailException', [
+                    'user'      => $user->fLog(),
+                    'exception' => $e,
+                    'headers'   => false,
+                ]);
             }
             }
         }
         }
 
 
@@ -234,7 +249,11 @@ class Register extends Page
                     ->setTpl('welcome.tpl', $tplData)
                     ->setTpl('welcome.tpl', $tplData)
                     ->send();
                     ->send();
             } catch (MailException $e) {
             } catch (MailException $e) {
-                $isSent = false;
+                $this->c->Log->error('Registration activation email MailException', [
+                    'user'      => $user->fLog(),
+                    'exception' => $e,
+                    'headers'   => false,
+                ]);
             }
             }
 
 
             // письмо активации аккаунта отправлено
             // письмо активации аккаунта отправлено
@@ -268,6 +287,11 @@ class Register extends Page
             || empty($user->activate_string)
             || empty($user->activate_string)
             || ! \hash_equals($user->activate_string, $args['key'])
             || ! \hash_equals($user->activate_string, $args['key'])
         ) {
         ) {
+            $this->c->Log->warning('Account activation failed', [
+                'user' => $user instanceof User ? $user->fLog() : $this->user->fLog(),
+                'args' => $args,
+            ]);
+
             return $this->c->Message->message('Bad request', false);
             return $this->c->Message->message('Bad request', false);
         }
         }
 
 
@@ -277,6 +301,10 @@ class Register extends Page
 
 
         $this->c->users->update($user);
         $this->c->users->update($user);
 
 
+        $this->c->Log->info('Account activated', [
+            'user' => $user->fLog(),
+        ]);
+
         $this->c->Lang->load('register');
         $this->c->Lang->load('register');
 
 
         $auth         = $this->c->Auth;
         $auth         = $this->c->Auth;