Viewing file: Auth.php (7.67 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Auth extends CI_Controller {
function __construct()
{
parent::__construct();
if ($this->session->userdata('login'))
{
redirect('../panel');
die();
}
}
public function login()
{
$this->lang->load('auth');
$this->load->view('theme-'.$this->config->item("theme").'/login');
}
public function register()
{
$this->lang->load('auth');
$this->load->view('theme-'.$this->config->item("theme").'/register');
}
public function reset_password()
{
$this->lang->load('auth');
$this->load->view('theme-'.$this->config->item("theme").'/reset_password');
}
public function reset_password_form($key)
{
$this->lang->load('auth');
$this->load->model('auth_model');
if($this->auth_model->checkResetKey($key)) {
$data["key"] = $key;
$this->load->view('theme-'.$this->config->item("theme").'/reset_password_form', $data);
}
else {
header("Location: /reset-password");
}
}
public function login_post() {
$this->lang->load('auth');
if($this->input->post('email') && $this->input->post('password')) {
$this->load->model('auth_model');
$checkUser = $this->auth_model->checkUser($this->input->post("email"),$this->input->post("password"));
if($checkUser) {
$this->session->set_userdata("login", $this->input->post('email'));
echo json_encode(array(
"success" => true,
"title" => $this->lang->line("login_successful"),
"message" => $this->lang->line("login_successful_message")
));
}
else {
echo json_encode(array(
"success" => false,
"title" => $this->lang->line("login_failed"),
"message" => $this->lang->line("login_failed_message")
));
}
}
else {
echo json_encode(array(
"success" => false,
"title" => $this->lang->line("login_failed"),
"message" => $this->lang->line("login_failed_message")
));
}
}
public function recaptcha_verify($recaptcha_response) {
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
$recaptcha_secret = $this->config->item('recaptcha_secret_key');
$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&response=' . $recaptcha_response);
return json_decode($recaptcha)->score >= 0.5;
}
public function register_post() {
$this->lang->load('auth');
if($this->input->post('name') && $this->input->post('email') && $this->input->post('password') && $this->input->post('password_again') && $this->input->post("recaptcha_response")) {
if($this->input->post('password') == $this->input->post('password_again')) {
if(strlen($this->input->post('password')) > 5) {
if($this->recaptcha_verify($this->input->post('recaptcha_response'))) {
$this->load->model('auth_model');
if(!$this->auth_model->checkEmail($this->input->post('email'))) {
if($this->auth_model->insertUser(strip_tags($this->input->post('name')), strip_tags($this->input->post('email')), $this->input->post('password'), $this->input->post('city'), $this->input->post('address'))) {
$this->session->set_userdata("login", $this->input->post('email'));
echo json_encode(array(
"success" => true,
"title" => $this->lang->line("register_successful"),
"message" => $this->lang->line("register_successful_message")
));
}
}
else {
echo json_encode(array(
"success" => false,
"title" => $this->lang->line("register_failed"),
"message" => $this->lang->line("email_found")
));
}
}
else {
echo json_encode(array(
"success" => false,
"title" => $this->lang->line("recaptcha_failed"),
"message" => $this->lang->line("recaptcha_failed_message")
));
}
}
else {
echo json_encode(array(
"success" => false,
"title" => $this->lang->line("register_failed"),
"message" => $this->lang->line("password_short")
));
}
}
else {
echo json_encode(array(
"success" => false,
"title" => $this->lang->line("register_failed"),
"message" => $this->lang->line("passwords_not_equal")
));
}
}
else {
echo json_encode(array(
"success" => false,
"title" => $this->lang->line("register_failed"),
"message" => $this->lang->line("please_fill_all_fields")
));
}
}
public function reset_password_post() {
$this->lang->load('auth');
if($this->input->post('email')) {
$this->load->model('auth_model');
$user = $this->auth_model->getUserByEmail($this->input->post('email'));
if(isset($user["id"])) {
$this->load->library('email');
$config = array(
'protocol' => 'smtp',
'smtp_host' => $this->config->item('smtp_host'),
'smtp_port' => $this->config->item('smtp_port'),
'smtp_user' => $this->config->item('smtp_user'),
'smtp_pass' => $this->config->item('smtp_pass'),
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
$fromemail = $this->config->item('smtp_user');
$toemail = $this->input->post('email');
$subject = $this->lang->line("reset_password")." - ".$this->config->item("site_name");
$data=array();
$data["link"] = $this->config->item('base_url') ."reset-password/". md5($user["email"].$user["password"]);
$mesg = $this->load->view('theme-'.$this->config->item("theme").'/email/reset_password',$data,true);
$config=array(
'charset'=>'utf-8',
'wordwrap'=> TRUE,
'mailtype' => 'html'
);
$this->email->initialize($config);
$this->email->to($toemail);
$this->email->from($fromemail, $this->config->item("site_name"));
$this->email->subject($subject);
$this->email->message($mesg);
if($this->email->send()) {
echo json_encode(array(
"success" => true,
"title" => $this->lang->line("reset_password_email_sent"),
"message" => $this->lang->line("reset_password_email_sent_message")
));
}
else {
echo json_encode(array(
"success" => false,
"title" => $this->lang->line("reset_password_failed"),
"message" => $this->lang->line("an_error_occurred")
));
}
}
else {
echo json_encode(array(
"success" => false,
"title" => $this->lang->line("reset_password_failed"),
"message" => $this->lang->line("user_not_found")
));
}
}
else {
echo json_encode(array(
"success" => false,
"title" => $this->lang->line("reset_password_failed"),
"message" => $this->lang->line("please_fill_all_fields")
));
}
}
public function reset_password_form_post() {
$this->lang->load('auth');
if($this->input->post('key') && $this->input->post('password')) {
$this->load->model('auth_model');
if(strlen($this->input->post('password')) > 5) {
$this->auth_model->resetPasswordByKey($this->input->post('password'), $this->input->post('key'));
echo json_encode(array(
"success" => true,
"title" => $this->lang->line("reset_password_successful"),
"message" => $this->lang->line("reset_password_successful_message")
));
}
else {
echo json_encode(array(
"success" => false,
"title" => $this->lang->line("reset_password_failed"),
"message" => $this->lang->line("password_short")
));
}
}
else {
echo json_encode(array(
"success" => false,
"title" => $this->lang->line("reset_password_failed"),
"message" => $this->lang->line("please_fill_all_fields")
));
}
}
}
|