Welcome Guest, Not a member yet? Register   Sign In
function is taking a while
#1

[eluser]jblack199[/eluser]
Greetings, so I just created a function to reset a users password. It also sends out an email at the same time, but the function seems to be running a bit slow for my taste.

in my controller:

Code:
public function forgot() {
        $this->load->library('valid_email');
        $err = "";
        if ($this->input->post('email') == '' ) { $err .= "<li>Email address cannot be blank.</li>"; }
        elseif ($this->valid_email->verify_email($this->input->post('email')) == '0') { $err .= "<li>Email Address must be a valid address.</li>";}
        
        if ($err != '') {
            $resp['response'] = 'false';
            $resp['msg'] = '<ul>'.$err.'</ul>';
            echo json_encode($resp);
        } else {
            $check = $this->loginmodel->forgotpass(randomPassword());
            echo $check;
        }
    }

and in my model, which is autoloaded

Code:
function forgotpass($pass) {
        $query = $this->db
        ->where('email', $this->input->post('email'))
        ->get('users');
        if ($query->num_rows < 1 ) {
            $resp['response'] = 'false';
            $resp['msg'] = '<ul><li>The email address supplied could not be found. Please try again.</li></ul>';
            $response = json_encode($resp);
        } else {
            $data = array('password' => md5($pass));
            $this->db
            ->where('email', $this->input->post('email'))
            ->update('users', $data);
            $resp['response'] = 'true';
            $resp['msg'] = '<ul><li>Your password has been changed.  An email has been sent out to the email address containing your new password.</li></ul>';
            $response = json_encode($resp);
            $this->email->from('[email protected]', 'smm');
            $this->email->to($this->input->post('email'));
            $this->email->subject('subject');
            $this->email->message($this->load->view('email/forgottpass', '', TRUE);
            $this->email->send();            
        }
        
        return $response;
    }

Everything seems to go fine, it takes about 5 seconds to run from button submission to getting the response back to jQuery.

Also in the email I get

Code:
<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined variable: pass</p>
<p>Filename: emails/forgotpass.php</p>
<p>Line Number: 4</p>

which means I need to figure out how to also send through the value of my $pass to the view so that the temporary password is logged into the view file. Also, it should have been an HTML email but all the HTML is displaying as text in the email...

Any help appreciated on either making the HTML display right in the email... making the $pass display in the email, or somehow getting the script to run faster than 5 seconds.




Theme © iAndrew 2016 - Forum software by © MyBB