Ejemplo n.º 1
0
 function actionEdit()
 {
     // Get the ID from the query string
     $id = $this->getIdFromQS();
     // Create a new form
     $form = new YDWeblogForm('userForm');
     // Add the elements
     $form->addElement('hidden', 'id', '');
     if ($id == '-1') {
         $form->addElement('text', 'name', t('username'), array('class' => 'tfM'));
     } else {
         $form->addElement('text', 'name', t('username'), array('class' => 'tfM', 'disabled' => ''));
     }
     $form->addElement('text', 'email', t('useremail'), array('class' => 'tfM'));
     $form->addElement('password', 'password', t('password'), array('class' => 'tfM'));
     $form->addElement('submit', 'cmdSubmit', t('save'), array('class' => 'button'));
     // Apply filters
     $form->addFilter('__ALL__', 'trim');
     $form->addFilters(array('name', 'email'), 'strip_html');
     // Add the rules
     $form->addRule('email', 'required', t('req_useremail'));
     $form->addRule('email', 'email', t('req_useremail'));
     if ($id == '-1') {
         $form->addRule('name', 'required', t('err_username'));
         $form->addRule('password', 'required', t('req_loginpass'));
     }
     $form->addFormRule(array(&$this, 'checkUserCredentials'));
     // Set the defaults
     if ($id != '-1') {
         // Get the user data
         $user = $this->weblog->getUserByID($id);
         unset($user['password']);
         // Set the form defaults
         $form->setDefaults($user);
         // Add this to the template
         $this->tpl->assign('user_data', $user);
     }
     // Validate the form
     if ($form->validate() == true) {
         // Get the form values
         $values = $form->getValues();
         // Save the userdata
         $this->weblog->saveUser($values);
         // Go to the default view
         $this->redirectToAction();
     }
     // Add the form to the template
     $this->tpl->assignForm('form', $form);
     // Display the template
     $this->display();
 }
 function actionLogin()
 {
     // Redirect to default action if already logged in
     if ($this->isAuthenticated() == true || !is_null($this->user)) {
         $this->forward('default');
         return;
     }
     // Create the login form
     $form = new YDWeblogForm('loginForm');
     // Check if the login name exists
     if (!empty($_COOKIE['YD_USER_NAME'])) {
         $form->setDefaults(array('loginName' => $_COOKIE['YD_USER_NAME']));
     }
     // Add the elements
     $form->addElement('text', 'loginName', t('username'), array('class' => 'tfS'));
     $form->addElement('password', 'loginPass', t('password'), array('class' => 'tfS'));
     $form->addElement('submit', 'cmdSubmit', t('login'), array('class' => 'button'));
     // Add the element rules
     $form->addRule('loginName', 'required', t('err_username'));
     $form->addRule('loginPass', 'required', t('err_password'));
     // Add the rules
     $form->addFormRule(array(&$this, 'checkLogin'));
     // Process the form
     if ($form->validate() == true) {
         // Get the form values
         $values = $form->getValues();
         // Set the cookies
         setcookie('YD_USER_NAME', $values['loginName'], time() + 31536000, '/');
         setcookie('YD_USER_PASS', md5($values['loginPass']), time() + 31536000, '/');
         // Set the username
         $this->username = $values['loginName'];
         // Forward to the main manage page
         $this->redirect('index.php');
     }
     // Add the form to the template
     $this->tpl->assignForm('form', $form);
     // Output the template
     $this->display('login');
 }