Beispiel #1
0
 /**
  * Add a new admin to the system
  *
  * @param array $args
  * @return void
  */
 public function add(array $args = array())
 {
     $ini = Garp_Auth::getInstance()->getConfigValues();
     if (empty($ini['adapters']['db'])) {
         Garp_Cli::errorOut('Error: DB adapter is not configured in application.ini.');
     } elseif (empty($ini['adapters']['db']['identityColumn']) || empty($ini['adapters']['db']['credentialColumn'])) {
         Garp_Cli::errorOut('Error: identityColumn or credentialColumn not configured in application.ini');
     } else {
         $newUserData = array('role' => 'admin');
         $promptData = array();
         // Pull required fields from Spawner config
         $modelSet = Garp_Spawn_Model_Set::getInstance();
         $userModelConfig = $modelSet['User'];
         $requiredFields = $userModelConfig->fields->getFields('required', true);
         foreach ($requiredFields as $field) {
             if ($field->origin == 'config' && $field->name !== 'id') {
                 $promptData[] = $field->name;
             } elseif ($field->origin == 'relation') {
                 Garp_Cli::errorOut('Field ' . $field->name . ' is required but must be filled by way of relation. ' . 'This makes it impossible to create an admin from the commandline.');
             }
         }
         if (!in_array($ini['adapters']['db']['identityColumn'], $promptData)) {
             $promptData[] = $ini['adapters']['db']['identityColumn'];
         }
         // prompt for the new data
         Garp_Cli::lineOut('Please fill the following columns:');
         foreach ($promptData as $key) {
             $newUserData[$key] = trim(Garp_Cli::prompt($key . ':'));
         }
         $newAuthLocalData = array('password' => trim(Garp_Cli::prompt('Choose a password:'******'s entirely possible to circumvent these
          * conventions and come up with project-specific standards.
          * In that case however, this CLI command is not for you.
          */
         $user = new Model_User();
         try {
             $id = $user->insert($newUserData);
             $authLocal = new Model_AuthLocal();
             $newAuthLocalData['user_id'] = $id;
             if ($authLocal->insert($newAuthLocalData)) {
                 Garp_Cli::lineOut('Successfully created the administrator. (id: ' . $id . ')');
             } else {
                 Garp_Cli::errorOut('Error: could not create administrator.');
             }
         } catch (Zend_Db_Statement_Exception $e) {
             if (strpos($e->getMessage(), 'Duplicate entry') !== false && strpos($e->getMessage(), 'email_unique') !== false) {
                 Garp_Cli::errorOut('Error: this email address is already in use. ' . 'Maybe you meant to use Garp Admin make?');
             } else {
                 throw $e;
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Store a new user. This creates a new AuthVimeo record, but also
  * a new user record.
  * @param String $vimeoId Vimeo user id
  * @param Zend_Oauth_Token_Access $accessToken oAuth access token
  * @param Array $props Properties received from Vimeo
  * @return Garp_Db_Table_Row The new user data
  */
 public function createNew($vimeoId, Zend_Oauth_Token_Access $accessToken, array $props)
 {
     // first save the new user
     $userModel = new Model_User();
     $userId = $userModel->insert($props);
     $userData = $userModel->find($userId)->current();
     $this->insert(array('vimeo_id' => $vimeoId, 'access_token' => $accessToken->getToken(), 'access_token_secret' => $accessToken->getTokenSecret(), 'user_id' => $userId));
     $this->getObserver('Authenticatable')->updateLoginStats($userId);
     return $userData;
 }
Beispiel #3
0
 /**
  * Store a new user. This creates a new auth_openid record, but also
  * a new users record.
  * @param String $openid
  * @param Array $props Properties fetched thru Sreg
  * @return Garp_Db_Table_Row The new user data
  */
 public function createNew($openid, array $props)
 {
     // first save the new user
     $userModel = new Model_User();
     $userId = $userModel->insert($props);
     $userData = $userModel->find($userId)->current();
     $this->insert(array('openid' => $openid, 'user_id' => $userId));
     $this->getObserver('Authenticatable')->updateLoginStats($userId);
     return $userData;
 }
Beispiel #4
0
 /**
  * Store a new user. This creates a new auth_facebook record, but also
  * a new user record.
  * @param Array $authData Data for the new Auth record
  * @param Array $userData Data for the new User record
  * @return Garp_Db_Table_Row The new user data
  */
 public function createNew(array $authData, array $userData)
 {
     // first save the new user
     $userModel = new Model_User();
     $userId = $userModel->insert($userData);
     $userData = $userModel->find($userId)->current();
     $authData['user_id'] = $userId;
     $this->insert($authData);
     $this->getObserver('Authenticatable')->updateLoginStats($userId);
     return $userData;
 }
Beispiel #5
0
 public function indexAction()
 {
     $table = new Model_User();
     //类的实例化
     // 增加的数据
     $data = array('tb_user' => 'King', 'tb_pass' => 'mrsoft');
     if ($table->insert($data)) {
         //执行添加操作
         $this->view->insert = "插入数据成功!";
     }
 }
Beispiel #6
0
 /**
  * Store a new user. This creates a new auth_linkedin record, but also
  * a new user record.
  * @param String $linkedinId LinkedIn user id
  * @param Array $props Properties received from LinkedIn
  * @return Garp_Db_Table_Row The new user data
  */
 public function createNew($linkedinId, array $props)
 {
     //print($linkedinId . '<pre>' . print_r($props, true));
     // first save the new user
     $userModel = new Model_User();
     $userId = $userModel->insert($props);
     $userData = $userModel->find($userId)->current();
     $this->insert(array('linkedin_uid' => $linkedinId, 'user_id' => $userId));
     $this->getObserver('Authenticatable')->updateLoginStats($userId);
     return $userData;
 }
 /**
  * 建立用户
  */
 public function createUser()
 {
     if ($this->getR('pwd') != $this->getR('pwd1')) {
         return array('status' => -1, 'info' => '密码不一致', 'data' => null);
     }
     $this->_modelUser = $this->getGlobal('model/User', 'Model_User');
     if ($this->_modelUser->findByUser($this->getR('user'))) {
         return array('status' => -1, 'info' => '此账号已存在', 'data' => null);
     }
     $userArr = array('user' => $this->getR('user'), 'vuser' => $this->getR('vuser'), 'pwd' => $this->convertPwd($this->getR('pwd')));
     if ($this->_modelUser->insert($userArr)) {
         $userArr['id'] = $this->_modelUser->getLastInsertId();
         import('object/UserClass');
         $userClass = new UserClass();
         $userClass->create($userArr);
         $userClass->setUpdate(true);
         $userClass = null;
         unset($userClass);
         return array('status' => 1, 'info' => '创建用户成功', 'data' => null);
     } else {
         return array('status' => -2, 'info' => '创建用户失败', 'data' => null);
     }
 }
 /**
  * Register a new account
  *
  * @return void
  */
 public function registerAction()
 {
     $this->view->title = __('register page title');
     $authVars = Garp_Auth::getInstance()->getConfigValues();
     if (!$this->getRequest()->isPost()) {
         return;
     }
     $errors = array();
     $postData = $this->getRequest()->getPost();
     $this->view->postData = $postData;
     // Apply some mild validation
     $password = $this->getRequest()->getPost('password');
     if (!$password) {
         $errors[] = sprintf(__('%s is a required field'), __('Password'));
     }
     $checkRepeatPassword = !empty($authVars['register']['repeatPassword']) && $authVars['register']['repeatPassword'];
     if ($checkRepeatPassword) {
         $repeatPasswordField = $this->getRequest()->getPost($authVars['register']['repeatPasswordField']);
         unset($postData[$authVars['register']['repeatPasswordField']]);
         if ($password != $repeatPasswordField) {
             $errors[] = __('the passwords do not match');
         }
     }
     if (count($errors)) {
         $this->view->errors = $errors;
         return;
     }
     // Save the new user
     $userModel = new Model_User();
     try {
         // Before register hook
         $this->_beforeRegister($postData);
         // Extract columns that are not part of the user model
         $userData = $userModel->filterColumns($postData);
         $insertId = $userModel->insert($userData);
         $this->_helper->flashMessenger(__($authVars['register']['successMessage']));
         // Store new user directly thru Garp_Auth so that they're logged in immediately
         $newUser = $userModel->find($insertId)->current();
         $auth = Garp_Auth::getInstance();
         $auth->store($newUser->toArray(), 'db');
         // After register hook
         $this->_afterRegister();
         // Determine targetUrl.
         // This is the URL the user was trying to access before registering, or a default URL.
         $router = Zend_Controller_Front::getInstance()->getRouter();
         if (!empty($authVars['register']['successRoute'])) {
             $targetUrl = $router->assemble(array(), $authVars['register']['successRoute']);
         } elseif (!empty($authVars['register']['successUrl'])) {
             $targetUrl = $authVars['register']['successUrl'];
         } else {
             $targetUrl = '/';
         }
         $store = Garp_Auth::getInstance()->getStore();
         if ($store->targetUrl) {
             $targetUrl = $store->targetUrl;
             unset($store->targetUrl);
         }
         $this->_redirect($targetUrl);
         // Check for duplication errors in order to show
         // a helpful error to the user.
     } catch (Zend_Db_Statement_Exception $e) {
         if (strpos($e->getMessage(), 'Duplicate entry') !== false && strpos($e->getMessage(), 'email_unique') !== false) {
             $errors[] = __('this email address already exists');
         } else {
             throw $e;
         }
         // Validation errors should be safe to show to the user (note: translation
         // must be done in the validator itself)
     } catch (Garp_Model_Validator_Exception $e) {
         $errors[] = $e->getMessage();
         // Unknown error? Yikes... Show to developers, but show a
         // generic error to the general public.
     } catch (Exception $e) {
         $error = APPLICATION_ENV === 'development' ? $e->getMessage() : __('register error');
         $errors[] = $error;
     }
     $this->view->errors = $errors;
 }
Beispiel #9
0
 protected function _createOrFetchUserRecord(array $userData)
 {
     $userModel = new Model_User();
     $userData = $userModel->filterColumns($userData);
     $select = $userModel->select()->where('email = ?', $userData['email']);
     if ($userRecord = $userModel->fetchRow($select)) {
         return $userRecord->id;
     }
     return $userModel->insert($userData);
 }
 public function testShouldFailOnStrangersToken()
 {
     if (!$this->_testsEnabled) {
         return;
     }
     $userModel = new Model_User();
     $userModel->insert(array('email' => '*****@*****.**', 'id' => 1));
     $userModel->insert(array('email' => '*****@*****.**', 'id' => 2));
     $authModel = new Model_AuthPasswordless();
     $authModel->insert(array('token' => '12345', 'token_expiration_date' => date('Y-m-d H:i:s', strtotime('+30 minutes')), 'user_id' => 2));
     $pwless = new Garp_Auth_Adapter_Passwordless();
     $response = $pwless->acceptToken('12345', 1);
     $this->assertFalse($response);
     $this->assertEquals($pwless->getErrors(), array(__('passwordless token not found')));
 }
Beispiel #11
0
        $sex = global_editor::rteSafe(html_entity_decode($sex, ENT_COMPAT, 'UTF-8'));
        $identity = $_pgR['Identity'];
        $identity = global_editor::rteSafe(html_entity_decode($identity, ENT_COMPAT, 'UTF-8'));
        $roleID = $_pgR['RoleID'];
        $roleID = global_editor::rteSafe(html_entity_decode($roleID, ENT_COMPAT, 'UTF-8'));
        $userRankID = $_pgR['UserRankID'];
        $userRankID = global_editor::rteSafe(html_entity_decode($userRankID, ENT_COMPAT, 'UTF-8'));
        $avatar = $_pgR['Avatar'];
        $avatar = global_editor::rteSafe(html_entity_decode($avatar, ENT_COMPAT, 'UTF-8'));
        $accountID = $_pgR['AccountID'];
        $accountID = global_editor::rteSafe(html_entity_decode($accountID, ENT_COMPAT, 'UTF-8'));
        $isActived = $_pgR['IsActived'];
        $isActived = global_editor::rteSafe(html_entity_decode($isActived, ENT_COMPAT, 'UTF-8'));
        //$strName = $_pgR['name'];
        //$strName = global_editor::rteSafe(html_entity_decode($strName,ENT_COMPAT ,'UTF-8' ));
        $resultID = $objUser->insert($userID, $userName, $password, $fullname, $birthDate, $address, $phone, $email, $sex, $identity, $roleID, $userRankID, $avatar, $accountID, $isActived);
        if ($resultID) {
            $arrHeader = global_common::getMessageHeaderArr($banCode);
            //$banCode
            echo global_common::convertToXML($arrHeader, array("rs", "inf"), array(1, $result), array(0, 1));
            return;
        } else {
            echo global_common::convertToXML($arrHeader, array("rs", "info"), array(0, "Input data is invalid"), array(0, 1));
            return;
        }
    } else {
        echo global_common::convertToXML($arrHeader, array("rs", 'info'), array(0, global_common::STRING_REQUIRE_LOGIN), array(0, 1));
    }
    return;
} elseif ($_pgR['act'] == model_User::ACT_UPDATE) {
    if (global_common::isCLogin()) {