2014-02-18 12:10:29 +01:00
|
|
|
<?php
|
|
|
|
App::uses('AppModel', 'Model');
|
2014-05-11 15:17:15 +02:00
|
|
|
App::uses('CakeEmail', 'Network/Email');
|
2014-02-18 12:10:29 +01:00
|
|
|
/**
|
|
|
|
* MicSysMicacc Model
|
|
|
|
*
|
|
|
|
* @property Mannerofaddress $Mannerofaddress
|
|
|
|
*/
|
|
|
|
class User extends AppModel {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use database config
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $useDbConfig = 'dreamjobMain';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use table
|
|
|
|
*
|
|
|
|
* @var mixed False or table name
|
|
|
|
*/
|
|
|
|
public $useTable = 'mic_sys_micacc';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display field
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $displayField = 'id';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validation rules
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2014-04-13 21:11:21 +02:00
|
|
|
public static function sendDeleteMail($data){
|
|
|
|
$Email = new CakeEmail('dreamjobMain');
|
|
|
|
$Email->to($data['User']['mail']);
|
|
|
|
$Email->subject('Welcome to our really cool thing');
|
|
|
|
$Email->template('delete_order');
|
|
|
|
$key = substr($data['User']['code'],2);
|
|
|
|
$Email->viewVars(array('data'=>$data,'key'=>$key));
|
2014-05-11 15:17:15 +02:00
|
|
|
return $Email->send();
|
|
|
|
}
|
|
|
|
public static function sendPasswortResetMail($data){
|
|
|
|
$Email = new CakeEmail('dreamjobMain');
|
|
|
|
$Email->to($data['User']['mail']);
|
|
|
|
$Email->subject('Welcome to our really cool thing');
|
|
|
|
$Email->template('password_reset');
|
|
|
|
$key = substr($data['User']['code'],2);
|
|
|
|
$Email->viewVars(array('data'=>$data,'key'=>$key));
|
2014-04-13 21:11:21 +02:00
|
|
|
return $Email->send();
|
|
|
|
}
|
|
|
|
public function sendDelete($data){
|
|
|
|
$dataSource = $this->getDataSource();
|
|
|
|
$dataSource->begin();
|
|
|
|
$this->id = $data['User']['id'];
|
|
|
|
$result = $this->saveField('code',$data['User']['code']);
|
2014-04-13 21:31:11 +02:00
|
|
|
if($result)
|
|
|
|
$result = $this->saveField('is_active',false);
|
2014-04-13 21:11:21 +02:00
|
|
|
if($result)
|
|
|
|
$result=self::sendDeleteMail($data);
|
|
|
|
|
|
|
|
if($result) {
|
|
|
|
$dataSource->commit();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$dataSource->rollback();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-11 15:17:15 +02:00
|
|
|
public function sendPasswortReset($data){
|
|
|
|
$dataSource = $this->getDataSource();
|
|
|
|
$dataSource->begin();
|
|
|
|
$result = $this->findByMail($data['User']['mail']);
|
|
|
|
if($result)
|
|
|
|
$this->id = $result['User']['id'];
|
|
|
|
if($result)
|
|
|
|
$result = $this->saveField('code',$data['User']['code']);
|
|
|
|
if($result)
|
|
|
|
$result = $this->saveField('is_active',false);
|
|
|
|
if($result)
|
|
|
|
$result=self::sendPasswortResetMail($data);
|
|
|
|
|
|
|
|
if($result) {
|
|
|
|
$dataSource->commit();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$dataSource->rollback();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-11 15:22:27 +02:00
|
|
|
public function replace_password($data,$password){
|
|
|
|
$dataSource = $this->getDataSource();
|
|
|
|
$dataSource->begin();
|
|
|
|
$this->id = $data['User']['id'];
|
|
|
|
if($result)
|
|
|
|
$result = $this->saveField('code','');
|
|
|
|
if($result)
|
|
|
|
$result = $this->saveField('password',$password);
|
|
|
|
|
|
|
|
if($result) {
|
|
|
|
$dataSource->commit();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$dataSource->rollback();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-09 19:30:26 +02:00
|
|
|
public function activeLinkUser($mail,$key){
|
|
|
|
$dataSource = $this->getDataSource();
|
|
|
|
|
|
|
|
$dataSource->begin();
|
|
|
|
$data = $this->find('first',array('conditions' => array(
|
|
|
|
'mail' => $mail,
|
2014-04-13 21:11:21 +02:00
|
|
|
'code'=> array('a:'.$key,'d:'.$key)
|
2014-04-09 19:30:26 +02:00
|
|
|
)));
|
|
|
|
$result = false;
|
|
|
|
if(!empty($data) and count($data)>0){
|
|
|
|
$this->id = $data['User']['id'];
|
|
|
|
$result = $this->saveField('code','');
|
|
|
|
if($result)
|
|
|
|
$result = $this->saveField('is_active',true);
|
|
|
|
}
|
|
|
|
if($result) {
|
|
|
|
$dataSource->commit();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$dataSource->rollback();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-18 12:10:29 +01:00
|
|
|
public $validate = array(
|
|
|
|
'id' => array(
|
|
|
|
'multiple' => array(
|
|
|
|
'rule' => array('multiple'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
'naturalNumber' => array(
|
|
|
|
'rule' => array('naturalNumber'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'first_name' => array(
|
|
|
|
'notEmpty' => array(
|
|
|
|
'rule' => array('notEmpty'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'last_name' => array(
|
|
|
|
'notEmpty' => array(
|
|
|
|
'rule' => array('notEmpty'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'is_staff' => array(
|
|
|
|
'boolean' => array(
|
|
|
|
'rule' => array('boolean'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'is_active' => array(
|
|
|
|
'boolean' => array(
|
|
|
|
'rule' => array('boolean'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'is_superuser' => array(
|
|
|
|
'boolean' => array(
|
|
|
|
'rule' => array('boolean'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'last_login' => array(
|
|
|
|
'datetime' => array(
|
|
|
|
'rule' => array('datetime'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'date_joined' => array(
|
|
|
|
'datetime' => array(
|
|
|
|
'rule' => array('datetime'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'password' => array(
|
|
|
|
'notEmpty' => array(
|
|
|
|
'rule' => array('notEmpty'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'mail' => array(
|
|
|
|
'email' => array(
|
|
|
|
'rule' => array('email'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
2014-05-11 15:17:15 +02:00
|
|
|
/*
|
|
|
|
* Legend: a=aktivierungscode, d=deaktivier zur Löschund, f=password vergessen
|
|
|
|
*/
|
2014-02-18 12:10:29 +01:00
|
|
|
'code' => array(
|
|
|
|
'notEmpty' => array(
|
|
|
|
'rule' => array('notEmpty'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'avatar' => array(
|
|
|
|
'url' => array(
|
|
|
|
'rule' => array('url'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'bday' => array(
|
|
|
|
'date' => array(
|
|
|
|
'rule' => array('date'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'comment' => array(
|
|
|
|
'notEmpty' => array(
|
|
|
|
'rule' => array('notEmpty'),
|
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
|
|
|
|
|
|
|
/**
|
|
|
|
* belongsTo associations
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $belongsTo = array(
|
|
|
|
'Mannerofaddress' => array(
|
|
|
|
'className' => 'Mannerofaddress',
|
|
|
|
'foreignKey' => 'mannerofaddress_id',
|
|
|
|
'conditions' => '',
|
|
|
|
'fields' => '',
|
|
|
|
'order' => ''
|
|
|
|
),
|
|
|
|
);
|
|
|
|
public $hasMany = array(
|
|
|
|
'AppUser' => array(
|
|
|
|
'className' => 'AppUser',
|
|
|
|
'foreignKey' => 'user_id',
|
|
|
|
'dependent' => true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|