[eluser]DephNet[Paul][/eluser]
Hi Guys,
So I have downloaded Ion Auth and started to have a bit of a play with it and while it is a good library I decided to change the way the errors are generated, which has meant that I have actually replaced most of the guts of Ion Auth with my own code. Because of this I wanted to check I was going down the right path before I get too far down and have to change masses of stuff.
I have slimmed the Ion Auth controller right down and this is what I have at the moment:
Code:
<?php
if(!defined("BASEPATH")) {exit("No direct script access allowed");}
if(!class_exists("Controller")) {class Controller extends CI_Controller {}}
class Auth extends Controller {
function __construct() {
parent::__construct();
$this->data["label"] = $this->lang->line("label");
$this->data["message"] = $this->lang->line("message");
$this->data["text"] = $this->lang->line("text");
}
function forgot_password() {
$this->data["title"] = "Recover Password";
$this->data["form"] = array("id" => "content","name" => "content");
$this->data["email"] = array("id" => "email","name" => "email");
$this->load->view("auth/forgot_password", $this->data);
}
function index() {
if(!$this->ion_auth->logged_in()) {
header("Location: " . site_url("auth/login"));
} else {
header("Location: " . site_url());
}
}
function login() {
$this->data["title"] = "Login";
$this->data["form"] = array("id" => "content","name" => "content");
$this->data["email"] = array("id" => "email","name" => "email");
$this->data["password"] = array("id" => "password","name" => "password");
$this->load->view("auth/login", $this->data);
}
function logout() {
$this->session->sess_destroy();
$this->data["title"] = "Logout";
$this->data["form"] = array("id" => "content","name" => "content");
$this->data["email"] = array("id" => "email","name" => "email");
$this->data["password"] = array("id" => "password","name" => "password");
$this->load->view("auth/logout", $this->data);
}
}
My forgot_password view is:
Code:
<?php
$this->load->view("common/header");
form_open("auth/forgot_password", $form);
echo "<input type=\"hidden\" name=\"submit\" value=\"yes\" />\n";
echo "<p class=\"info\">" . $text["forgot"] . "</p>\n";
$this->ion_auth->forgot_password($_POST);
echo "<label for=\"email\">" . $label["email"] . "</label>" . form_input($email) . "\n";
echo "<button type=\"submit\">" . $label["submit"] . "</button>\n";
echo "<button type=\"reset\" class=\"secondary\">" . $label["reset"] . "</button>\n";
form_close();
$this->load->view("common/footer");
My $this->ion_auth->forgot_password() is:
Code:
public function forgot_password($email) {
if(isset($email["submit"])) {
$email = $email["email"];
if(empty($email)) {
$type = "error";
$body = "No email address detected, please check and try again";
} else {
if (!preg_match("/@/i", $email)) {
$type = "error";
$body = "Invalid email address detected, please check and try again";
} else {
if(!checkdnsrr(substr(strstr($_POST["email"], "@"), 1),'MX')) {
$type = "error";
$body = "Invalid email domain detected, please check and try again";
} else {
if($this->ci->ion_auth_model->forgot_password("lookup", $email) === FALSE) {
$type = "error";
$body = "Email address not found, please check and try again";
} else {
$this->ci->ion_auth_model->forgot_password("email", $email);
if ($this->ci->email->send()) {
$type = "success";
$body = "Your password has been reset, please check your email";
} else {
$type = "error";
$body = "Fatal error, please contact staff for assistance";
}
}
}
}
}
echo "<div class=\"" . $type . "\">" . $body . ".</div>\n";
}
}
And finally my $this->ci->ion_auth_model->forgot_password() is:
Code:
public function forgot_password($process, $email) {
if($process === "lookup") {
$query = "SELECT * FROM users WHERE email = ?";
$query = $this->db->query($query, $email);
if ($query->num_rows() != 1) {
return FALSE;
} else {
return TRUE;
}
} elseif($process === "email") {
// Send email
}
}
My questions are:
1) Am I on the right track, or have I made any mistakes/errors that you can see?
2) I am trying to make this a multi-lingual site from the off, even though it will be in English to start with, so how can I get the messages to be read from the appropriate language file?
3) Is there anything that you can see that may cause me problems in the future?
Those are all the questions I have for the moment, and I look forward to your help
--Paul