Exemple #1
0
 function forgot_password()
 {
     $post = $this->input->post();
     $form = HC_Lib::form();
     $form->set_inputs(array('email' => 'text'));
     $validator = new HC_Validator();
     $validator->set_rules('email', 'required');
     if ($post && $validator->run($post) == TRUE) {
         $form->grab($post);
         $values = $form->values();
         $forgotten = $this->auth->forgotten_password($values['email']);
         if ($forgotten) {
             //if there were no errors
             $this->session->set_flashdata('message', HCM::__('Password reset message has been sent to your email'));
             $this->redirect('auth/login');
         } else {
             $this->session->set_flashdata('error', $this->auth->error);
             $this->redirect('auth/forgot_password');
         }
     }
     $errors = $validator->error();
     $form->set_values($post);
     $form->set_errors($errors);
     $this->layout->set_partial('content', $this->render('auth/forgot_password', array('form' => $form)));
     $this->layout();
 }
 function update($tab = 'core')
 {
     $app_conf = HC_App::app_conf();
     $fields = $this->config->items('settings');
     $tabs = $this->_get_tabs($fields);
     $these_fields = $tabs[$tab];
     $validator = new HC_Validator();
     foreach ($these_fields as $fn) {
         $f = $fields[$fn];
         if (isset($f['rules'])) {
             $validator->set_rules($fn, $f['rules']);
         }
     }
     $post = $this->input->post();
     $this->form->grab($post);
     $values = $this->form->values();
     if ($values && $validator->run($values) == TRUE) {
         reset($these_fields);
         foreach ($these_fields as $fn) {
             $app_conf->set($fn, $values[$fn]);
         }
         // redirect back
         $msg = HCM::__('Settings updated');
         $this->session->set_flashdata('message', $msg);
         $to = 'conf/admin/index/' . $tab;
         $this->redirect($to);
     } else {
         $errors = $validator->error();
         $this->form->set_values($values);
         $this->form->set_errors($errors);
         $fields = $this->config->items('settings');
         /* render view */
         $this->layout->set_partial('content', $this->render('conf/admin/index', array('fields' => $fields, 'form' => $this->form, 'tab' => $tab, 'tabs' => $tabs)));
         $this->layout();
     }
 }
Exemple #3
0
 function run()
 {
     $validator = new HC_Validator();
     // $validator->set_rules('first_name',			'trim|required');
     $post = $this->input->post();
     $this->form->grab($post);
     $values = $this->form->values();
     $errors = array();
     if ($values && $validator->run($values)) {
         /* run setup */
         /* reset tables */
         $this->_drop_tables();
         /* setup tables */
         $this->load->library('migration');
         if (!$this->migration->current()) {
             show_error($this->migration->error_string());
             return false;
         }
         $setup_ok = TRUE;
         /* admin user */
         $um = HC_App::model('user');
         $um->from_array($values);
         $um->level = $um->_const('LEVEL_ADMIN');
         if ($um->save()) {
             $email_from = $values['email'];
             $email_from_name = $values['first_name'] . ' ' . $values['last_name'];
         } else {
             $errors = array_merge($errors, $um->errors());
             $this->_drop_tables();
             $setup_ok = FALSE;
         }
         if ($setup_ok) {
             /* default settings */
             $app_conf = HC_App::app_conf();
             $app_conf->init();
             // to reload database
             $app_conf->set('email_from', $email_from);
             $app_conf->set('email_from_name', $email_from_name);
             $this->session->set_flashdata('message', HCM::__('OK'));
             # message sent on succesful setup
             $this->redirect('setup/ok');
             return;
         }
     }
     $errors = array_merge($errors, $validator->errors());
     $this->form->set_errors($errors);
     return $this->index();
 }
Exemple #4
0
 function run()
 {
     $validator = new HC_Validator();
     $wum = HC_App::model('wordpress_user');
     $wordpress_roles = $wum->wp_roles();
     $wordpress_count_users = count_users();
     foreach ($wordpress_roles as $role_value => $role_name) {
         $field_name = 'role_' . $role_value;
         $validator->set_rules($field_name, 'trim|required');
     }
     $post = $this->input->post();
     $this->form->grab($post);
     $values = $this->form->values();
     if ($post) {
         if ($validator->run($values) == FALSE) {
             $errors = $validator->error();
             $this->form->set_values($values);
             $this->form->set_errors($errors);
             /* render view */
             return $this->index();
         } else {
             /* run setup */
             /* reset tables */
             $this->_drop_tables();
             /* setup tables */
             $this->load->library('migration');
             if (!$this->migration->current()) {
                 show_error($this->migration->error_string());
                 return false;
             }
             $app_conf = HC_App::app_conf();
             $app_conf->init();
             $setup_ok = TRUE;
             $append_role_name = $values['append_role_name'];
             /* save settings */
             reset($values);
             foreach ($values as $k => $v) {
                 $app_conf->set('wordpress_' . $k, $v);
             }
             $um = HC_App::model('user');
             /* all users */
             $result = $wum->sync_all($values);
             if ($result !== TRUE) {
                 $msg = array();
                 foreach ($result as $uid => $user_result) {
                     foreach ($user_result as $k => $v) {
                         $msg[] = 'User ID=' . $uid . ': ' . $k . ': ' . $v;
                     }
                 }
                 $msg = join('<br>', $msg);
                 $this->session->set_flashdata('error', $msg);
                 $setup_ok = FALSE;
             }
             $success_count = $wum->get_last_count('success');
             /* this user */
             $current_user = wp_get_current_user();
             $result = $wum->sync($current_user->ID, $um->_const('LEVEL_ADMIN'));
             if ($result !== TRUE) {
                 $msg = array();
                 foreach ($result as $k => $v) {
                     $msg[] = $k . ': ' . $v;
                 }
                 $msg = join('<br>', $msg);
                 $this->session->set_flashdata('error', $msg);
                 $setup_ok = FALSE;
             }
             // $success_count++;
             if ($setup_ok) {
                 /* default settings */
                 $email_from = get_bloginfo('admin_email');
                 $email_from_name = get_bloginfo('name');
                 $app_conf->set('email_from', $email_from);
                 $app_conf->set('email_from_name', $email_from_name);
                 $msg = 'Imported ' . $success_count . ' ';
                 $msg .= $count_users > 1 ? 'users' : 'user';
                 $this->session->set_flashdata('message', $msg);
                 $this->redirect('setup/ok');
                 return;
             } else {
                 $this->_drop_tables();
                 $this->redirect('wordpress/setup');
             }
         }
     }
     return $this->index();
 }
Exemple #5
0
 function syncrun()
 {
     $validator = new HC_Validator();
     $wum = HC_App::model('wordpress_user');
     $wordpress_roles = $wum->wp_roles();
     $wordpress_count_users = count_users();
     foreach ($wordpress_roles as $role_value => $role_name) {
         $field_name = 'role_' . $role_value;
         $validator->set_rules($field_name, 'trim|required');
     }
     $post = $this->input->post();
     $this->form->grab($post);
     $values = $this->form->values();
     if ($post) {
         if ($validator->run($values) == FALSE) {
             $errors = $validator->error();
             $this->form->set_values($values);
             $this->form->set_errors($errors);
             /* render view */
             return $this->sync();
         } else {
             $app_conf = HC_App::app_conf();
             $setup_ok = TRUE;
             $append_role_name = $values['append_role_name'];
             /* save settings */
             reset($values);
             foreach ($values as $k => $v) {
                 $app_conf->set('wordpress_' . $k, $v);
             }
             $um = HC_App::model('user');
             /* all users */
             $result = $wum->sync_all($values);
             if ($result !== TRUE) {
                 $msg = array();
                 foreach ($result as $uid => $user_result) {
                     foreach ($user_result as $k => $v) {
                         $msg[] = 'User ID=' . $uid . ': ' . $k . ': ' . $v;
                     }
                 }
                 $msg = join('<br>', $msg);
                 $this->session->set_flashdata('error', $msg);
                 $setup_ok = FALSE;
             }
             $success_count = $wum->get_last_count('success');
             $archived_count = $wum->get_last_count('archived');
             /* this user */
             $current_user = wp_get_current_user();
             $result = $wum->sync($current_user->ID, $um->_const('LEVEL_ADMIN'));
             if ($result !== TRUE) {
                 $msg = array();
                 foreach ($result as $k => $v) {
                     $msg[] = $k . ': ' . $v;
                 }
                 $msg = join('<br>', $msg);
                 $this->session->set_flashdata('error', $msg);
                 $setup_ok = FALSE;
             }
             // $success_count++;
             if ($setup_ok) {
                 $msg = 'Synchronized ' . $success_count . ' ';
                 $msg .= $success_count_users > 1 ? 'users' : 'user';
                 if ($archived_count) {
                     $msg .= '<br>Archived ' . $archived_count . ' ';
                     $msg .= $archived_count > 1 ? 'users' : 'user';
                 }
                 $this->session->set_flashdata('message', $msg);
                 $this->redirect('admin/users');
                 return;
             } else {
                 $this->redirect('wordpress/admin/users');
             }
         }
     }
     return $this->sync();
 }