Exemplo n.º 1
0
 /**
  * Save configurations build by installer interface
  */
 public function make()
 {
     // prepare configurations to save
     /** @var array $cfg */
     $cfg = App::$Properties->getAll('default');
     $this->before();
     $cfg['baseDomain'] = $this->baseDomain;
     $cfg['database'] = $this->db;
     $cfg['adminEmail'] = $this->email;
     $cfg['singleLanguage'] = $this->singleLanguage;
     $cfg['multiLanguage'] = (bool) $this->multiLanguage;
     $cfg['passwordSalt'] = '$2a$07$' . Str::randomLatinNumeric(mt_rand(21, 30)) . '$';
     $cfg['debug']['cookie']['key'] = 'fdebug_' . Str::randomLatinNumeric(mt_rand(4, 16));
     $cfg['debug']['cookie']['value'] = Str::randomLatinNumeric(mt_rand(32, 128));
     // import database tables
     $connectName = 'install';
     include root . '/Private/Database/install.php';
     // insert admin user
     $user = new User();
     $user->setConnection('install');
     $user->login = $this->user['login'];
     $user->email = $this->user['email'];
     $user->role_id = 4;
     $user->password = App::$Security->password_hash($this->user['password'], $cfg['passwordSalt']);
     $user->save();
     $profile = new Profile();
     $profile->setConnection('install');
     $profile->user_id = $user->id;
     $profile->save();
     // set installation version
     $system = new System();
     $system->setConnection('install');
     $system->var = 'version';
     $system->data = Version::VERSION;
     $system->save();
     // write config data
     App::$Properties->writeConfig('default', $cfg);
     // make routing configs based on preset property
     $routing = [];
     switch ($this->mainpage) {
         case 'news':
             $routing = ['Alias' => ['Front' => ['/' => '/content/list/news', '/about' => '/content/read/page/about-page']]];
             break;
         case 'about':
             $routing = ['Alias' => ['Front' => ['/' => '/content/read/page/about-page']]];
             break;
     }
     // write routing configurations
     App::$Properties->writeConfig('routing', $routing);
     // write installer lock
     File::write('/Private/Install/install.lock', 'Installation is locked!');
 }
Exemplo n.º 2
0
 /**
  * Add user in database
  * @return string
  * @throws NativeException
  */
 public function actionAdduser()
 {
     echo "Login:"******"Email:";
     $email = Console::$Input->read();
     if (!Str::isEmail($email)) {
         throw new NativeException('Email is bad');
     }
     echo "Password:"******"RoleId (1 = onlyread, 2 = user, 3 = moderator, 4 = admin):";
     $role = (int) Console::$Input->read();
     if (!Arr::in($role, [1, 2, 3, 4])) {
         $role = 2;
     }
     if (User::isMailExist($email) || User::isLoginExist($login)) {
         throw new NativeException('User with this email or login is always exist');
     }
     $salt = Console::$Properties->get('passwordSalt');
     $user = new User();
     $user->login = $login;
     $user->email = $email;
     $user->password = Security::password_hash($pass, $salt);
     $user->role_id = $role;
     $user->save();
     $profile = new Profile();
     $profile->user_id = $user->id;
     $profile->save();
     return 'User was successful added to database!';
 }
Exemplo n.º 3
0
 /**
  * Edit user profile by id
  * @param int $id
  * @return string
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws \Ffcms\Core\Exception\SyntaxException
  */
 public function actionUpdate($id)
 {
     $user = UserRecords::findOrNew($id);
     // generate model data based on user object
     $model = new FormUserUpdate($user);
     // check is form is sended
     if ($model->send()) {
         if ($model->validate()) {
             // check validation
             $model->save();
             App::$Session->getFlashBag()->add('success', __('Data was successful updated'));
         } else {
             App::$Session->getFlashBag()->add('error', __('Form validation is failed'));
         }
     }
     // render viewer
     return $this->view->render('user_update', ['model' => $model]);
 }
