dreamjob/app/Controller/Component/MiconwareSessionComponent.php

84 lines
2.6 KiB
PHP
Executable File

<?php
App::uses('Component', 'Controller');
class MiconwareSessionComponent extends Component {
public $components = array('Session');
public $self_worker_obj;
public $self_company_obj;
public function init($controller){
$controller->Security->requireSecure();
$this->User = ClassRegistry::init('User');
$this->refreshCache();
}
public function initWeb($controller){
$controller->set("isLoggedin",$this->isLoggedin());
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);
}
$controller->set("isStaff",$this->isStaff());
$controller->set("MEDIA",'/uploads');
$controller->set("strip_tags",'<b><i><br><ol><ul><li><h1><h2><h3><h4><h5><h6><blockquote><u><img><a><span><div><pre><code>');
$controller->set('default_sForm',array(
'inputDefaults' => array(
'div' => array('class' => 'control-group'),
'label' => array('class' => 'control-label'),
'between' => '<div class="controls">',
'after' => '</div>',
'class' => ''))
);
$controller->set('default_hForm',array(
'inputDefaults' => array(
'div' => true,
'label' => false,
'error' => false,
'class' => 'form-control '),
'class'=>'tableForm'
)
);
$controller->set('default_Form',array(
'inputDefaults' => array(
'div' => array('class' => 'form-group'),
'label' => array('class' => 'col-sm-3 control-label'),
'between' => '<div class="col-sm-9">',
'after' => '</div>',
'error' => array('attribute'=>array('wrap'=>'span','class'=>'help-block')),
'class' => 'form-control '))
);
}
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;
}
public function isLoggedin(){
return $this->Session->check('user');
}
public function isStaff(){
return false;
}
public function login($mail,$password){
$users=$this->User->find('first', array(
'fields' => array('User.id','User.password'),
'conditions' => array('User.mail' => $mail,'User.is_active'=>true)
));
if($this->validate_password($password,$users['User']['password']) and !$this->isLoggedin()){
$this->User->id = $users['User']['id'];
$result = $this->User->saveField('la