dreamjob/app/Model/User.php

242 lines
6.6 KiB
PHP
Raw Permalink Normal View History

2015-03-31 14:49:03 +02:00
<?php
App::uses('AppModel', 'Model');
App::uses('CakeEmail', 'Network/Email');
/**
* 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
*/
public static function sendDeleteMail($data){
$Email = new CakeEmail('dreamjobMain');
$Email->to($data['User']['mail']);
$Email->subject('Profillöschung');
$Email->template('delete_order');
$key = substr($data['User']['code'],2);
$Email->viewVars(array('data'=>$data,'key'=>$key));
$Email->attachments(array('dak.jpg' => WWW_ROOT.DS.'mail'.DS.'dak.jpg'));
return $Email->send();
}
public static function sendPasswortResetMail($data){
$Email = new CakeEmail('dreamjobMain');
$Email->to($data['User']['mail']);
$Email->subject('Passwort zurücksetzen');
$Email->template('password_reset');
$key = substr($data['User']['code'],2);
$Email->viewVars(array('data'=>$data,'key'=>$key));
$Email->attachments(array('dak.jpg' => WWW_ROOT.DS.'mail'.DS.'dak.jpg'));
return $Email->send();
}
public function sendDelete($data){
$dataSource = $this->getDataSource();
$dataSource->begin();
$this->id = $data['User']['id'];
$result = $this->saveField('code',$data['User']['code']);
if($result)
$result = $this->saveField('is_active',false);
if($result)
$result=self::sendDeleteMail($data);
if($result) {
$dataSource->commit();
return true;
} else {
$dataSource->rollback();
}
return false;
}
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=self::sendPasswortResetMail($data);
if($result) {
$dataSource->commit();
return true;
} else {
$dataSource->rollback();
}
return false;
}
public function replace_password($data,$password){
$dataSource = $this->getDataSource();
$dataSource->begin();
$this->id = $data['User']['id'];
$result = $this->saveField('password',$password);
if($result)
$result = $this->saveField('code','');
if($result) {
$dataSource->commit();
return true;
} else {
$dataSource->rollback();
}
return false;
}
public function activeLinkUser($mail,$key){
$dataSource = $this->getDataSource();
$dataSource->begin();
$data = $this->find('first',array('conditions' => array(
'mail' => $mail,
'code'=> array('a:'.$key,'d:'.$key)
)));
$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;
}
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
),
),
'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
),
),
/*
* Legend: a=aktivierungscode, d=deaktivier zur Löschund, f=password vergessen
*/
'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
),
),
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $hasMany = array(
'AppUser' => array(
'className' => 'AppUser',
'foreignKey' => 'user_id',
'dependent' => true
)
);
}