/** * 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!'); }
/** * 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!'; }
/** * 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; }
/** * Get user profile data as relation of user table. Ex: User::find(1)->getProfile()->nick * @return \Apps\ActiveRecord\Profile */ public function getProfile() { // lets find profile identity via current user id $object = Profile::identity($this->getId()); // is not exist? Hmmm, lets create it! if ($object === null && $this->getId() > 0) { $object = new Profile(); $object->user_id = $this->getId(); $object->save(); } // return result ;) return $object; }