mirror of
https://github.com/Ekokumppanit/ystavakylaecard.git
synced 2026-02-20 16:49:35 +00:00
Initial commit, Ecard system build with CodeIgniter PHP framework
Currently working - Basic structure - Basic caching and gzip compression for speed - Admin authentication
This commit is contained in:
committed by
Ismo Vuorinen
parent
345d8ea65a
commit
c10c9e3131
20
application/models/ecard_model.php
Normal file
20
application/models/ecard_model.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Ecard
|
||||
*/
|
||||
class Ecard_model extends MY_Model
|
||||
{
|
||||
public $before_create = array( 'timestamps' );
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function timestamps($book)
|
||||
{
|
||||
$book['created_at'] = $book['updated_at'] = date('Y-m-d H:i:s');
|
||||
return $book;
|
||||
}
|
||||
}
|
||||
87
application/models/erkanaauth_model.php
Executable file
87
application/models/erkanaauth_model.php
Executable file
@@ -0,0 +1,87 @@
|
||||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Erkanaauth_model extends CI_Model {
|
||||
|
||||
var $db_table = 'users';
|
||||
var $db_userid = 'id';
|
||||
|
||||
function __construct()
|
||||
{
|
||||
// Call the Model constructor
|
||||
parent::__construct();
|
||||
log_message('debug', 'Authorization class initialized (model Erkanaauth).');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempt to login using the given condition
|
||||
*
|
||||
* Accepts an associative array as input, containing login conditions
|
||||
* Example:
|
||||
* $conditions = array
|
||||
* (
|
||||
* 'email'=>$email,
|
||||
* 'password'=>dohash($password)
|
||||
* );
|
||||
* $this->erkanaauth->try_login($conditions));
|
||||
*
|
||||
* @access public
|
||||
* @param array login conditions
|
||||
* @return mixed boolean:false or object with user record
|
||||
*/
|
||||
function try_login($condition = array())
|
||||
{
|
||||
$query = $this->db->get_where($this->db_table, $condition, 1, 0);
|
||||
|
||||
if ($query->num_rows != 1) return FALSE;
|
||||
|
||||
$row = $query->row();
|
||||
$this->session->set_userdata(array('user_id'=>$row->id));
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multipurpose: Check logged state and have the current user info
|
||||
*
|
||||
* Copied from http://codeigniter.com/forums/viewthread/63423/P30/:
|
||||
* getUser() now returns a user's record and can be
|
||||
* used to determine login status as well as retrieving
|
||||
* user information. Right now it doesnt support roles
|
||||
* (so if you use that system, add in a JOIN to the method below)
|
||||
* but it will when I actually release this version
|
||||
*
|
||||
* @access public
|
||||
* @param int the user id, defaults to session user_id
|
||||
* @return mixed boolean:false or object with user record
|
||||
*/
|
||||
function getUser($id = FALSE)
|
||||
{
|
||||
if ($id == FALSE) $id = $this->session->userdata('user_id');
|
||||
|
||||
if ($id == FALSE) return FALSE;
|
||||
|
||||
$condition = array(($this->db_table .'.' .$this->db_userid) =>$id);
|
||||
|
||||
$query = $this->db->get_where($this->db_table, $condition, 1, 0);
|
||||
|
||||
$row = ($query->num_rows() == 1) ? $query->row() : FALSE;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a user out
|
||||
*
|
||||
* Example: $this->erkanaauth->logout()
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function logout()
|
||||
{
|
||||
$this->session->set_userdata(array('user_id'=>FALSE));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
10
application/models/index.html
Normal file
10
application/models/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user