Esempio n. 1
0
 /**
  * Display the Member Profile
  */
 public function index()
 {
     $this->template->content = new View('members/profile');
     // setup and initialize form field names
     $form = array('current_password' => '', 'username' => '', 'new_password' => '', 'password_again' => '', 'name' => '', 'email' => '', 'notify' => '', 'public_profile' => '', 'color' => '');
     //	Copy the form as errors, so the errors will be stored with keys
     //	corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         $post = Validation::factory($_POST);
         //	 Add some filters
         $post->pre_filter('trim', TRUE);
         $post->add_rules('username', 'required', 'alpha_numeric');
         $post->add_rules('name', 'required', 'length[3,100]');
         $post->add_rules('email', 'required', 'email', 'length[4,64]');
         $post->add_rules('current_password', 'required');
         $post->add_callbacks('email', array($this, 'email_exists_chk'));
         $post->add_callbacks('username', array($this, 'username_exists_chk'));
         $post->add_callbacks('current_password', array($this, 'current_pw_valid_chk'));
         // If Password field is not blank
         if (!empty($post->new_password)) {
             $post->add_rules('new_password', 'required', 'length[' . kohana::config('auth.password_length') . ']', 'alpha_numeric', 'matches[password_again]');
         }
         if ($post->validate()) {
             // Needinfo is set to 1 if we need more information on a user
             //   Set to 0 if the user is filling out the form, it means
             //   they have had an opportunity to provide extra details.
             $needinfo = 0;
             if (!empty($post->needinfo)) {
                 $needinfo = $post->needinfo;
             }
             $username = '';
             if (isset($post->username)) {
                 $username = $post->username;
             }
             $user = ORM::factory('user', $this->user_id);
             if ($user->loaded) {
                 $user->username = $username;
                 $user->name = $post->name;
                 $user->email = $post->email;
                 $user->notify = $post->notify;
                 $user->public_profile = $post->public_profile;
                 $user->color = $post->color;
                 $user->needinfo = $needinfo;
                 if ($post->new_password != '') {
                     $user->password = $post->new_password;
                 }
                 $user->save();
                 // We also need to update the RiverID server with the new password if
                 //    we are using RiverID and a password is being passed
                 if (kohana::config('riverid.enable') == TRUE and !empty($user->riverid) and $post->new_password != '') {
                     $riverid = new RiverID();
                     $riverid->email = $user->email;
                     $riverid->password = $post->current_password;
                     $riverid->new_password = $post->new_password;
                     if ($riverid->changepassword() == FALSE) {
                         // TODO: Something went wrong. Tell the user.
                     }
                 }
             }
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             $form['new_password'] = "";
             $form['password_again'] = "";
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('auth'));
             $form_error = TRUE;
         }
     } else {
         $user = ORM::factory('user', $this->user_id);
         $form['username'] = $user->username;
         $form['name'] = $user->name;
         $form['email'] = $user->email;
         $form['notify'] = $user->notify;
         $form['public_profile'] = $user->public_profile;
         $form['color'] = $user->color;
     }
     // If $user was never set above, we need to grab it now.
     if (!isset($user)) {
         $user = ORM::factory('user', $this->user_id);
     }
     if ($user->public_profile == 1) {
         $this->template->content->profile_public = TRUE;
         $this->template->content->profile_private = FALSE;
     } else {
         $this->template->content->profile_public = FALSE;
         $this->template->content->profile_private = TRUE;
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->yesno_array = array('1' => strtoupper(Kohana::lang('ui_main.yes')), '0' => strtoupper(Kohana::lang('ui_main.no')));
     // Javascript Header
     $this->template->colorpicker_enabled = TRUE;
 }
Esempio n. 2
0
 public function index()
 {
     $this->template->content = new View('admin/profile');
     // setup and initialize form field names
     $form = array('current_password' => '', 'new_password' => '', 'password_again' => '', 'name' => '', 'email' => '', 'notify' => '');
     //  Copy the form as errors, so the errors will be stored with keys
     //  corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         $post = Validation::factory($_POST);
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         $post->add_rules('name', 'required', 'length[3,100]');
         $post->add_rules('email', 'required', 'email', 'length[4,64]');
         $post->add_rules('current_password', 'required');
         $post->add_callbacks('email', array($this, 'email_exists_chk'));
         $post->add_callbacks('current_password', array($this, 'current_pw_valid_chk'));
         // If Password field is not blank
         if (!empty($post->new_password)) {
             $post->add_rules('new_password', 'required', 'length[' . Kohana::config('auth.password_length') . ']', 'matches[password_again]');
         }
         //for plugins that'd like to know what the user has to say about their profile
         Event::run('ushahidi_action.profile_add_admin', $post);
         if ($post->validate()) {
             $user = ORM::factory('user', $this->user_id);
             if ($user->loaded) {
                 $user->name = $post->name;
                 $user->email = $post->email;
                 $user->notify = $post->notify;
                 if ($post->new_password != '') {
                     $user->password = $post->new_password;
                 }
                 $user->save();
                 Event::run('ushahidi_action.profile_edit', $user);
                 // We also need to update the RiverID server with the new password if
                 //    we are using RiverID and a password is being passed
                 if (kohana::config('riverid.enable') == TRUE and !empty($user->riverid) and $post->new_password != '') {
                     $riverid = new RiverID();
                     $riverid->email = $user->email;
                     $riverid->password = $post->current_password;
                     $riverid->new_password = $post->new_password;
                     if ($riverid->changepassword() == FALSE) {
                         // TODO: Something went wrong. Tell the user.
                     }
                 }
             }
             $form_saved = TRUE;
             // Repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             $form['new_password'] = "";
             $form['password_again'] = "";
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('auth'));
             $form_error = TRUE;
         }
     } else {
         $user = ORM::factory('user', $this->user_id);
         $form['username'] = $user->email;
         $form['name'] = $user->name;
         $form['email'] = $user->email;
         $form['notify'] = $user->notify;
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->yesno_array = array('1' => utf8::strtoupper(Kohana::lang('ui_main.yes')), '0' => utf8::strtoupper(Kohana::lang('ui_main.no')));
     // Javascript Header
 }