OSDN Git Service

バージョン記載追加
[trpgtools-onweb/cake-frame.git] / app / controllers / regist_mails_controller.php
1 <?php
2 /**
3  * PHP version 5
4  *
5  * @category Controller
6  * @package  Chara-Shee!
7  * @version  beta
8  * @author   Cake <cake_67@users.sourceforge.jp>
9  * @license  http://www.opensource.org/licenses/mit-license.php The MIT License
10  * @link     http://trpgtools-onweb.sourceforge.jp/
11  */
12 class RegistMailsController extends AppController {
13
14         var $name = 'RegistMails';
15
16         var $components = array(
17                 'Mail',
18                 'Crypt',
19         );
20
21         var $disableTokenActions = array();
22
23         // listView用のpagenate設定
24         var $paginate = array(
25                 'conditions' => array(
26                 ),
27                 'fields' => array(
28                         'RegistMail.id',
29                         'RegistMail.mail',
30                         'RegistMail.user_id',
31 //                      'RegistMail.key_code',
32 //                      'RegistMail.is_mobile',
33                         'RegistMail.modified',
34                         'RegistMail.created',
35                 ),
36                 'recursive' => -1,
37                 'limit' => 20,
38                 'order' => array(
39                         'RegistMail.modified' => 'asc'
40                 ),
41         );
42
43         function beforeFilter() {
44
45                 parent::beforeFilter();
46
47                 // 認証なしアクセス可
48                 $this->AuthPlus->allow('add');
49
50                 if (!empty($this->user_id)) {
51                         $this->disableTokenActions = array(
52                                 'add',
53                                 'edit',
54                         );
55                 }
56
57         }
58
59
60         function index() {
61                         $this->redirect(array('action'=>'add'));
62         }
63
64         function add() {
65                 // メンバー登録にメールアドレス登録必須設定
66                 if ($this->user_id = null && !$this->site_configs['Site.registMail']['value']) {
67                         $this->redirect(array('controller' => 'users', 'action'=>'add'));
68                 }
69
70                 if (!empty($this->data)) {
71                         // バリデーション
72                         $this->RegistMail->set($this->data);
73                         if ($this->RegistMail->validates()) {
74
75                                 // 登録済アドレス
76                                 // ユーザ登録済み
77                                 if (!$user_id = $this->RegistMail->isUniquePcMail($this->data['RegistMail'])) {
78                                         $this->Session->setFlash(__('This Address has been registed.', true));
79                                 } else {
80
81                                         // 仮登録
82                                         if ($id = $this->RegistMail->getRegistId4address($this->data['RegistMail'])) {
83                                                 $this->RegistMail->id = $id;
84                                         } else {
85                                                 $this->RegistMail->create();
86                                         }
87
88                                         $to = $this->data['RegistMail']['mail'];
89                                         $this->data['RegistMail']['mail'] = $this->Crypt->crypt($this->data['RegistMail']['mail']);
90                                         $this->data['RegistMail']['key_code'] = $this->setKeyCode();
91                                         $this->data['RegistMail']['is_mobile'] = false;
92
93                                         // メンバー登録/アドレス登録の処理分け
94                                         if ($this->AuthPlus->user("id")) {
95                                                 $this->data['RegistMail']['user_id'] = $this->AuthPlus->user("id");
96                                                 $subject = sprintf(__('Address Registration for %s', true), $this->site_configs['Site.siteName']['value']);
97                                         } else {
98                                                 $this->data['RegistMail']['user_id'] = null;
99                                                 $subject = sprintf(__('Member Registration for %s', true), $this->site_configs['Site.siteName']['value']);
100                                         }
101
102                                         if ($this->RegistMail->save($this->data, array('validate' => false))) {
103                                                 if ($this->AuthPlus->user("id")) {
104                                                         $this->Mail->send_mail_regist(
105                                                                 $this->data['RegistMail']['key_code'], 
106                                                                 $to, 
107                                                                 $subject
108                                                         );
109                                                 } else {
110                                                         $this->Mail->send_member_regist(
111                                                                 $this->data['RegistMail']['key_code'], 
112                                                                 $to, 
113                                                                 $subject
114                                                         );
115                                                 }
116
117                                                 $this->AuthPlus->logout();
118                                                 $this->redirect(array('controller' => 'users','action'=>'regist_end'));
119                                         } else {
120                                                 $this->data['RegistMail']['mail'] = $to;
121                                                 $this->Session->setFlash(__('The Mail Regist could not be done. Please, try again.', true));
122                                         }
123                                 }
124                         }
125                 }
126
127                 $this->pageTitle .= " - ". __('Regist Mail', true);
128         }
129
130         function admin_index() {
131                 $this->RegistMail->recursive = 0;
132                 $regist_mails = $this->paginate();
133
134                 foreach ($regist_mails as $k => $v) {
135                         // アドレス復号化
136                         if (isset($v['RegistMail']['mail']) && !empty($v['RegistMail']['mail'])) {
137                                 $regist_mails[$k]['RegistMail']['mail'] = $this->Crypt->decrypt($v['RegistMail']['mail']);
138                         }
139                 }
140
141                 $this->set('registMails', $regist_mails);
142
143                 $this->pageTitle .= " - ". __('RegistMails', true);
144         }
145
146         function admin_delete($id = null) {
147                 if (!$id) {
148                         $this->Session->setFlash(__('Invalid id for RegistMail', true));
149                         $this->redirect(array('action'=>'index'));
150                 }
151                 if ($this->RegistMail->del($id)) {
152                         $this->Session->setFlash(__('RegistMail deleted', true));
153                         $this->redirect(array('action'=>'index'));
154                 }
155         }
156
157
158         /* keyCode */
159         // keyCode発行
160         function setKeyCode()
161         {
162                 return Security::generateAuthKey();
163         }
164 }