コード例 #1
0
ファイル: mhi.php プロジェクト: katembu/Ushahidi_Web
 public function account()
 {
     // If not logged in, go back to the start
     $session = Session::instance();
     $mhi_user_id = $session->get('mhi_user_id');
     if ($mhi_user_id == FALSE) {
         // If the user is not logged in, go home.
         url::redirect('/');
     }
     $this->template->header->this_body = '';
     $this->template->content = new View('mhi/mhi_account');
     $this->template->header->js .= new View('mhi/mhi_account_js');
     $mhi_user = new Mhi_User_Model();
     // Get user info
     $this->template->content->user = $mhi_user->get($mhi_user_id);
     $form = array('username' => '', 'password' => '');
     $form_error = FALSE;
     $errors = FALSE;
     // Set up the validation object
     $_POST = Validation::factory($_POST)->pre_filter('trim')->add_rules('firstname', 'required')->add_rules('lastname', 'required')->add_rules('email', 'required')->add_rules('password', 'required');
     if ($_POST->validate()) {
         $mhi_user = new Mhi_User_Model();
         $postdata_array = $_POST->safe_array();
         $update = $mhi_user->update($mhi_user_id, array('firstname' => $postdata_array['firstname'], 'lastname' => $postdata_array['lastname'], 'email' => $postdata_array['email'], 'password' => $postdata_array['password']));
         // If update worked, go back to manage page
         if ($update != FALSE) {
             url::redirect('mhi/manage');
         } else {
             $errors = array('Something went wrong with form submission. Please try again.');
             $form_error = TRUE;
         }
     }
     $this->template->header->form_error = $form_error;
     $this->template->header->errors = $errors;
 }
コード例 #2
0
ファイル: mhi.php プロジェクト: jetherton/Ushahidi_Web
 public function reset_password()
 {
     $this->template->header->this_body = '';
     $this->template->content = new View('mhi/mhi_reset_password');
     $this->template->content->reset_flag = FALSE;
     if ($_POST) {
         // Validate the email address
         $post = Validation::factory($_POST);
         $post->pre_filter('trim');
         $post->add_rules('email', 'required', 'email');
         if ($post->validate()) {
             $settings = kohana::config('settings');
             $mhi_user = new Mhi_User_Model();
             $email = $post->email;
             $mhi_user_id = $mhi_user->get_id($email);
             $new_password = text::rand_str(15);
             $update = $mhi_user->update($mhi_user_id, array('password' => $new_password));
             $to = $email;
             $from = $settings['site_email'];
             $subject = 'Your Crowdmap password has been reset.';
             $message = 'You have chosen to have your password reset. We have gone ahead and changed your login information to the following:' . "\n\n";
             $message .= 'E-mail: ' . $email . "\n";
             $message .= 'Password: '******'Now that your password has changed, please visit the website at http://crowdmap.com to change it to something you prefer.' . "\n\n";
             $message .= 'Thank you!' . "\n";
             $message .= 'The Crowdmap Team';
             email::send($to, $from, $subject, $message, FALSE);
             Mhi_Log_Model::log($mhi_user_id, 5);
             $this->template->content->reset_flag = TRUE;
         } else {
             throw new Kohana_User_Exception('E-mail Validation Error', "Email didn't validate");
         }
     }
 }