Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* login logic: */
- public function action_signin()
- {
- $this->init();
- $page = View::factory('main/signin');
- if ($_POST)
- {
- $user = ORM::factory('user');
- // if ($user->login($_POST))
- // if (Auth::login($_POST['username'], $_POST['password'], isset($_POST['remember'])))
- echo "username: ".$_POST['username']."<br>";
- echo "password: ".$_POST['password']."<br>";
- if (isset($_POST['remember'])) var_dump($_POST['remember']);
- if (Auth::instance()->login($_POST['username'], $_POST['password'], isset($_POST['remember'])))
- {
- if ($user->has('roles', ORM::factory('role', array('name' => 'admin'))))
- {
- echo "redirect yourself to admin.<br>";
- exit;
- $this->request->redirect('admin');
- }
- else
- {
- echo "inside Controller_Main action_signin(). This user did not have any roles set to redirect, sooo you should make one :)<br>";
- // $page->status = "yew logged in! :D";
- // $this->init();
- }
- }
- else
- {
- $page->status = "Username or password is incorrect, or your login privileges have been suspended.";
- // $this->template->content = $_POST->errors('signin');
- // print_r($_POST);
- }
- }
- /* overloaded user model */
- <?php defined('SYSPATH') or die('No direct access allowed.');
- class Model_User extends Model_Auth_User {
- public $primary_contact;
- public function __construct($id = NULL)
- {
- // additional relationships
- $this->_has_one['mod_by'] = array('model' => 'user', 'foreign_key' => 'mod_by_id');
- $this->_has_many['contacts'] = array();
- parent::__construct($id);
- // load primary contact
- if ($this->loaded())
- {
- $this->primary_contact = ORM::factory('contact')->where('user_id', '=', $this->id)->and_where('type', '=', 'PRIMARY')->find();
- }
- else
- {
- $this->primary_contact = ORM::factory('contact');
- }
- }
- // from () to (Validation $validation = NULL)
- public function save(Validation $validation = NULL)
- {
- if (! $this->loaded())
- {
- $this->date_created = date('Y-m-d H:i:s');
- }
- $current_user = Auth::instance()->get_user();
- if ($current_user)
- {
- $this->date_modified = date('Y-m-d H:i:s');
- $this->mod_by_id = $current_user->id;
- }
- parent::save($validation);
- }
- } // End User Model
- /* inside auth config file */
- <?php defined('SYSPATH') or die('No direct access allowed.');
- return array(
- 'driver' => 'orm',
- 'hash_method' => 'sha256',
- 'hash_key' => 'FA23',
- 'lifetime' => 1209600,
- 'session_key' => 'auth_user',
- // Username/password combinations for the Auth File driver
- 'users' => array(
- // 'admin' => 'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02',
- ),
- );
- /* inside post processor */
- if (isset($_POST['save']))
- {
- $user = ORM::factory('user', $_POST['id']);
- $user->email = $_POST['email'];
- $user->username = $_POST['username'];
- if ($user->loaded())
- {
- $user->save();
- // remove all previous roles (they will be re-added after this if statement)
- foreach ($user->roles->find_all() as $role)
- {
- $user->remove('roles', ORM::factory('role', $role));
- }
- }
- else
- {
- $user->password = $_POST['password'];
- $user->save();
- }
- // user roles
- foreach ($_POST['roles'] as $role_id)
- {
- $user->add('roles', ORM::factory('role', $role_id));
- }
- // update/add PRIMARY contact
- $contact = ORM::factory('contact', $_POST['contact_id']);
- $contact->ProcessPost($_POST);
- $contact->user_id = $user->id;
- $contact->save();
- // set ID so we are still viewing this user
- $id = $user->id;
- $user_list = ORM::factory('user')->find_all()->as_array('id', 'username');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement