示例#1
0
  public function processsignupAction() {
    $request = $this->getRequest();

    // Check if we have a POST request
    if (!$request->isPost())
      return $this->_helper->redirector('index');

    // Get our form and validate it; display signup form if entries
    // are invalid
    $form = $this->getSignupForm();
    if (!$form->isValid($request->getPost())) {
      $this->view->loginForm = $this->getLoginForm();
      $this->view->signupForm = $form;
      return $this->render('index');
    }

    // create the new profile. this function will return null
    // if the profile already exists
    $ar=$form->getValues();
    $username=$ar['username'];
    try {
      $profile = ProfileTable::create($username);
    }
    catch (Exception $e) {
      $this->handleError($e);
    }
    if (!$profile) { // already exists
      $form->setDescription('Username already exists, please choose '.
            'another one!');
      $this->view->loginForm = $this->getLoginForm();
      $this->view->signupForm = $form;
      return $this->render('index');
    }
    else { // initialize with an empty password
      $profile->setId($username);
      $profile->setPasswordPlain('');
      ProfileTable::store($profile);

      // The user was created! Authenticate the user against his empty
      // password and redirect him to the profile page.
      $adapter=$this->getAuthAdapter(array('username' => $username, 
                'password' => ''));
      $auth=Zend_Auth::getInstance();
      $result=$auth->authenticate($adapter);
      if (!$result->isValid()) 
        die("This should never happen...");
      $this->_helper->redirector('index', 'profile');
    }
  }
  public function processAction() {
    $profile=Zend_Auth::getInstance()->getIdentity();
    $request = $this->getRequest();
    $this->view->username=$profile->getId();

    // Check if we have a POST request
    if (!$request->isPost())
      return $this->_helper->redirector('index', 'index');

    // Get our form and validate it
    $form = $this->getProfileForm();
    if (!$form->isValid($request->getPost())) {
      $this->view->form = $form;
      return $this->render('index');
    }

    // store the values in the profile
    $ar=$form->getValues();

    // just a sanity check
    if ($ar['username']!=$profile->getId())
      die("This should never happen...");

    if ($ar['password'])
      $profile->setPasswordPlain($ar['password']);
    if ($ar['display_name']!=$profile->getDisplayName())
      $profile->setDisplayName($ar['display_name']);
    if ($ar['email']!=$profile->getEmail())
      $profile->setEmail($ar['email']);
    if ($ar['location']!=$profile->getLocation())
      $profile->setLocation($ar['location']);
    if ($ar['webpage']!=$profile->getWebpage())
      $profile->setWebpage($ar['webpage']);
    if ($ar['avatar']!=$profile->getAvatar())
      $profile->setAvatar($ar['avatar']);

    ProfileTable::store($profile);
    $form->setDescription('Your profile was saved.');
    $this->view->form = $form;
    return $this->render('index');
  }