Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( ! defined('SB_ENGINE_PATH')) exit('No direct script access allowed');
- /**
- * @package sambhuti
- * @author Piyush Mishra<me[at]piyushmishra[dot]com>
- */
- class login extends baseController
- {
- function __construct()
- {
- parent::__construct();
- if($this->session->get('auth') && $this->uri->segment(2)!="logout")
- header("Location:".$this->uri->site_url);
- }
- function index()
- {
- $this->load->view('login_form');
- }
- function signup()
- {
- $this->load->view('signup_form');
- }
- function do_signup()
- {
- $this->load->model('user');
- // $this->user->getpass();
- if($this->input->hasVar('email'))
- {
- $this->input->set('email',FILTER_VALIDATE_EMAIL);
- $this->input->set('fname',FILTER_VALIDATE_REGEXP,array("options"=>array('regexp'=>'/^([a-zA-Z]+)$/')));
- $this->input->set('lname',FILTER_VALIDATE_REGEXP,array("options"=>array('regexp'=>'/^([a-zA-Z]+)$/')));
- $this->input->set('pass',FILTER_UNSAFE_RAW);
- $this->input->set('pass2',FILTER_UNSAFE_RAW);
- $this->input->set('slug',FILTER_VALIDATE_REGEXP,array("options"=>array('regexp'=>'/^([a-zA-Z_]+)$/')));
- $email = $this->input->get('email');
- $fname = $this->input->get('fname');
- $lname = $this->input->get('lname');
- $slug = $this->input->get('slug');
- if(($this->input->get('pass')===$this->input->get('pass2')) && strlen($this->input->get('pass'))>8)
- if(strlen($email) && strlen ($fname) && strlen ($lname) && strlen($slug))
- {
- $key=$this->user->keygen($email);
- if($this->user->create($fname,$lname,$email,$slug,$this->input->get('pass'),$key))
- {
- echo "Success!"." <a href='".$this->uri->site_url."login'>Login now</a> the key will be mailed in real site.<br /> you wont need it now... its ".$key;
- echo "<br />"."This part takes place when user clicks on email. Auto activating....";
- if($this->user->checkactivate($key))
- echo "<br />"."Activated";
- else
- echo "<br />"."Couldnt activate!. <a href='".$this->uri->site_url."login/activate/".$key."'>Click to activate</a>";
- }
- else
- exit("Cannot take that in. na ha!!"." <a href='".$this->uri->site_url."login/signup'>Go back</a>");
- }
- else
- exit("fill the form properly!"." <a href='".$this->uri->site_url."login/signup'>Go back</a>");
- else
- exit("Passwords huh!!! Minimum 8 chars and should match!!!!"." <a href='".$this->uri->site_url."login/signup'>Go back</a>");
- //$this->input->hasvar(array('email','fname','lname','pass','pass2'));
- //print_r($this->input->getall());
- }
- else
- {
- header("Location:".$this->uri->site_url."login/signup");
- die();
- }
- }
- function logout()
- {
- $this->session->destroy();
- header("Location:".$this->uri->site_url."login");
- die();
- }
- function activate($key=null)
- {
- if(is_null($key) || strlen($key)!=32)
- exit("Invalid key");
- else
- {
- $this->load->model('user');
- if($this->user->checkactivate($key))
- echo "User Activated"."<a href='".$this->uri->site_url."login'>Login now</a>";
- else
- exit("Invalid key");
- }
- }
- function check_auth()
- {
- $this->load->model('user');
- if($this->input->hasVar('email'))
- {
- $this->input->set('email',FILTER_VALIDATE_EMAIL);
- $this->input->set('pass',FILTER_UNSAFE_RAW);
- $email=$this->input->get('email');
- $pass_from_user=$this->input->get('pass');
- if($this->user->emailexists($email))
- {
- $pass_from_db=$this->user->getpass($email);
- $salt=$this->user->fetchsalt($pass_from_db);
- $calc_pass=$this->user->hashpass($pass_from_user,$salt);
- if($calc_pass==$pass_from_db)
- {
- $this->session->set('auth',true);
- $this->session->set('user',serialize($this->user->getbyemail($email)));
- header("Location:".$this->uri->site_url."profile");
- die();
- }
- }
- exit("Error logging in :( "."<a href='".$this->uri->site_url."login'>Go back</a>");
- }
- else
- {
- header("Location:".$this->uri->site_url."login");
- die();
- }
- //echo $this->user->create("Piyush","Mishra","mymail".rand(1,10000)."@piyush.com","pass","wtf".rand(1,10000)."key");
- //echo "All users<br /><pre>";
- //print_r($this->user->getall());
- }
- /*
- * for testing only
- function fakemake()
- {
- $this->load->model('user');
- echo $this->user->create("Piyush","Mishra","mymail".rand(1,10000)."@piyush.com","pass","wtf".rand(1,10000)."key");
- }
- function check_few()
- {
- $array=array(1,5,8,2,15,9);
- $this->load->model('user');
- echo "<pre>";
- print_r($this->user->getsome($array));
- }*/
- }
- /**
- * End of file Login
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement