示例#1
0
 public function authenticate($data)
 {
     $user = User::findByEmail($data->email);
     if (empty($user)) {
         throw new Exception('Такой пользователь не существует', self::ERROR_INVALID_EMAIL);
     }
     if (!\T4\Crypt\Helpers::checkPassword($data->password, $user->password)) {
         throw new Exception('Неверный пароль', self::ERROR_INVALID_PASSWORD);
     }
     $this->login($user);
     Application::getInstance()->user = $user;
     return $user;
 }
 public function up()
 {
     if (!$this->existsTable('__blocks')) {
         $this->createTable('__blocks', ['section' => ['type' => 'int'], 'path' => ['type' => 'string'], 'template' => ['type' => 'string'], 'options' => ['type' => 'text'], 'order' => ['type' => 'int']], [['columns' => ['section']], ['columns' => ['order']]]);
     }
     if (!$this->existsTable('__users')) {
         $this->createTable('__users', ['email' => ['type' => 'string'], 'password' => ['type' => 'string']], [['columns' => ['email']]]);
         $this->createTable('__user_roles', ['name' => ['type' => 'string'], 'title' => ['type' => 'string']], [['type' => 'unique', 'columns' => ['name']]]);
         $this->createTable('__user_roles_to___users', ['__user_id' => ['type' => 'link'], '__role_id' => ['type' => 'link']]);
         $roleAdminId = $this->insert('__user_roles', ['name' => 'admin', 'title' => 'Администратор']);
         $userAdminId = $this->insert('__users', ['email' => '*****@*****.**', 'password' => \T4\Crypt\Helpers::hashPassword('123456')]);
         $this->insert('__user_roles_to___users', ['__user_id' => $userAdminId, '__role_id' => $roleAdminId]);
         $this->createTable('__user_sessions', ['hash' => ['type' => 'string'], '__user_id' => ['type' => 'link'], 'userAgentHash' => ['type' => 'string']], ['hash' => ['columns' => ['hash']], 'user' => ['columns' => ['__user_id']], 'ua' => ['columns' => ['userAgentHash']]]);
     }
 }
