ここの情報は古いです。ご理解頂いた上でお取り扱いください。

source: OpenPNE3/trunk/lib/action/sfOpenPNEMemberAction.class.php @ 10348

Last change on this file since 10348 was 10348, checked in by ebihara, 14 years ago

#3287:added ability to delete the member's account himself

File size: 7.9 KB
Line 
1<?php
2
3/**
4 * This file is part of the OpenPNE package.
5 * (c) OpenPNE Project (http://www.openpne.jp/)
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file and the NOTICE file that were distributed with this source code.
9 */
10
11/**
12 * sfOpenPNEMemberAction
13 *
14 * @package    OpenPNE
15 * @subpackage action
16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
17 */
18abstract class sfOpenPNEMemberAction extends sfActions
19{
20  public function preExecute()
21  {
22    $this->id = $this->getRequestParameter('id', $this->getUser()->getMemberId());
23
24    $this->relation = MemberRelationshipPeer::retrieveByFromAndTo($this->getUser()->getMemberId(), $this->id);
25    if (!$this->relation) {
26      $this->relation = new MemberRelationship();
27      $this->relation->setMemberIdFrom($this->getUser()->getMemberId());
28      $this->relation->setMemberIdTo($this->id);
29    }
30  }
31
32 /**
33  * Executes login action
34  *
35  * @param sfRequest $request A request object
36  */
37  public function executeLogin($request)
38  {
39    $this->getUser()->logout();
40
41    $this->forms = $this->getUser()->getAuthForms();
42
43    if ($request->hasParameter('authMode'))
44    {
45      if ($uri = $this->getUser()->login())
46      {
47        $this->redirectIf($this->getUser()->hasCredential('SNSRegisterBegin'), 'member/registerInput');
48        $this->redirectIf($this->getUser()->hasCredential('SNSRegisterFinish'), $this->getUser()->getRegisterEndAction());
49        $this->redirectIf($this->getUser()->hasCredential('SNSMember'), $uri);
50      }
51      return sfView::ERROR;
52    }
53
54    return sfView::SUCCESS;
55  }
56
57 /**
58  * Executes logout action
59  *
60  * @param sfRequest $request A request object
61  */
62  public function executeLogout($request)
63  {
64    $this->getUser()->logout();
65    $this->redirect('member/login');
66  }
67
68 /**
69  * Executes register action
70  *
71  * @param sfRequest $request A request object
72  */
73  public function executeRegisterInput($request)
74  {
75    $mode = (sfConfig::get('app_is_mobile') ? 'mobile' : 'pc');
76    $this->forward404Unless(opToolkit::isEnabledRegistration($mode));
77
78    $this->form = $this->getUser()->getAuthAdapter()->getAuthRegisterForm();
79
80    if ($request->isMethod('post'))
81    {
82      $this->form->bindAll($request);
83      if ($this->form->isValidAll())
84      {
85        $result = $this->getUser()->register($this->form);
86        $this->redirectIf($result, $this->getUser()->getRegisterEndAction());
87      }
88    }
89
90    return sfView::SUCCESS;
91  }
92
93 /**
94  * Executes home action
95  *
96  * @param sfRequest $request A request object
97  */
98  public function executeHome($request)
99  {
100    $this->getUser()->getMember()->updateLastLoginTime();
101    return sfView::SUCCESS;
102  }
103
104 /**
105  * Executes profile action
106  *
107  * @param sfRequest $request A request object
108  */
109  public function executeProfile($request)
110  {
111    $this->redirectIf($this->relation->isAccessBlocked(), '@error');
112
113    $id = $this->getRequestParameter('id', $this->getUser()->getMemberId());
114    $this->member = MemberPeer::retrieveByPk($id);
115    $this->communities = CommunityPeer::retrievesByMemberId($id);
116    $this->forward404Unless($this->member, 'Undefined member.');
117
118    return sfView::SUCCESS;
119  }
120
121 /**
122  * Executes editProfile action
123  *
124  * @param sfRequest $request A request object
125  */
126  public function executeEditProfile($request)
127  {
128    $this->memberForm = new MemberForm($this->getUser()->getMember());
129
130    $profiles = $this->getUser()->getMember()->getProfiles();
131    $this->profileForm = new MemberProfileForm($profiles);
132    $this->profileForm->setConfigWidgets();
133
134    if ($request->isMethod('post'))
135    {
136      $this->memberForm->bind($request->getParameter('member'));
137      $this->profileForm->bind($request->getParameter('profile'));
138      if ($this->memberForm->isValid() && $this->profileForm->isValid())
139      {
140        $this->memberForm->save();
141        $this->profileForm->save($this->getUser()->getMemberId());
142        $this->redirect('member/profile');
143      }
144    }
145
146    return sfView::SUCCESS;
147  }
148
149 /**
150  * Executes config complete action
151  *
152  * @param sfRequest $request A request object
153  */
154  public function executeConfigComplete($request)
155  {
156    $type = $request->getParameter('type');
157    $this->forward404Unless($type);
158
159    $memberId = $request->getParameter('id');
160
161    $memberConfig = MemberConfigPeer::retrieveByNameAndMemberId($type.'_token', $memberId);
162    $this->forward404Unless($memberConfig);
163    $this->forward404Unless((bool)$request->getParameter('token') !== $memberConfig->getValue());
164
165    $option = array('member' => $memberConfig->getMember());
166    $this->form = new sfOpenPNEPasswordForm(array(), $option);
167
168    if ($request->isMethod('post'))
169    {
170      $this->form->bind($request->getParameter('password'));
171      if ($this->form->isValid())
172      {
173        $config = MemberConfigPeer::retrieveByNameAndMemberId($type, $memberId);
174        $pre = MemberConfigPeer::retrieveByNameAndMemberId($type.'_pre', $memberId);
175
176        if (!$config)
177        {
178          $config = new MemberConfig();
179          $config->setName($type);
180          $config->setMemberId($memberId);
181        }
182        $config->setValue($pre->getValue());
183
184        if ($config->save())
185        {
186          $pre->delete();
187          $token = MemberConfigPeer::retrieveByNameAndMemberId($type.'_token', $memberId);
188          $token->delete();
189        }
190
191        $this->redirect('member/home');
192      }
193    }
194
195    return sfView::SUCCESS;
196  }
197
198 /**
199  * Executes config action
200  *
201  * @param sfRequest $request A request object
202  */
203  public function executeConfig($request)
204  {
205    $this->categories = sfConfig::get('openpne_member_category');
206
207    $this->categoryCaptions = array();
208    $categoryAttributes = sfConfig::get('openpne_member_category_attribute');
209    foreach ($this->categories as $key => $value)
210    {
211      $title = $key;
212
213      if (!empty($categoryAttributes[$key]['caption']))
214      {
215        $title = $categoryAttributes[$key]['caption'];
216      }
217
218      $this->categoryCaptions[$key] = $title;
219    }
220
221    $this->categoryName = $request->getParameter('category', null);
222    if ($this->categoryName)
223    {
224      $this->forward404Unless(array_key_exists($this->categoryName, $this->categories), 'Undefined category');
225      $formClass = 'MemberConfig'.ucfirst($this->categoryName).'Form';
226      $this->form = new $formClass($this->getUser()->getMember());
227    }
228
229    if ($request->isMethod('post'))
230    {
231      $this->form->bind($request->getParameter('member_config'));
232      if ($this->form->isValid())
233      {
234        $this->form->save($this->getUser()->getMemberId());
235        $this->redirect('member/config?category='.$this->categoryName);
236      }
237    }
238
239    return sfView::SUCCESS;
240  }
241
242 /**
243  * Executes invite action
244  *
245  * @param sfRequest $request A request object
246  */
247  public function executeInvite($request)
248  {
249    if (
250      !$this->getUser()->getAuthAdapter()->getAuthConfig('invite_mode')
251      || !opToolkit::isEnabledRegistration()
252    )
253    {
254      return sfView::ERROR;
255    }
256
257    $this->form = new InviteForm();
258    $this->form->setOption('is_link', true);
259    if ($request->isMethod('post'))
260    {
261      $this->form->bind($request->getParameter('member_config'));
262      if ($this->form->isValid())
263      {
264        $this->form->save();
265
266        return sfView::SUCCESS;
267      }
268    }
269
270    return sfView::INPUT;
271  }
272
273 /**
274  * Executes delete action
275  *
276  * @param sfRequest $request A request object
277  */
278  public function executeDelete($request)
279  {
280    if (1 == $this->getUser()->getMemberId())
281    {
282      return sfView::ERROR;
283    }
284
285    $this->form = new sfOpenPNEPasswordForm(array(), array('member' => $this->getUser()->getMember()));
286    if ($request->isMethod('post'))
287    {
288      $this->form->bind($request->getParameter('password'));
289      if ($this->form->isValid())
290      {
291        $this->getUser()->getMember()->delete();
292        $this->getUser()->setFlash('notice', '退会が完了しました');
293        $this->getUser()->logout();
294        $this->redirect('member/login');
295      }
296    }
297
298    return sfView::INPUT;
299  }
300}
Note: See TracBrowser for help on using the repository browser.