Beispiel #1
0
 public function register()
 {
     $signedUser = $this->app->user();
     // auth
     if (Util\Auth::isAuth($signedUser)) {
         header('Location: /profile');
         exit;
     }
     // check
     $user = new \Rebond\Core\User\Model();
     $form = new \Rebond\Core\User\Form($user);
     $tpl = new Util\Template(Util\Template::MODULE, ['app', 'User']);
     // register
     $register = Util\Converter::toString('register', 'post');
     if (isset($register)) {
         if ($form->setFromPost()->validate(['username', 'email', 'password'])->isValid()) {
             $user->setStatus(0);
             $user->setPassword(Util\Security::encryptPassword($user->getPassword()));
             $resultUpload = Util\Media::upload($user->getUsername());
             if ($resultUpload['result'] == ResultType::ERROR) {
                 Util\Session::set('siteError', $resultUpload['message']);
             } else {
                 if ($resultUpload['result'] == ResultType::SUCCESS) {
                     $user->setAvatarId($resultUpload['mediaId']);
                 }
                 $user->save();
             }
             // send email
             if (Mail::register($this->app->site()->getTitle(), $user)) {
                 return $tpl->render('register-success');
             }
             // mail could not be sent
             $user->setStatus(1);
             $userRole = new \Rebond\Core\UserRole\Model();
             $userRole->setUserId($user->getId());
             $userRole->setRoleId(\Rebond\Core\Role\Model::MEMBER);
             $userRole->save();
             return $tpl->render('register-success-nomail');
         } else {
             Util\Session::set('siteError', $form->getValidation()->getMessage());
         }
     }
     // confirm email
     $confirm = Util\Converter::toString('confirm');
     if (isset($confirm)) {
         $signedUser = \Rebond\Core\UserSecurity\Service::getUserBySecure($confirm, \Rebond\Core\UserSecurity\Model::CONFIRM);
         if (isset($signedUser) && $signedUser->getId() != 0) {
             $userRole = new \Rebond\Core\UserRole\Model();
             $userRole->setUserId($signedUser->getId());
             $userRole->setRoleId(\Rebond\Core\Role\Model::MEMBER);
             $userRole->save();
             Util\Session::set('allSuccess', Util\Lang::lang('hi', [$signedUser->getUsername()]));
             Util\Session::set('signedUser', $signedUser->getId());
             $this->app->setUser($signedUser);
             return $tpl->render('register-confirm');
         }
     }
     $tpl->set('item', $form);
     return $tpl->render('register');
 }
Beispiel #2
0
 public function register()
 {
     $signedUser = $this->app->user();
     // auth
     if (Util\Auth::isAuth($signedUser)) {
         header('Location: /profile');
         exit;
     }
     // check
     $user = new \Rebond\Core\User\Model();
     $form = new \Rebond\Core\User\Form($user);
     $tpl = new Util\Template(Util\Template::MODULE, ['app', 'User']);
     // register
     $register = Util\Converter::string('register', 'post');
     if (isset($register)) {
         if ($form->setFromPost()->validate()->isValid()) {
             $user->setStatus(0);
             $user->setPassword(Util\Security::encryptPassword($user->getPassword()));
             $avatarId = Util\Media::generateAvatar($user->getUsername());
             $user->setAvatarId($avatarId);
             $user->save();
             // send email
             if (Mail::register($this->app->site()->getTitle(), $user)) {
                 return $tpl->render('register-success');
             } else {
                 $user->setStatus(1);
                 $user->save();
                 $userRole = new \Rebond\Core\UserRole\Model();
                 $userRole->setUserId($user->getId());
                 $userRole->setRoleId(5);
                 // member
                 $userRole->save();
                 return $tpl->render('register-success-nomail');
             }
         } else {
             Session::set('siteError', $form->getValidation()->getMessage());
         }
     }
     // confirm email
     $confirm = Util\Converter::string('confirm');
     if (isset($confirm)) {
         $signedUser = \Rebond\Core\UserSecurity\Data::loadBySecure($confirm, \Rebond\Core\UserSecurity\Model::CONFIRM);
         if (isset($signedUser) && $signedUser->getId() != 0) {
             $userRole = new \Rebond\Core\UserRole\Model();
             $userRole->setUserId($signedUser->getId());
             $userRole->setRoleId(5);
             // member
             $userRole->save();
             Util\Session::set('allSuccess', Util\Lang::lang('hi', [$signedUser->getUsername()]));
             Util\Session::set('signedUser', $signedUser->getId());
             $this->app->setUser($signedUser);
             return $tpl->render('register-confirm');
         }
     }
     $tpl->set('item', $form);
     return $tpl->render('register');
 }
Beispiel #3
0
 protected static function mapper(array $row, $alias = 'user')
 {
     $model = new \Rebond\Core\User\Model(false);
     if (isset($row[$alias . 'Id'])) {
         $model->setId($row[$alias . 'Id']);
     }
     if (isset($row[$alias . 'Username'])) {
         $model->setUsername($row[$alias . 'Username']);
     }
     if (isset($row[$alias . 'Email'])) {
         $model->setEmail($row[$alias . 'Email']);
     }
     if (isset($row[$alias . 'Password'])) {
         $model->setPassword($row[$alias . 'Password']);
     }
     if (isset($row[$alias . 'Firstname'])) {
         $model->setFirstname($row[$alias . 'Firstname']);
     }
     if (isset($row[$alias . 'Lastname'])) {
         $model->setLastname($row[$alias . 'Lastname']);
     }
     if (isset($row[$alias . 'AvatarId'])) {
         $model->setAvatarId($row[$alias . 'AvatarId']);
         $model->setAvatar(\Rebond\Core\Media\Data::join($row, $alias . '_avatar'));
     }
     if (isset($row[$alias . 'IsAdmin'])) {
         $model->setIsAdmin($row[$alias . 'IsAdmin']);
     }
     if (isset($row[$alias . 'IsDev'])) {
         $model->setIsDev($row[$alias . 'IsDev']);
     }
     if (isset($row[$alias . 'Status'])) {
         $model->setStatus($row[$alias . 'Status']);
     }
     if (isset($row[$alias . 'CreatedDate'])) {
         $model->setCreatedDate($row[$alias . 'CreatedDate']);
     }
     if (isset($row[$alias . 'ModifiedDate'])) {
         $model->setModifiedDate($row[$alias . 'ModifiedDate']);
     }
     return $model;
 }
Beispiel #4
0
 public function index()
 {
     // check
     $this->db = new \Rebond\Util\Data();
     $this->authFile = \Rebond\Config::getPath('config') . 'authentication.txt';
     $this->queryTables = 'SELECT COUNT(TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = \'' . \Rebond\Config::getDb('name') . '\'';
     $this->queryCheckUser = '******';
     $this->info = [];
     $isAuth = Session::int('auth');
     $action = Converter::string('action');
     // action
     if ($isAuth == 0) {
         $this->step = 'auth';
         // check auth
         if (!file_exists($this->authFile)) {
             $auth = \Rebond\Util\Security::encrypt(time());
             File::save($this->authFile, 'w', $auth);
         } else {
             $auth = File::read($this->authFile, 'r');
         }
         if (isset($_POST['submitAuth'])) {
             if ($auth == $_POST['auth']) {
                 Session::set('auth', 1);
                 $isAuth = 1;
                 unlink($this->authFile);
                 $this->step = 'db';
                 $this->info[] = '<p class="bg-success">You have been authenticated!</p>';
             } else {
                 $this->info[] = '<p class="bg-error">The identification number you entered is incorrect. Please try again.</p>';
             }
         }
     }
     if ($isAuth == 1) {
         // check db
         $tableCount = $this->db->count($this->queryTables);
         $userTable = $this->db->selectOne($this->queryCheckUser);
         if ($tableCount != 0 && $tableCount !== self::TABLECOUNT) {
             $this->info[] = '<p class="bg-error">Your database contains ' . $tableCount . ' table(s). A fresh install of Rebond should contain ' . self::TABLECOUNT . ' tables. Please check your database name to make sure that you want to install Rebond in this database.</p>';
         }
         if (count($userTable) == 0) {
             $this->step = 'db';
             if ($action == 'db') {
                 $scripts = \Rebond\Util\File::getFiles('files/install');
                 sort($scripts);
                 foreach ($scripts as $script) {
                     $result = $this->db->runScript('files/install', $script);
                     if ($result['status'] == \Rebond\Core\ResultType::SUCCESS) {
                         $this->info[] = '<p>' . $script . '... success.</p>';
                     } else {
                         $this->info[] = '<p>' . $script . '... failed: <span class="error">' . $result['message'] . '</span></p>';
                         break;
                     }
                 }
                 $tableCount = $this->db->count($this->queryTables);
                 $userTable = $this->db->selectOne($this->queryCheckUser);
                 if (count($userTable) == 0) {
                     $this->info[] = '<p class="bg-error">The database has NOT been installed correctly. Please try to reinstall the database.</p>';
                 } else {
                     $this->info[] = '<p class="bg-success">The database has been installed successfully.</p>';
                     $this->step = 'db-ok';
                 }
             }
             // check user
         } else {
             if (\Rebond\Core\User\Data::count() == 0) {
                 $this->step = 'user';
                 $user = new \Rebond\Core\User\Model();
                 $userForm = new \Rebond\Core\User\Form($user);
                 if (isset($_POST['submitUser'])) {
                     if ($userForm->setFromPost()->validate()->isValid()) {
                         $user->setPassword(Security::encryptPassword($user->getPassword()));
                         $user->setIsAdmin(true);
                         $user->setIsDev(true);
                         $user->save();
                         $this->step = 'ready';
                     } else {
                         Session::set('adminError', $userForm->getValidation()->getMessage());
                     }
                 }
                 // ready
             } else {
                 $this->step = 'ready';
                 if ($action == 'launch') {
                     $adminPath = \Rebond\Config::getPath('admin');
                     $sitePath = \Rebond\Config::getPath('site');
                     rename($adminPath . 'index.php', $adminPath . 'index_install.php');
                     rename($adminPath . 'index_admin.php', $adminPath . 'index.php');
                     rename($sitePath . 'index.php', $sitePath . 'index_install.php');
                     rename($sitePath . 'index_cms.php', $sitePath . 'index.php');
                     $db = new \Rebond\Util\Data();
                     $db->backup('launch');
                     Session::kill('auth');
                     Session::setAndRedirect('signedUser', 1, '/configuration/site');
                 }
             }
         }
     }
     // menu
     $tplMenu = new Template(Template::SITE, ['admin', 'install']);
     $tplMenu->set('menuAuth', $this->step == 'auth' ? ' class="active"' : '');
     $tplMenu->set('menuDb', in_array($this->step, ['db', 'db-ok']) ? ' class="active"' : '');
     $tplMenu->set('menuUser', $this->step == 'user' ? ' class="active"' : '');
     $tplMenu->set('menuReady', $this->step == 'ready' ? ' class="active"' : '');
     // main
     $tplMain = new Template(Template::SITE, ['admin', 'install']);
     // layout
     $this->tplLayout->set('column1', $tplMenu->render('menu'));
     $this->tplLayout->add('column1', implode($this->info));
     if ($this->step == 'user') {
         if (!isset($user)) {
             $userForm = new \Rebond\Core\User\Form();
             $userForm->setFromPost();
         }
         $tplMain->set('form', $userForm);
     }
     $this->tplLayout->add('column1', $tplMain->render($this->step));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'install');
     $this->tplMaster->addCss('/css/normalize.css');
     $this->tplMaster->addCss('/css/rebond.css');
     $this->tplMaster->addCss('/css/custom.css');
     $this->tplMaster->addJs('//code.jquery.com/jquery-2.1.3.min.js');
     $this->tplMaster->addJs('/js/rebond.js');
     $this->tplMaster->addJs('/js/custom.js');
     return $this->tplMaster->render('tpl-install');
 }