Beispiel #1
0
 public function indexAction()
 {
     $error = $warning = $formData = array();
     $redirectUrl = $this->registry->request->query->get('redirect');
     //base64 encoded
     $isLoginSuccess = false;
     if ($this->registry->request->request->has('fsubmit')) {
         $formData = array_merge($formData, $this->registry->request->request->all());
         $myUser = \Model\User::getByEmail($formData['femail']);
         if ($myUser->id > 0 && $myUser->password == \Litpi\ViephpHashing::hash($formData['fpassword'])) {
             $isLoginSuccess = true;
             $redirectUrl = $this->doLogin($myUser->id, $formData['fpassword'], $redirectUrl);
             $this->doRedirect($redirectUrl);
         } else {
             $error[] = $this->registry->lang['controller']['errAccountInvalid'];
         }
     }
     if (!$isLoginSuccess) {
         $this->registry->smarty->assign(array('formData' => $formData, 'error' => $error, 'redirectUrl' => $redirectUrl));
         $contents = $this->registry->smarty->fetch($this->registry->smartyController . 'index.tpl');
         $this->registry->response->setContent($contents);
     }
 }
Beispiel #2
0
 public function indexAction()
 {
     if (!$this->checkinstallrequirement()) {
         die('Install Error. First User Account Already Existed.
           You can remove this install script from Site Controller');
     } else {
         $success = $error = $formData = array();
         if (isset($_POST['fsubmit'])) {
             $formData = array_merge($formData, $_POST);
             if ($this->installValidator($formData, $error)) {
                 $tableExisted = false;
                 if ($this->usertablesExists()) {
                     $tableExisted = true;
                 } else {
                     try {
                         //Create Table ac_user
                         $sql = '
                                 CREATE TABLE IF NOT EXISTS `' . TABLE_PREFIX . 'ac_user` (
                                   `u_id` int(11) NOT NULL AUTO_INCREMENT,
                                   `u_screenname` varchar(32) NOT NULL,
                                   `u_fullname` varchar(50) NOT NULL,
                                   `u_avatar` varchar(128) NOT NULL,
                                   `u_groupid` smallint(2) NOT NULL DEFAULT 0,
                                   `u_region` int(11) NOT NULL DEFAULT 0,
                                   `u_gender` smallint(1) NOT NULL DEFAULT 0,
                                   `u_view` int(11) NOT NULL DEFAULT 0,
                                   `u_datelastaction` int(10) NOT NULL DEFAULT 0,
                                   `u_parentid` int(11) NOT NULL DEFAULT 0,
                                   `u_skype` varchar(50) NOT NULL,
                                   PRIMARY KEY (`u_id`),
                                   KEY `u_screenname` (`u_screenname`),
                                   KEY `u_fullname` (`u_fullname`),
                                   KEY `u_groupid` (`u_groupid`),
                                   KEY `u_region` (`u_region`),
                                   KEY `u_gender` (`u_gender`),
                                   KEY `u_view` (`u_view`),
                                   KEY `u_datelastaction` (`u_datelastaction`),
                                   KEY `u_parentid` (`u_parentid`)
                                 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
                         $stmt = $this->registry->db->query($sql);
                         if ($stmt) {
                             $sql = '
                                     CREATE TABLE IF NOT EXISTS `' . TABLE_PREFIX . 'ac_user_profile` (
                                       `u_id` int(11) NOT NULL,
                                       `up_email` varchar(50) NOT NULL,
                                       `up_password` text NOT NULL,
                                       `up_birthday` date NOT NULL,
                                       `up_phone` varchar(20) NOT NULL,
                                       `up_address` varchar(255) NOT NULL,
                                       `up_city` varchar(32) NOT NULL,
                                       `up_country` varchar(2) NOT NULL,
                                       `up_website` varchar(50) NOT NULL,
                                       `up_bio` varchar(255) NOT NULL,
                                       `up_activatedcode` varchar(32) NOT NULL,
                                       `up_datecreated` int(10) NOT NULL DEFAULT 0,
                                       `up_datemodified` int(10) NOT NULL DEFAULT 0,
                                       `up_datelastlogin` int(10) NOT NULL DEFAULT 0,
                                       `up_oauth_partner` smallint(2) NOT NULL DEFAULT 0,
                                       `up_oauth_uid` varchar(50) NOT NULL DEFAULT 0,
                                       `up_ipaddress` int(11) NOT NULL DEFAULT 0,
                                       PRIMARY KEY (`u_id`),
                                       KEY `up_email` (`up_email`),
                                       KEY `up_country` (`up_country`),
                                       KEY `up_oauth_partner` (`up_oauth_partner`),
                                       KEY `up_oauth_uid` (`up_oauth_uid`),
                                       KEY `up_ipaddress` (`up_ipaddress`)
                                     ) ENGINE=MyISAM DEFAULT CHARSET=utf8;';
                             $stmt = $this->registry->db->query($sql);
                             if ($stmt) {
                                 //two table create ok
                                 $tableExisted = true;
                             }
                         }
                     } catch (\PDOException $e) {
                         $error[] = 'Error while creating main user tables. <br />(Error Code: ' . $e->getCode() . ', <br />Error Message: ' . $e->getMessage() . ')';
                     }
                 }
                 if ($tableExisted) {
                     //begin create new account
                     $myUser = new \Model\User();
                     $myUser->fullname = $formData['ffullname'];
                     $myUser->email = $formData['femail'];
                     $myUser->password = \Litpi\ViephpHashing::hash($formData['fpassword']);
                     $myUser->groupid = GROUPID_ADMIN;
                     if ($myUser->addData()) {
                         $success[] = 'Administrator Account had been created.';
                         $adminRedirectUrl = base64_encode($this->registry->conf['rooturl_admin']);
                         $this->registry->smarty->assign(array('adminRedirectUrl' => $adminRedirectUrl));
                     } else {
                         $error[] = 'Error while creating Administrator Account. Please try again.';
                     }
                 }
             }
             $this->registry->smarty->assign(array('error' => $error, 'success' => $success, 'formData' => $formData));
         }
         $contents = $this->registry->smarty->fetch($this->registry->smartyController . 'index.tpl');
         $this->registry->response->setContent($contents);
     }
 }
Beispiel #3
0
 public function addAction()
 {
     $error = array();
     $success = array();
     $contents = '';
     $formData = array();
     if ($this->postBag->has('fsubmit')) {
         if ($this->registry->session->get('userAddToken') == $this->postBag->get('ftoken')) {
             //kiem tra token
             $formData = array_merge($formData, $this->postBag->all());
             if ($this->addActionValidator($formData, $error)) {
                 //kiem tra du lieu nhap
                 $myUser = new \Model\User();
                 $myUser->groupid = (int) $formData['fgroupid'];
                 $myUser->email = Helper::plaintext($formData['femail']);
                 $myUser->password = \Litpi\ViephpHashing::hash($formData['fpassword']);
                 $myUser->fullname = Helper::plaintext($formData['ffullname']);
                 if ($myUser->addData() > 0) {
                     $success[] = str_replace('###email###', $myUser->email, $this->registry->lang['controller']['succAdd']);
                     $formData = array('fgroupid' => $formData['fgroupid']);
                 } else {
                     $error[] = $this->registry->lang['controller']['errAdd'];
                 }
             }
         }
     }
     $this->registry->session->set('userAddToken', Helper::getSecurityToken());
     //them token moi
     $this->registry->smarty->assign(array('formData' => $formData, 'redirectUrl' => $this->getRedirectUrl(), 'userGroups' => \Model\User::getGroupnameList(), 'error' => $error, 'success' => $success));
     $contents = $this->registry->smarty->fetch($this->registry->smartyController . 'add.tpl');
     $this->registry->smarty->assign(array('menu' => 'useradd', 'pageTitle' => $this->registry->lang['controller']['pageTitle_add'], 'contents' => $contents));
     $contents = $this->registry->smarty->fetch($this->registry->smartyModule . 'index.tpl');
     $this->registry->response->setContent($contents);
 }
Beispiel #4
0
 public function resetpass($newpass)
 {
     $sql = 'UPDATE ' . TABLE_PREFIX . 'ac_user_profile
             SET up_password = ?
             WHERE u_id = ?
             LIMIT 1';
     $stmt = $this->db->query($sql, array(\Litpi\ViephpHashing::hash($newpass), $this->id));
     if ($stmt) {
         return true;
     } else {
         return false;
     }
 }