Codeigniter password dimenticata

Jakub Lemiszewski

Utente Attivo
5 Dic 2013
119
1
0
Ho creato delle funzioni per avere nel mio forum la possibilita di resettare la password ma non funziona.
Ecco qua il codice.
http://jaku0260.keaweb.dk/index.php/user/resend_password
Form:

HTML:
<div class="container-forgot">
		
		<form class="form-horizontal well" method="post" id="form" action="<?php echo base_url();?>user/doforget">
			<fieldset>
	          <legend>Reset password</legend>
			
				<div class="control-group">
					<label for="email"> Email</label>
					<input class="box" type="text" id="email" name="email" />
				</div>
				<div class="form-actions">
					<input type="submit" class="btn btn-primary" value="Reset" />
				</div>
				<?php if( isset($info)): ?>
					<div class="alert alert-success">
						<?php echo($info) ?>
					</div>
				<?php elseif( isset($error)): ?>
					<div class="alert alert-error">
						<?php echo($error) ?>
					</div>
				<?php endif; ?>
				
			</fieldset>
		</form>
	</div>

Controller:

PHP:
public function resend_password(){
  if (isset($_GET['info'])) {
               $data['info'] = $_GET['info'];
              }
		if (isset($_GET['error'])) {
              $data['error'] = $_GET['error'];
              }
		$this->load->view('user/resend_password');
 }

Metodo:

PHP:
public function doforget()
	{
		$this->load->helper('url');
		$email= $_POST['email'];
		$q = $this->db->query("select * from users where email='" . $email . "'");
        if ($q->num_rows > 0) {
            $r = $q->result();
            $user=$r[0];
			$this->resetpassword($user);
			$info= "Password has been reset and has been sent to email id: ". $email;
			redirect('/index.php/user/forget?info=' . $info, 'refresh');
        }
		$error= "The email id you entered not found on our database ";
		redirect('/index.php/user/forget?error=' . $error, 'refresh');
		
	} 
	
	private function resetpassword($user)
	{
		date_default_timezone_set('GMT');
		$this->load->helper('string');
		$password= random_string('alnum', 16);
		$this->db->where('id', $user->id);
		$this->db->update('users',array('password'=>MD5($password)));
		$this->load->library('email');
		$this->email->from('cantreply@youdomain.com', 'Your name');
		$this->email->to($user->email); 	
		$this->email->subject('Password reset');
		$this->email->message('You have requested the new password, Here is you new password:'. $password);	
		$this->email->send();
	}
 

Discussioni simili