Exemple #1
0
 public function settings()
 {
     if (!$this->Auth->isLoggedIn()) {
         $this->Auth->authenticationError();
     }
     $this->title = tr('Settings');
     $form = new Form('Settings');
     $form->addString('title', tr('Title'));
     $form->addString('username', tr('Username'));
     $form->addString('password', tr('Password'));
     $form->addString('confirmPassword', tr('Confirm password'));
     $form->title = $this->config['title'];
     $form->username = $this->config['username'];
     if ($this->request->hasValidData('Settings')) {
         $form->addData($this->request->data['Settings']);
         $this->config['title'] = $form->title;
         $this->config['username'] = $form->username;
         if (!empty($form->password)) {
             if ($form->password === $form->confirmPassword) {
                 $this->config['password'] = $this->Auth->passwordHasher->hash($form->password);
                 if ($this->config->save()) {
                     $this->Notify->success = tr('Password changed.');
                     return $this->refresh();
                 } else {
                     $this->Notify->error = tr('Could not save configuration file.');
                 }
             } else {
                 $form->addError('password', tr('The two passwords are not identical.'));
             }
         } else {
             if ($this->config->save()) {
                 $this->Notify->success = tr('Settings saved.');
                 return $this->refresh();
             } else {
                 $this->Notify->error = tr('Could not save configuration file.');
             }
         }
     }
     $this->settings = $form;
     return $this->render();
 }
Exemple #2
0
 /**
  * Set up maintenance user and install lock.
  * @param string $data POST data if any.
  * @return \Jivoo\Routing\Response|string Response.
  */
 public function configure($data = null)
 {
     $this->viewData['title'] = tr('Configure maintenance user');
     $form = new Form('user');
     $form->addField('username', DataType::string(), tr('Username'));
     $form->addField('password', DataType::string(), tr('Password'));
     $form->addField('confirmPassword', DataType::string(), tr('Confirm password'));
     $form->username = '******';
     if (isset($data)) {
         $form->addData($data['user']);
         if ($form->isValid()) {
             if ($form->password !== $form->confirmPassword) {
                 $form->addError('password', tr('The two passwords are not identical.'));
             } else {
                 $auth = $this->m->Setup->getAuth();
                 $password = $auth->passwordHasher->hash($form->password);
                 $this->m->Setup->lock($form->username, $password);
                 return $this->next();
             }
         }
     }
     $this->viewData['user'] = $form;
     return $this->render();
 }