Are you a regular stikked user? Signup so you can keep track of your pastes!
  1. <?php
  2. class Users extends Controller
  3. {
  4.         function Users()
  5.         {
  6.                 parent::Controller();
  7.         }
  8.        
  9.         function login()
  10.         {
  11.        
  12.                 $this->basetemplate->set("title","Login");
  13.                 $this->basetemplate->set("domain",$this->config->item("base_url"));
  14.                
  15.                 $this->form_validation->set_rules('user','Username','required');
  16.                 $this->form_validation->set_rules('pass','Password','required');
  17.                
  18.                 if( !$this->form_validation->run() )
  19.                 {
  20.                         $this->basetemplate->load(array(
  21.                                 'users/login'
  22.                         ));
  23.                 }
  24.                 else
  25.                 {
  26.                         if( !$this->user_exists( $this->input->post("user"), $this->input->post("pass") ) )
  27.                         {
  28.                                 $this->basetemplate->load(array(
  29.                                         'users/login'
  30.                                 ));
  31.                         }
  32.                         else
  33.                         {
  34.                                 $this->basesession->set("auth",true);
  35.                                 $this->basesession->set("user",$this->input->post("user"));
  36.                                 $this->basesession->set("pass",md5($this->input->post("pass")));
  37.                                 redirect("users/test/");
  38.                         }
  39.                 }
  40.         }
  41.         function test()
  42.         {
  43.                 print_r($_SESSION);
  44.         }
  45.         function register()
  46.         {
  47.  
  48.                 $this->form_validation->set_rules('user','Username','required');
  49.                 $this->form_validation->set_rules('pass','Password','required');
  50.                 $this->form_validation->set_rules('pass2','Password Confirmation','required|matches[pass]');
  51.                 $this->form_validation->set_rules('email','Email','required|valid_email');
  52.                 $this->form_validation->set_rules('paypal','Paypal Address','required|valid_email');
  53.                
  54.                 if( !$this->form_validation->run() )
  55.                 {
  56.                         $this->basetemplate->set("title","Register");
  57.                         $this->basetemplate->set("domain",$this->config->item("base_url"));
  58.                         $this->basetemplate->load(array(
  59.                                 'users/register',
  60.                         ));
  61.                 }
  62.                 else
  63.                 {
  64.                         $data = array(
  65.                                 'username' => $this->input->post("user"),
  66.                                 'userpass' => md5( $this->input->post("pass") ),
  67.                                 'useremail' => $this->input->post("email"),
  68.                                 'userpaypal' => $this->input->post("paypal"),
  69.                         );
  70.                         $this->db->insert("users", $data);
  71.                         redirect("/users/login");
  72.                 }
  73.                
  74.         }
  75.        
  76.         /**
  77.          * Validation Functions
  78.          *
  79.          */
  80.          
  81.         function user_exists($username,$password)
  82.         {
  83.                 $query = $this->db->get_where("users",array('username' => $username),1);
  84.                 $data = $query->result_array();
  85.                 if( empty( $data ) )
  86.                 {
  87.                         return false;
  88.                 }
  89.                 else
  90.                 {
  91.                         if( $data[0]['userpass'] == md5( $password ) )
  92.                         {
  93.                                 return true;
  94.                         }
  95.                         else
  96.                         {
  97.                                 return false;
  98.                         }
  99.                 }
  100.         }
  101. }
  102. ?>

Reply to "Untitled"

Here you can reply to the paste above

Create a snipurl

Make Private

Feeling clever? Set some advanced options.