Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Action extends CI_Controller
- {
- protected $type;
- function index()
- {
- show_error("The action you have requested is not allowed.", 403, "An Error Was Encountered");
- }
- function register()
- {
- $this->type = "login";
- $this->load->helper("form");
- $this->load->library("form_validation");
- $this->form_validation->set_rules("username", "username", "trim|required|max_length[10]|min_length[1]");
- $this->form_validation->set_rules("password", "password", "trim|required|min_length[1]");
- $this->form_validation->set_rules("passver", "second password", "trim|required|min_length[1]|matches[password]");
- $this->form_validation->set_rules("email", "email", "trim|required|min_length[1]|valid_email");
- $this->form_validation->set_rules("phone", "phone", "trim|required|min_length[1]");
- $this->form_validation->set_rules("g-recaptcha-response", "captcha", "required");
- if($this->form_validation->run() == FALSE)
- {
- $this->load->library("pageloadpreset");
- $this->pageloadpreset->load("register", $this);
- }
- else
- {
- $this->form_validation->set_rules("g-recaptcha-response", "captcha", "callback_captcha_check");
- if($this->form_validation->run() == FALSE)
- {
- $this->load->library("pageloadpreset");
- $this->pageloadpreset->load("register", $this);
- }
- else
- {
- $this->form_validation->set_rules("phone", "phone", "callback_phone_check");
- if($this->form_validation->run() == FALSE)
- {
- $this->load->library("pageloadpreset");
- $this->pageloadpreset->load("register", $this);
- }
- else
- {
- //$this->form_validation->set_rules("password", "password", "callback_querydb");
- }
- }
- }
- }
- function login()
- {
- $this->type = "login";
- $this->load->helper("form");
- $this->load->library("form_validation");
- $this->form_validation->set_rules("username", "username", "trim|required|max_length[10]|min_length[1]");
- $this->form_validation->set_rules("password", "password", "trim|required|min_length[1]");
- if($this->form_validation->run() == FALSE)
- {
- $this->load->library("pageloadpreset");
- $this->pageloadpreset->load("login", $this);
- }
- else
- {
- $this->form_validation->set_rules("password", "password", "callback_querydb");
- if($this->form_validation->run() == FALSE)
- {
- $this->load->library("pageloadpreset");
- $this->pageloadpreset->load("login", $this);
- }
- else
- {
- echo "ok";
- }
- }
- }
- function querydb($parameter)
- {
- $this->load->model("dbsystem", "", TRUE);
- if($this->type == "login")
- {
- $username = $this->input->post("username");
- $password = $parameter;
- $loginResult = $this->dbsystem->login($username, $password);
- if($loginResult != "mse")
- {
- if($loginResult != "unf")
- {
- if($loginResult != "wp")
- {
- $sessionArray = array();
- foreach($loginResult as $row)
- {
- $sessionArray = array(
- "username" => $row->username
- );
- $this->session->set_userdata("logged_in", $sessionArray);
- }
- return TRUE;
- }
- else
- {
- $this->form_validation->set_message("querydb", "Invalid password");
- return FALSE;
- }
- }
- else
- {
- $this->form_validation->set_message("querydb", "This user was not found");
- return FALSE;
- }
- }
- else
- {
- show_error("A fatal error occured, the site admins have been notified. If this error persists, try again later.", 500, "Error");
- log_message("error", "Mysql connection error!");
- return FALSE;
- }
- }
- else if($this->type == "register")
- {
- }
- }
- function captcha_check($captchaResponse)
- {
- $ip = $this->input->ip_address();
- $pkey = "6LeewiYTAAAAAA7MZt_Rn62qsIwRV3IjrtBpOUS3";
- $url = "https://www.google.com/recaptcha/api/siteverify?secret=".$pkey."&response=".$captchaResponse."&remoteip=".$ip."";
- $req = curl_init($url);
- curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false);
- if($res = curl_exec($req))
- {
- curl_close($req);
- $res = json_decode($res, true);
- if($res['success'] == true)
- {
- return TRUE;
- }
- else
- {
- $this->form_validation->set_message("captcha_check", "Invalid captcha");
- return FALSE;
- }
- }
- else
- {
- show_error("A fatal error occured, the site admins have been notified. If this error persists, try again later.", 500, "Error");
- log_message("error", "Curl error!");
- }
- }
- function phone_check($phone)
- {
- $access_key = "68b7972ae57423e8cfb197fd4dbf53d0";
- $url = "http://apilayer.net/api/validate?access_key=".$access_key."&number=".$phone."&country_code=&format=1";
- $req = curl_init($url);
- curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
- if($res = curl_exec($req))
- {
- curl_close($req);
- $res = json_decode($res, true);
- if($res['success'] == "true")
- {
- return TRUE;
- }
- else
- {
- $this->form_validation->set_message("phone_check", "Invalid phone number");
- return FALSE;
- }
- }
- else
- {
- show_error("A fatal error occured, the site admins have been notified. If this error persists, try again later.", 500, "Error");
- log_message("error", "Curl error!");
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement