Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Login extends CI_Controller
- {
- public function __construct()
- {
- parent::__construct();
- $this->load->model("login_model");
- $this->load->model("user_model");
- $this->load->model("register_model");
- $this->load->model("faucet_model");
- }
- public function index()
- {
- $this->template->set_page_title("Login");
- $this->template->set_error_view("error/login_error.php", array('css_inc' =>'' ,'js_inc'=>'' ));
- $this->template->set_layout("layout/layout.php", array('css_inc' =>'' ,'js_inc'=>'' ));
- if ($this->user_model->check_block_ip()) {
- $this->template->error("You have been blocked from this site!");
- }
- if ($this->user->loggedin) {
- redirect(base_url());
- }
- $this->template->loadContent("login/index.php", array('css_inc' =>'' ,'js_inc'=>'' ));
- }
- public function go($redirect="")
- {
- $this->template->set_error_view("error/login_error.php", array('css_inc' =>'' ,'js_inc'=>'' ));
- $this->template->set_layout("layout/layout.php", array('css_inc' =>'' ,'js_inc'=>'' ));
- if ($this->user_model->check_block_ip()) {
- $this->template->error("You have been blocked from this site!");
- }
- $config = $this->config->item("cookieprefix");
- if ($this->user->loggedin) {
- $this->template->error("You are already logged in!");
- }
- $email = $this->input->post("email", true);
- $pass = $this->common->nohtml($this->input->post("pass", true));
- $remember = $this->input->post("remember", true);
- if (!$this->faucet_model->check_captcha('solvemedia')) {
- $this->template->set_error_view("error/login_error.php", array('css_inc' =>'' ,'js_inc'=>'' ));
- $this->template->error("Please fill out the captcha correctly!", array('css_inc' =>'' ,'js_inc'=>'' ));
- }
- if($this->settings->info->login_protect) {
- // Check user for 5 login attempts
- $s = $this->login_model->get_login_attempts($_SERVER['REMOTE_ADDR'],
- $email, (15*60));
- if($s->num_rows() > 0) {
- $s = $s->row();
- if($s->count >=5) {
- $this->template->error("You have attempted to login too many times! Please wait 15 minutes before trying again.");
- }
- }
- }
- if (empty($email) || empty($pass)) {
- $this->template->error("You are missing some details!");
- }
- $login = $this->login_model->getUserByEmail($email);
- if ($login->num_rows() == 0) {
- $login = $this->login_model->getUserByUsername($email);
- if($login->num_rows() == 0) {
- $this->login_protect($email);
- $this->template->error("Invalid Login Details!");
- }
- }
- $r = $login->row();
- $userid = $r->ID;
- $email = $r->email;
- $phpass = new PasswordHash(12, false);
- if (!$phpass->CheckPassword($pass, $r->password)) {
- $this->login_protect($email);
- $this->template->error("Invalid Login Details!");
- }
- if($this->settings->info->secure_login) {
- // Generate a token
- $token = rand(1,100000) . $email;
- $token = md5(sha1($token));
- // Store it
- $this->login_model->updateUserToken($userid, $token);
- } else {
- if(empty($r->token)) {
- // Generate a token
- $token = rand(1,100000) . $email;
- $token = md5(sha1($token));
- // Store it
- $this->login_model->updateUserToken($userid, $token);
- } else {
- if($r->online_timestamp + (3600*24*30*2) < time() ) {
- // Generate a token
- $token = rand(1,100000) . $email;
- $token = md5(sha1($token));
- // Store it
- $this->login_model->updateUserToken($userid, $token);
- } else {
- $token = $r->token;
- }
- }
- }
- // Create Cookies
- if ($remember == 1) {
- $ttl = 3600*24*31;
- } else {
- $ttl = 3600*24*31;
- }
- setcookie($config . "un", $email, time()+$ttl, "/");
- setcookie($config . "tkn", $token, time()+$ttl, "/");
- if(!empty($redirect)) {
- redirect(site_url(urldecode($redirect)));
- } else {
- redirect(base_url());
- }
- }
- private function login_protect($email)
- {
- // Add Count
- $s = $this->login_model
- ->get_login_attempts($_SERVER['REMOTE_ADDR'],
- $email, (15*60));
- if($s->num_rows() > 0) {
- $s = $s->row();
- $this->login_model->update_login_attempt($s->ID, array(
- "count" => $s->count+1
- )
- );
- } else {
- $this->login_model->add_login_attempt(array(
- "IP" => $_SERVER['REMOTE_ADDR'],
- "username" => $email,
- "count" => 1,
- "timestamp" => time()
- )
- );
- }
- }
- public function logout($hash)
- {
- $this->template->set_error_view("error/login_error.php");
- $config = $this->config->item("cookieprefix");
- $this->load->helper("cookie");
- if ($hash != $this->security->get_csrf_hash() ) {
- echo'hash';
- //$this->template->error(lang("error_6"));
- redirect(base_url());
- exit;
- }
- delete_cookie($config. "un");
- delete_cookie($config. "tkn");
- delete_cookie($config. "provider");
- delete_cookie($config. "oauthid");
- delete_cookie($config. "oauthtoken");
- delete_cookie($config. "oauthsecret");
- $this->session->sess_destroy();
- redirect(base_url());
- }
- public function banned()
- {
- $this->template->set_error_view("error/login_error.php");
- $this->template->set_layout("layout/login_layout.php");
- $this->template->loadContent("login/banned.php", array());
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement