dreamjob/app/Controller/Component/MiconwareSessionComponent.php

84 lines
2.6 KiB
PHP
Raw Normal View History

2014-02-18 12:10:29 +01:00
<?php
App::uses('Component', 'Controller');
class MiconwareSessionComponent extends Component {
public $components = array('Session');
2014-02-19 00:02:17 +01:00
public $self_worker_obj;
public $self_company_obj;
2014-02-18 12:10:29 +01:00
public function init($controller){
$controller->Security->requireSecure();
$this->User = ClassRegistry::init('User');
2014-02-19 00:02:17 +01:00
$this->refreshCache();
2014-02-18 12:10:29 +01:00
}
public function initWeb($controller){
$controller->set("isLoggedin",$this->isLoggedin());
2014-02-19 00:02:17 +01:00
if($this->isLoggedin()){
$controller->set("WORKER",($this->self_worker_obj)?$this->self_worker_obj:false);
$controller->set("COMPANY",($this->self_company_obj)?$this->self_company_obj:false);
}
2014-02-18 12:10:29 +01:00
$controller->set("isStaff",$this->isStaff());
2014-04-15 19:47:57 +02:00
$controller->set("MEDIA",'/uploads');
2014-04-29 14:25:25 +02:00
$controller->set("strip_tags",'<b><i><br><ol><ul><li><h1><h2><h3><h4><h5><h6><blockquote><u><img><a><span><div><pre><code>');
2014-02-23 10:59:00 +01:00
$controller->set('default_sForm',array(
2014-02-18 12:10:29 +01:00
'inputDefaults' => array(
'div' => array('class' => 'control-group'),
'label' => array('class' => 'control-label'),
'between' => '<div class="controls">',
'after' => '</div>',
'class' => ''))
);
2014-03-15 01:52:07 +01:00
$controller->set('default_hForm',array(
'inputDefaults' => array(
2014-04-01 20:58:36 +02:00
'div' => true,
2014-03-28 16:22:19 +01:00
'label' => false,
'error' => false,
2014-03-15 01:52:07 +01:00
'class' => 'form-control '),
2014-04-01 20:58:36 +02:00
'class'=>'tableForm'
2014-03-15 01:52:07 +01:00
)
);
2014-02-23 10:59:00 +01:00
$controller->set('default_Form',array(
'inputDefaults' => array(
'div' => array('class' => 'form-group'),
2014-03-16 11:09:10 +01:00
'label' => array('class' => 'col-sm-3 control-label'),
'between' => '<div class="col-sm-9">',
2014-02-23 10:59:00 +01:00
'after' => '</div>',
2014-03-12 17:42:02 +01:00
'error' => array('attribute'=>array('wrap'=>'span','class'=>'help-block')),
2014-02-23 10:59:00 +01:00
'class' => 'form-control '))
);
2014-02-18 12:10:29 +01:00
}
2014-02-19 00:02:17 +01:00
public function refreshCache(){
if($this->isLoggedin()){
$self_company = false;
$this->self_worker_obj = $this->getApplication('DreamjobWorker');
if(!is_array($this->self_worker_obj) or count($this->self_worker_obj)<= 0){
$this->self_company_obj = $this->getApplication('DreamjobCompany');
$self_company = true;
}
}
}
public function getCompany(){
return $this->self_company_obj;
}
public function getWorker(){
return $this->self_worker_obj;
}
2014-02-18 12:10:29 +01:00
public function isLoggedin(){
return $this->Session->check('user');
}
public function isStaff(){
2014-02-19 00:02:17 +01:00
return false;
2014-02-18 12:10:29 +01:00
}
public function login($mail,$password){
$users=$this->User->find('first', array(
'fields' => array('User.id','User.password'),
2014-04-11 17:39:56 +02:00
'conditions' => array('User.mail' => $mail,'User.is_active'=>true)
2014-02-18 12:10:29 +01:00
));
if($this->validate_password($password,$users['User']['password']) and !$this->isLoggedin()){
2014-04-17 00:17:00 +02:00
$this->User->id = $users['User']['id'];
2014-04-29 14:25:25 +02:00
$result = $this->User->saveField('la