RECUPERAR EMAIL - PROBLEMA
O sistema em questão é para uma escola de informatica está totalmente funcional, a não ser na recuperação de senha que não está chegando no email.
Abaixo os anexos destes dois arquivos.
Para quem não puder baixar, e querer ver o anexo. O código é este:
login.php
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Login extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('crud_model');
$this->load->database();
/*cash control*/
$this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
$this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
}
/***default functin, redirects to login page if no admin logged in yet***/
public function index()
{
if ($this->session->userdata('admin_login') == 1)
redirect(base_url() . 'index.php?admin/dashboard', 'refresh');
if ($this->session->userdata('teacher_login') == 1)
redirect(base_url() . 'index.php?teacher/dashboard', 'refresh');
if ($this->session->userdata('student_login') == 1)
redirect(base_url() . 'index.php?student/dashboard', 'refresh');
if ($this->session->userdata('parent_login') == 1)
redirect(base_url() . 'index.php?parents/dashboard', 'refresh');
$config = array(
array(
'field' => 'email',
'label' => 'Email',
'rules' => 'required|xss_clean|valid_email'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'required|xss_clean|callback__validate_login'
)
);
$this->form_validation->set_rules($config);
$this->form_validation->set_message('_validate_login', ucfirst($this->input->post('login_type')) . ' Login failed!');
$this->form_validation->set_error_delimiters('<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>', '</div>');
if ($this->form_validation->run() == FALSE) {
$this->load->view('login');
} else {
if ($this->session->userdata('admin_login') == 1)
redirect(base_url() . 'index.php?admin/dashboard', 'refresh');
if ($this->session->userdata('teacher_login') == 1)
redirect(base_url() . 'index.php?teacher/dashboard', 'refresh');
if ($this->session->userdata('student_login') == 1)
redirect(base_url() . 'index.php?student/dashboard', 'refresh');
if ($this->session->userdata('parent_login') == 1)
redirect(base_url() . 'index.php?parents/dashboard', 'refresh');
}
}
/***validate login****/
function _validate_login($str)
{
if ($this->input->post('login_type') == '') {
$this->session->set_flashdata('flash_message', get_phrase('select_account_type'));
redirect(base_url() . 'index.php?login', 'refresh');
return FALSE;
}
$query = $this->db->get_where($this->input->post('login_type'), array(
'email' => $this->input->post('email'),
'password' => $this->input->post('password')
));
if ($query->num_rows() > 0) {
$row = $query->row();
if ($this->input->post('login_type') == 'admin') {
$this->session->set_userdata('admin_login', '1');
$this->session->set_userdata('admin_id', $row->admin_id);
$this->session->set_userdata('name', $row->name);
$this->session->set_userdata('level', $row->level);
$this->session->set_userdata('login_type', 'admin');
}
if ($this->input->post('login_type') == 'teacher') {
$this->session->set_userdata('teacher_login', '1');
$this->session->set_userdata('teacher_id', $row->teacher_id);
$this->session->set_userdata('name', $row->name);
$this->session->set_userdata('login_type', 'teacher');
}
if ($this->input->post('login_type') == 'student') {
$this->session->set_userdata('student_login', '1');
$this->session->set_userdata('student_id', $row->student_id);
$this->session->set_userdata('name', $row->name);
$this->session->set_userdata('login_type', 'student');
}
if ($this->input->post('login_type') == 'parent') {
$this->session->set_userdata('parent_login', '1');
$this->session->set_userdata('parent_id', $row->parent_id);
$this->session->set_userdata('name', $row->name);
$this->session->set_userdata('login_type', 'parent');
}
return TRUE;
} else {
$this->session->set_flashdata('flash_message', get_phrase('login_failed'));
redirect(base_url() . 'index.php?login', 'refresh');
return FALSE;
}
}
/***DEFAULT NOR FOUND PAGE*****/
function four_zero_four()
{
$this->load->view('four_zero_four');
}
/***RESET AND SEND PASSWORD TO REQUESTED EMAIL****/
function reset_password()
{
$account_type = $this->input->post('account_type');
if ($account_type == "") {
redirect(base_url(), 'refresh');
}
$email = $this->input->post('email');
$result = $this->email_model->password_reset_email($account_type, $email); //SEND EMAIL ACCOUNT OPENING EMAIL
if ($result == true) {
$this->session->set_flashdata('flash_message', get_phrase('password_sent'));
} else if ($result == false) {
$this->session->set_flashdata('flash_message', get_phrase('account_not_found'));
}
redirect(base_url(), 'refresh');
}
/*******LOGOUT FUNCTION *******/
function logout()
{
$this->session->unset_userdata();
$this->session->sess_destroy();
$this->session->set_flashdata('logout_notification', 'logged_out');
redirect(base_url() . 'index.php?login', 'refresh');
}
}
email_model.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Email_model extends CI_Model {
function __construct()
{
parent::__construct();
}
function account_opening_email($account_type = '' , $email = '')
{
$system_name = $this->db->get_where('settings' , array('type' => 'system_name'))->row()->description;
$email_msg = "Welcome to ".$system_name."<br />";
$email_msg .= "Your account type : ".$account_type."<br />";
$email_msg .= "Your login password : ".$this->db->get_where($account_type , array('email' => $email))->row()->password."<br />";
$email_msg .= "Login Here : ".base_url()."<br />";
$email_sub = "Account opening email";
$email_to = $email;
$this->do_email($email_msg , $email_sub , $email_to);
}
function password_reset_email($account_type = '' , $email = '')
{
$query = $this->db->get_where($account_type , array('email' => $email));
if($query->num_rows() > 0)
{
$password = $query->row()->password;
$email_msg = "Your account type is : ".$account_type."<br />";
$email_msg .= "Your password is : ".$password."<br />";
$email_sub = "Password reset request";
$email_to = $email;
$this->do_email($email_msg , $email_sub , $email_to);
return true;
}
else
{
return false;
}
}
/***custom email sender****/
function do_email($msg=NULL, $sub=NULL, $to=NULL, $from=NULL)
{
$config = array();
$config['useragent'] = "Curso";
$config['mailpath'] = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol'] = "smtp";
$config['smtp_host'] = "localhost";
$config['smtp_port'] = "587";
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$this->load->library('email');
$this->email->initialize($config);
$system_name = $this->db->get_where('settings' , array('type' => 'system_name'))->row()->description;
if($from == NULL)
$from = $this->db->get_where('settings' , array('type' => 'system_email'))->row()->description;
$this->email->from($from, $system_name);
$this->email->from($from, $system_name);
$this->email->to($to);
$this->email->subject($sub);
$msg = $msg."<br /><br /><br /><br /><br /><br /><br /><hr /><center><a href=\"http://codecanyon.net/user/joyontaroy?ref=joyontaroy\">© 2013 Bayanno Hospital Management System</a></center>";
$this->email->message($msg);
$this->email->send();
//echo $this->email->print_debugger();
}
}
Quem puder me ajudar, agradeço muito!!!
Discussão (5)
Carregando comentários...