DataObjects/Core_person_signup.php
[Pman.Core] / DataObjects / Core_person_signup.php
1 <?php
2 /**
3  * Table Definition for Person
4  */
5 require_once 'DB/DataObject.php';
6
7
8 class Pman_Core_DataObjects_Core_person_signup extends DB_DataObject 
9 {
10     ###START_AUTOCODE
11     /* the code below is auto generated do not remove the above tag */
12
13     public $__table = 'core_person_signup';                          // table name
14     public $id;                              // int(11)  not_null primary_key auto_increment
15     public $email;                           // string(128)  not_null
16     
17     public $name;                            // string(128)  not_null
18     public $firstname;                            // string(128)  not_null
19     public $lastname;                            // string(128)  not_null
20     public $firstname_alt;                            // string(128)  not_null
21     public $lastname_alt;                            // string(128)  not_null
22     
23     
24     public $honor;                            // string(128)  not_null
25     public $verify_key;                      // int(11)
26     public $verified;
27     
28
29     public $created_dt;                      // datetime(19)  binary
30
31     
32     
33     
34     
35     function verify($key)
36     {
37         // if key matches verify_key
38         // copy into person or other entity...
39         // and delete....
40         if($this->get("verify_key",$key)){
41             $p = DB_DataObject::factory('person');
42             $p->setFrom(array(
43                 'honor'=>$this->honor,
44                 'name'=>$this->name,
45                 'email'=>$this->email,
46                 'firstname'=>$this->firstname,
47                 'lastname'=>$this->lastname,
48                 'firstname_alt'=>$this->firstname_alt,
49                 'lastname_alt'=>$this->lastname_alt));
50
51             if($p->insert()){
52                 
53                 $temp_pwd = $p->generatePassword();
54
55                 $this->delete();
56
57                 //login
58                 @session_start();
59         
60                 $_SESSION['Hydra']['authUser'] = $p ? serialize($p) : false;
61
62                 //mail pwd
63                 $c = DB_DataObject::factory('core_email');
64                 if (!$c->get('name', 'CORE_PERSON_SIGNUP_CONGRATULATION')) {
65                     $this->jerr("can not find template");
66                 }
67                 $ret = $c->send(array(
68                    'rcpts' => $this->email,
69                    'honor' => $this->honor.". ".$this->lastname,
70                    'password' => $temp_pwd
71                 ), true);
72          
73                 if (is_object($ret)) {
74                     return false;
75                 }
76                 return true;
77             }else{
78                 return false;
79             }   
80         }
81         return false;
82         
83     }
84
85
86     function convertTo($table){
87         $t = DB_DataObject::factory($table);
88         $ret = $t->get('email',$this->email);
89         if($ret != 0){
90             return false;
91         }else{
92             $t->setFrom(array(
93                 'honor'=>$this->honor,
94                 'name'=>$this->name,
95                 'email'=>$this->email,
96                 'firstname'=>$this->firstname,
97                 'lastname'=>$this->lastname,
98                 'firstname_alt'=>$this->firstname_alt,
99                 'lastname_alt'=>$this->lastname_alt));
100
101             $t->insert();
102             return true;
103         }
104     }
105 }
106
107