From 770f78cbbf815276f26f9b1f971127b086ca501d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=AF=D0=BA=D0=BE=D0=B2=D0=BB=D0=B5=D0=B2?= <vlad309523@gmail.com> Date: Sat, 16 Dec 2017 19:10:33 +0300 Subject: [PATCH] FEAT: notify when email is changed --- .../classes/Controller/Handler/Sign.php | 19 +++++++++++-------- .../classes/Controller/Student/Index.php | 5 +++++ .../classes/Controller/Teacher/Index.php | 5 +++++ ~dev_rating/application/classes/User.php | 3 ++- .../application/views/student/index.twig | 6 ++++++ .../application/views/teacher/index.twig | 6 ++++++ 6 files changed, 35 insertions(+), 9 deletions(-) diff --git a/~dev_rating/application/classes/Controller/Handler/Sign.php b/~dev_rating/application/classes/Controller/Handler/Sign.php index 29a30e4b3..d82247936 100644 --- a/~dev_rating/application/classes/Controller/Handler/Sign.php +++ b/~dev_rating/application/classes/Controller/Handler/Sign.php @@ -127,14 +127,17 @@ class Controller_Handler_Sign extends Controller_Handler $this->fail(); } - if (Model_Account::changeEMail($id, $email)) { - $session = Session::instance(); - $session->set('EMail', $email); - } else { - Log::instance()->add(Log::WARNING, '{0} {1}', array( - '{0}' => 'EMAIL_SIGNIN', - '{1}' => 'Cannot set email ' . $email . ' for user ' . $globalKey . ' ( ' . $id . ' )', - )); + $session = Session::instance(); + if ($session['EMail'] != $email) { + if (Model_Account::changeEMail($id, $email)) { + $session->set('EMail', $email); + $session->set('EMailChanged', true); + } else { + Log::instance()->add(Log::WARNING, '{0} {1}', array( + '{0}' => 'EMAIL_SIGNIN', + '{1}' => 'Cannot set email ' . $email . ' for user ' . $globalKey . ' ( ' . $id . ' )', + )); + } } $this->redirect('/'); diff --git a/~dev_rating/application/classes/Controller/Student/Index.php b/~dev_rating/application/classes/Controller/Student/Index.php index 1a620bc03..b082419c2 100644 --- a/~dev_rating/application/classes/Controller/Student/Index.php +++ b/~dev_rating/application/classes/Controller/Student/Index.php @@ -20,10 +20,15 @@ class Controller_Student_Index extends Controller_Environment_Student $list = Controller_Teacher_Index::getShortListOfTeachers($list); } + $session = Session::instance(); + $EMailChanged = $session['EMailChanged']; + $session->set('EMailChanged', false); + $this->twig->set([ 'Marks' => $marks, 'Disciplines' => $disciplines, 'Teachers' => $teachers, + 'EMailChanged' => $EMailChanged, ])->set_filename(static::TWIG_FOLDER . 'index'); } diff --git a/~dev_rating/application/classes/Controller/Teacher/Index.php b/~dev_rating/application/classes/Controller/Teacher/Index.php index 7b4dd7140..e32d08315 100644 --- a/~dev_rating/application/classes/Controller/Teacher/Index.php +++ b/~dev_rating/application/classes/Controller/Teacher/Index.php @@ -43,12 +43,17 @@ class Controller_Teacher_Index extends Controller_Environment_Teacher } } + $session = Session::instance(); + $EMailChanged = $session['EMailChanged']; + $session->set('EMailChanged', false); + $this->twig->set([ 'Subjects' => $subjects, 'Teachers' => $teachers, 'Groups' => $groups, 'Students' => $students, 'DisciplineCreationISAllowed' => Model_System::loadConfig()->Functional->DisciplineCreation, + 'EMailChanged' => $EMailChanged, ])->set_filename('teacher/index'); } diff --git a/~dev_rating/application/classes/User.php b/~dev_rating/application/classes/User.php index c14f6ab82..7b96595ee 100644 --- a/~dev_rating/application/classes/User.php +++ b/~dev_rating/application/classes/User.php @@ -194,7 +194,8 @@ class User implements ArrayAccess $session->set('PasswordHash', $passwordHash); $session->set('start_time', time()); $session->set('RecordBookID', null); - + $session->set('EMailChanged', false); + foreach ($userInfo as $key => $value) $session->set($key, $value); diff --git a/~dev_rating/application/views/student/index.twig b/~dev_rating/application/views/student/index.twig index 68edf3216..35cd6ce4a 100644 --- a/~dev_rating/application/views/student/index.twig +++ b/~dev_rating/application/views/student/index.twig @@ -59,6 +59,12 @@ {{ HTML.script('static/js/student/index.js')|raw }} <meta name="viewport" content="width=device-width, initial-scale=1.0"> + + {% if EMailChanged %} + <script> + alert('E-Mail быз изменен'); + </script> + {% endif %} {% endblock %} {% block main_content_classes %}sidePadding{% endblock %} diff --git a/~dev_rating/application/views/teacher/index.twig b/~dev_rating/application/views/teacher/index.twig index 9db4345fc..2df525f01 100644 --- a/~dev_rating/application/views/teacher/index.twig +++ b/~dev_rating/application/views/teacher/index.twig @@ -5,6 +5,12 @@ {{ HTML.script('static/js/discipline/disciplineList.js')|raw }} {{ HTML.style('static/css/teacher/index.css')|raw }} {{ HTML.style('static/css/common/buttons.css')|raw }} + + {% if EMailChanged %} + <script> + alert('E-Mail быз изменен'); + </script> + {% endif %} {% endblock %} {% macro outputDiscipline(Discipline, Groups, Teachers, Students, DisciplineCreationISAllowed) %} -- GitLab