示例#3
0
 public function actionChangePassword($id, $password = null)
 {
     $user = User::findByPK($id);
     $this->data->user = $user;
     $this->data->resalt = false;
     if (isset($this->app->request->post['submit'])) {
         if (null == $password) {
             $this->data->message = "Пароль не может быть пустым";
         } else {
             $user->password = \T4\Crypt\Helpers::hashPassword($password);
             $user->save();
             $this->data->message = "Пароль  для " . $user->email . " установлен";
             $this->data->resalt = true;
         }
     }
 }
 public function up()
 {
     if (!$this->existsTable('__blocks')) {
         $this->createTable('__blocks', ['section' => ['type' => 'int'], 'path' => ['type' => 'string'], 'template' => ['type' => 'string'], 'options' => ['type' => 'text'], 'order' => ['type' => 'int']], [['columns' => ['section']], ['columns' => ['order']]]);
     }
     if (!$this->existsTable('__users')) {
         $this->createTable('__users', ['email' => ['type' => 'string'], 'password' => ['type' => 'string']], [['columns' => ['email']]]);
         $adminUserId = $this->insert('__users', ['email' => '*****@*****.**', 'password' => Helpers::hashPassword('DcnfdfqCnhfyfJUhjvyfz!')]);
         $this->createTable('roles', ['name' => ['type' => 'string'], 'title' => ['type' => 'string']], [['columns' => ['name']]]);
         $this->createTable('__users_to_roles', ['__role_id' => ['type' => 'link'], '__user_id' => ['type' => 'link']]);
         $adminRoleId = $this->insert('roles', ['name' => 'admin', 'title' => 'Администраторы']);
         $this->insert('roles', ['name' => 'teacher', 'title' => 'Преподаватели']);
         $this->insert('roles', ['name' => 'student', 'title' => 'Студенты']);
         $this->insert('roles', ['name' => 'applicant', 'title' => 'Соискатели']);
         $this->insert('roles', ['name' => 'employer', 'title' => 'Работодатели']);
         $this->insert('__users_to_roles', ['__role_id' => $adminRoleId, '__user_id' => $adminUserId]);
         $this->createTable('__user_sessions', ['hash' => ['type' => 'string'], '__user_id' => ['type' => 'link'], 'userAgentHash' => ['type' => 'string']], ['hash' => ['columns' => ['hash']], 'user' => ['columns' => ['__user_id']], 'ua' => ['columns' => ['userAgentHash']]]);
     }
 }
 public function up()
 {
     if (!$this->existsTable('__blocks')) {
         $this->createTable('__blocks', ['section' => ['type' => 'int'], 'path' => ['type' => 'string'], 'template' => ['type' => 'string'], 'options' => ['type' => 'text'], 'order' => ['type' => 'int']], [['columns' => ['section']], ['columns' => ['order']]]);
     }
     if (!$this->existsTable('__users')) {
         $this->createTable('__users', ['email' => ['type' => 'string'], 'password' => ['type' => 'string']], [['columns' => ['email']]]);
         $this->createTable('__user_roles', ['name' => ['type' => 'string'], 'title' => ['type' => 'string']], [['type' => 'unique', 'columns' => ['name']]]);
         $this->createTable('__user_roles_to___users', ['__user_id' => ['type' => 'link'], '__role_id' => ['type' => 'link']]);
         $role = new Role();
         $role->name = 'admin';
         $role->title = 'Администратор';
         $role->save();
         $user = new User();
         $user->email = '*****@*****.**';
         $user->password = \T4\Crypt\Helpers::hashPassword('123456');
         $user->roles->append($role);
         $user->save();
         $this->createTable('__user_sessions', ['hash' => ['type' => 'string'], '__user_id' => ['type' => 'link'], 'userAgentHash' => ['type' => 'string']], ['hash' => ['columns' => ['hash']], 'user' => ['columns' => ['__user_id']], 'ua' => ['columns' => ['userAgentHash']]]);
     }
 }
示例#6
0
 public function register($data)
 {
     $errors = new MultiException();
     if (empty($data->email)) {
         $errors->add('Не введен e-mail', self::ERROR_INVALID_EMAIL);
     }
     if (empty($data->password)) {
         $errors->add('Не введен пароль', self::ERROR_INVALID_PASSWORD);
     }
     if (empty($data->password2)) {
         $errors->add('Не введено подтверждение пароля', self::ERROR_INVALID_PASSWORD);
     }
     if ($data->password2 != $data->password) {
         $errors->add('Введенные пароли не совпадают', self::ERROR_INVALID_PASSWORD);
     }
     if (empty($data->firstname)) {
         $errors->add('Не введено имя', self::ERROR_INVALID_FIRSTNAME);
     }
     if (empty($data->lastname)) {
         $errors->add('Не введена фамилия', self::ERROR_INVALID_LASTNAME);
     }
     if (empty($data->phonenum)) {
         $errors->add('Не введен номер телефона', self::ERROR_INVALID_PHONENUM);
     }
     if (!$errors->isEmpty()) {
         throw $errors;
     }
     $user = User::findByEmail($data->email);
     if (!empty($user)) {
         $errors->add('Такой e-mail уже зарегистрирован', self::ERROR_INVALID_EMAIL);
     }
     if (!$errors->isEmpty()) {
         throw $errors;
     }
     $app = Application::getInstance();
     /*if ($app->config->extensions->captcha->register) {
           if (empty($data->captcha)) {
               $errors->add('Не введена строка с картинки', self::ERROR_INVALID_CAPTCHA);
           } else {
               if (!$app->extensions->captcha->checkKeyString($data->captcha)) {
                   $errors->add('Неверные символы с картинки', self::ERROR_INVALID_CAPTCHA);
               }
           }
       }*/
     if (!$errors->isEmpty()) {
         throw $errors;
     }
     $user = new User();
     $user->email = $data->email;
     $user->password = \T4\Crypt\Helpers::hashPassword($data->password);
     $user->save();
     return $user;
 }