Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.70 KB | None | 0 0
  1. /* login logic: */
  2.  
  3.     public function action_signin()
  4.     {
  5.         $this->init();
  6.         $page = View::factory('main/signin');
  7.  
  8.         if ($_POST)
  9.         {
  10.             $user = ORM::factory('user');
  11. //          if ($user->login($_POST))
  12. //          if (Auth::login($_POST['username'], $_POST['password'], isset($_POST['remember'])))
  13.  
  14. echo "username: ".$_POST['username']."<br>";
  15. echo "password: ".$_POST['password']."<br>";
  16. if (isset($_POST['remember'])) var_dump($_POST['remember']);
  17.  
  18.             if (Auth::instance()->login($_POST['username'], $_POST['password'], isset($_POST['remember'])))
  19.             {
  20.                 if ($user->has('roles', ORM::factory('role', array('name' => 'admin'))))
  21.                 {
  22.                     echo "redirect yourself to admin.<br>";
  23.                     exit;
  24.                     $this->request->redirect('admin');
  25.                 }
  26.                 else
  27.                 {
  28.                     echo "inside Controller_Main action_signin(). This user did not have any roles set to redirect, sooo you should make one :)<br>";
  29. //                  $page->status = "yew logged in! :D";
  30. //                  $this->init();
  31.                 }
  32.             }
  33.             else
  34.             {
  35.                 $page->status = "Username or password is incorrect, or your login privileges have been suspended.";
  36. //              $this->template->content = $_POST->errors('signin');
  37. //              print_r($_POST);
  38.             }
  39.         }
  40.  
  41.  
  42. /* overloaded user model */
  43.  
  44. <?php defined('SYSPATH') or die('No direct access allowed.');
  45.  
  46. class Model_User extends Model_Auth_User {
  47.  
  48.     public $primary_contact;
  49.  
  50.     public function __construct($id = NULL)
  51.     {
  52.         // additional relationships
  53.         $this->_has_one['mod_by'] = array('model' => 'user', 'foreign_key' => 'mod_by_id');
  54.         $this->_has_many['contacts'] = array();
  55.         parent::__construct($id);
  56.  
  57.         // load primary contact
  58.         if ($this->loaded())
  59.         {
  60.             $this->primary_contact = ORM::factory('contact')->where('user_id', '=', $this->id)->and_where('type', '=', 'PRIMARY')->find();
  61.         }
  62.         else
  63.         {
  64.             $this->primary_contact = ORM::factory('contact');
  65.         }
  66.     }
  67.  
  68.     // from () to (Validation $validation = NULL)
  69.     public function save(Validation $validation = NULL)
  70.     {
  71.         if (! $this->loaded())
  72.         {
  73.             $this->date_created = date('Y-m-d H:i:s');
  74.         }
  75.  
  76.         $current_user = Auth::instance()->get_user();
  77.  
  78.         if ($current_user)
  79.         {
  80.             $this->date_modified = date('Y-m-d H:i:s');
  81.             $this->mod_by_id = $current_user->id;
  82.         }
  83.         parent::save($validation);
  84.     }
  85.  
  86. } // End User Model
  87.  
  88. /* inside auth config file */
  89.  
  90. <?php defined('SYSPATH') or die('No direct access allowed.');
  91.  
  92. return array(
  93.  
  94.     'driver'       => 'orm',
  95.     'hash_method'  => 'sha256',
  96.     'hash_key'     => 'FA23',
  97.     'lifetime'     => 1209600,
  98.     'session_key'  => 'auth_user',
  99.  
  100.     // Username/password combinations for the Auth File driver
  101.     'users' => array(
  102.         // 'admin' => 'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02',
  103.     ),
  104.  
  105. );
  106.  
  107.  
  108. /* inside post processor */
  109.             if (isset($_POST['save']))
  110.             {
  111.                 $user = ORM::factory('user', $_POST['id']);
  112.                 $user->email = $_POST['email'];
  113.                 $user->username = $_POST['username'];
  114.  
  115.                 if ($user->loaded())
  116.                 {
  117.                     $user->save();
  118.  
  119.                     // remove all previous roles (they will be re-added after this if statement)
  120.                     foreach ($user->roles->find_all() as $role)
  121.                     {
  122.                         $user->remove('roles', ORM::factory('role', $role));
  123.                     }
  124.                 }
  125.                 else
  126.                 {
  127.                     $user->password = $_POST['password'];
  128.                     $user->save();
  129.                 }
  130.  
  131.                 // user roles
  132.                 foreach ($_POST['roles'] as $role_id)
  133.                 {
  134.                     $user->add('roles', ORM::factory('role', $role_id));
  135.                 }
  136.  
  137.                 // update/add PRIMARY contact
  138.                 $contact = ORM::factory('contact', $_POST['contact_id']);
  139.                 $contact->ProcessPost($_POST);
  140.                 $contact->user_id = $user->id;
  141.                 $contact->save();
  142.  
  143.                 // set ID so we are still viewing this user
  144.                 $id = $user->id;
  145.                 $user_list = ORM::factory('user')->find_all()->as_array('id', 'username');
  146.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement