Blame view

src/app/backend/controllers/PageController.php 2.92 KB
ef60cd4d   Administrator   first commit
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
  <?php
  /**
   * Created by PhpStorm.
   * User: Vitaliy
   * Date: 12.06.14
   * Time: 12:02
   */
  
  namespace controllers;
  
  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
  class PageController extends \Phalcon\Mvc\Controller
  {
      function indexAction()
      {
         $data = \users::findFirst("id = '10'");
          $test = \userToServices::findFirst("user_id = '10'");
          $this->view->setVars([
              'data' => $data,
              'test' => $test
          ]);
      }
  
      function loginAction()
      {
          if($this->request->getPost()) {
              $email          = $this->request->getPost('email', 'email');
              $password       = $this->request->getPost('password', 'string');
              $password       = $this->common->hashPasswd( $password );
              $model = \users::findFirst(array(
                  "email = '$email'",
                  "password => '$password'",
              ));
              if($model instanceof \users) {
                  $this->session->set("user-name", $model->name);
                  $this->session->set("user-status", $model->status);
                  return $this->response->redirect('index_page');
              } else {
                  echo "Пользователя с такими данными не существует";
              }
          }
  
  
          $this->view->setVars([
  
          ]);
  
      }
  
      function logoutAction()
      {
          $this->session->destroy();
          return $this->response->redirect('login_page');
      }
  
      public function downloadImagesAction()
      {
  
          if ($this->request->hasFiles() == true) {
  
              $data['directory'] = $this->request->getPost('directory' );
  
              foreach ($this->request->getUploadedFiles() as $file){
  
                  $allowed_filetypes = array('.jpg','.JPG', '.png', '.PNG', '.gif', '.GIF');
  
                  $ext = substr($file->getName() ,strpos($file->getName() ,'.'),strlen($file->getName() )-1);
  
                  if(!$data['directory']) {
                      $data['directory'] = md5(microtime());
                  }
  
  
                  if(in_array($ext,$allowed_filetypes))
                  {
                      $image_path = $this->storage->getEmailTemplatePath( 'temp', $data['directory']);
  
                      if(!file_exists($image_path))
                      {
                          mkdir( $image_path, 0777, true );
                      }
                      $file->moveTo($image_path.$file->getName());
                      $data['message'] = 'Загрузка файла '.$file->getName().' выполнена успешно.';
                  } else {
                      $data['message'] = 'Произошла ошибка. Не верный формат файла.';
                  }
                  $this->view->disableLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT);
  
  
                  echo json_encode($data);
  
  
              }
          }
      }
  
  
  }