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         //$this->whereAdd("verify_key = '".$key."'");
41         $row = $this->get("verify_key",$key);
42         var_dump($row);
43         exit();
44         if(!empty($row)){
45             $p = DB_DataObject::factory('person');
46             $p->honor = $row->honor;
47             $p->name = $row->name;
48             $p->email = $row->email;
49             $p->firstname = $row->firstname;
50             $p->lastname = $row->lastname;
51             $p->firstname_alt = $row->firstname_alt;
52             $p->lastname_alt = $row->lastname_alt;
53             $temp_pwd = $p->generatePassword();
54             //$temp_pwd = mt_rand(100000,999999);
55             //$p->passwd = $temp_pwd;
56             if($p->insert()){
57                 
58                 $this->delete();
59
60                 //login
61                 @session_start();
62         
63                 $_SESSION['Hydra']['authUser'] = $p ? serialize($p) : false;
64
65                 //mail pwd
66                 $htmlStr = "";
67                 $htmlStr .= "Dear ".$p->honor.".".$p->lastname."<br /><br />";
68                 $htmlStr .= "Congratulations on Joining HydRa.<br /><br />";
69                 $htmlStr .= "If you need to access the system again please log in using the password ";
70                 $htmlStr .= $temp_pwd; 
71
72                 $name = "Roojs";
73                 $email_sender = "no-reply@roojs.com";
74                 $subject = "Congratulations";
75                 $recipient_email = $p->email;
76  
77                 $headers  = "MIME-Version: 1.0\r\n";
78                 $headers .= "Content-type: text/html; charset=utf-8\r\n";
79                 $headers .= "From: {$name} ";
80                 $headers .= "<";
81                 $headers .= $email_sender;
82                 $headers .= ">\r\n";
83
84                 $body = $htmlStr;
85                 if(mail($recipient_email, $subject, $body, $headers)){
86                     error_log("Sending failed.");
87                 }
88             }else{
89                 error_log("db insert error");
90                 return false;
91             }   
92         }
93         return false;
94         
95     }
96 }
97
98