Exemplo n.º 4
0
 /**
  * Try to insert user data in database
  * @param bool $activation
  * @return bool
  * @throws \Ffcms\Core\Exception\SyntaxException
  * @throws \Ffcms\Core\Exception\NativeException
  */
 public function tryRegister($activation = false)
 {
     $check = App::$User->where('login', '=', $this->login)->orWhere('email', '=', $this->email)->count();
     if ($check !== 0) {
         return false;
     }
     $password = App::$Security->password_hash($this->password);
     // create row
     $user = new User();
     $user->login = $this->login;
     $user->email = $this->email;
     $user->password = $password;
     // if need to be approved - make random token and send email
     if ($activation) {
         $user->approve_token = Str::randomLatinNumeric(mt_rand(32, 128));
         // random token for validation url
         // send email
         $template = App::$View->render('user/mail/approve', ['token' => $user->approve_token, 'email' => $user->email, 'login' => $user->login]);
         $sender = App::$Properties->get('adminEmail');
         // format SWIFTMailer format
         $mailMessage = \Swift_Message::newInstance(App::$Translate->get('Default', 'Registration approve', []))->setFrom([$sender])->setTo([$this->email])->setBody($template, 'text/html');
         // send message
         App::$Mailer->send($mailMessage);
     }
     // save row
     $user->save();
     // create profile
     $profile = new Profile();
     $profile->user_id = $user->id;
     // save profile
     $profile->save();
     // set user & profile objects to attributes to allow extending this model
     $this->_userObject = $user;
     $this->_profileObject = $profile;
     return true;
 }
Exemplo n.º 5
0
 /**
  * Get user identity for current object
  * @return User|null
  */
 public function User()
 {
     return User::identity($this->user_id);
 }
Exemplo n.º 6
0
 /**
  * Build content data to model properties
  * @param $records
  * @throws ForbiddenException
  * @throws NotFoundException
  */
 private function buildContent($records)
 {
     $nullItems = 0;
     foreach ($records as $row) {
         /** @var Content $row */
         // check title length on current language locale
         $localeTitle = $row->getLocaled('title');
         if (Str::likeEmpty($localeTitle)) {
             ++$nullItems;
             continue;
         }
         // get snippet from full text for current locale
         $text = Text::snippet($row->getLocaled('text'));
         $itemPath = $this->categories[$row->category_id]->path;
         if (!Str::likeEmpty($itemPath)) {
             $itemPath .= '/';
         }
         $itemPath .= $row->path;
         // prepare tags data
         $tags = $row->getLocaled('meta_keywords');
         if (!Str::likeEmpty($tags)) {
             $tags = explode(',', $tags);
         } else {
             $tags = null;
         }
         $owner = App::$User->identity($row->author_id);
         // make a fake if user is not exist over id
         if ($owner === null) {
             $owner = new User();
         }
         // check if current user can rate item
         $ignoredRate = App::$Session->get('content.rate.ignore');
         $canRate = true;
         if (Obj::isArray($ignoredRate) && Arr::in((string) $row->id, $ignoredRate)) {
             $canRate = false;
         }
         if (!App::$User->isAuth()) {
             $canRate = false;
         } elseif ($owner->getId() === App::$User->identity()->getId()) {
             // own item
             $canRate = false;
         }
         // build result array
         $this->items[] = ['id' => $row->id, 'title' => $localeTitle, 'text' => $text, 'date' => Date::humanize($row->created_at), 'updated' => $row->updated_at, 'author' => $owner, 'poster' => $row->getPosterUri(), 'thumb' => $row->getPosterThumbUri(), 'thumbSize' => File::size($row->getPosterThumbUri()), 'views' => (int) $row->views, 'rating' => (int) $row->rating, 'canRate' => $canRate, 'category' => $this->categories[$row->category_id], 'uri' => '/content/read/' . $itemPath, 'tags' => $tags];
     }
     if ($nullItems === $this->_contentCount) {
         throw new NotFoundException(__('Content is not founded'));
     }
 }
Exemplo n.º 7
0
 /**
  * Check if new login is always exist
  * @param string $login
  * @param int|null $userId
  * @return bool
  */
 public static function isUniqueLogin($login, $userId = null)
 {
     $find = User::where('login', '=', $login);
     if ($userId !== null && Obj::isLikeInt($userId)) {
         $find->where('id', '!=', $userId);
     }
     return $find->count() === 0;
 }