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

source: OpenPNE3/branches/goto_doctrine/lib/action/sfOpenPNEMemberAction.class.php @ 11219

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

#3765:imported new models for Doctrine from some old models for Propel to enable to login

File size: 10.6 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 = Doctrine::getTable('MemberRelationship')->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 = Doctrine::getTable('Member')->find($id);
115   
116    $this->forward404Unless($this->member, 'Undefined member.');
117
118    $c = new Criteria();
119    $c->addAscendingOrderByColumn(Propel::getDB()->random(time()));
120
121    if (!$this->friendsSize)
122    {
123      $this->friendsSize = 9;
124    }
125    $this->friends = $this->member->getFriends($this->friendsSize, $c);
126
127    if (!$this->communitiesSize)
128    {
129      $this->communitiesSize = 9;
130    }
131    $this->communities = $this->member->getJoinCommunities($this->communitiesSize, $c);
132    $this->crownIds = Doctrine::getTable('CommunityMember')->getCommunityIdsOfAdminByMemberId($id);
133
134    return sfView::SUCCESS;
135  }
136
137 /**
138  * Executes editProfile action
139  *
140  * @param sfRequest $request A request object
141  */
142  public function executeEditProfile($request)
143  {
144    $this->memberForm = new MemberForm($this->getUser()->getMember());
145
146    $profiles = $this->getUser()->getMember()->getProfiles();
147    $this->profileForm = new MemberProfileForm($profiles);
148    $this->profileForm->setConfigWidgets();
149
150    if ($request->isMethod('post'))
151    {
152      $this->memberForm->bind($request->getParameter('member'));
153      $this->profileForm->bind($request->getParameter('profile'));
154      if ($this->memberForm->isValid() && $this->profileForm->isValid())
155      {
156        $this->memberForm->save();
157        $this->profileForm->save($this->getUser()->getMemberId());
158        $this->redirect('member/profile');
159      }
160    }
161
162    return sfView::SUCCESS;
163  }
164
165 /**
166  * Executes config complete action
167  *
168  * @param sfRequest $request A request object
169  */
170  public function executeConfigComplete($request)
171  {
172    $type = $request->getParameter('type');
173    $this->forward404Unless($type);
174
175    $memberId = $request->getParameter('id');
176
177    $memberConfig = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId($type.'_token', $memberId);
178    $this->forward404Unless($memberConfig);
179    $this->forward404Unless((bool)$request->getParameter('token') !== $memberConfig->getValue());
180
181    $option = array('member' => $memberConfig->getMember());
182    $this->form = new sfOpenPNEPasswordForm(array(), $option);
183
184    if ($request->isMethod('post'))
185    {
186      $this->form->bind($request->getParameter('password'));
187      if ($this->form->isValid())
188      {
189        $config = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId($type, $memberId);
190        $pre = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId($type.'_pre', $memberId);
191
192        if (!$config)
193        {
194          $config = new MemberConfig();
195          $config->setName($type);
196          $config->setMemberId($memberId);
197        }
198        $config->setValue($pre->getValue());
199
200        if ($config->save())
201        {
202          $pre->delete();
203          $token = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId($type.'_token', $memberId);
204          $token->delete();
205        }
206
207        $this->redirect('member/home');
208      }
209    }
210
211    return sfView::SUCCESS;
212  }
213
214 /**
215  * Executes config action
216  *
217  * @param sfRequest $request A request object
218  */
219  public function executeConfig($request)
220  {
221    $this->categories = sfConfig::get('openpne_member_category');
222
223    $this->categoryCaptions = array();
224    $categoryAttributes = sfConfig::get('openpne_member_category_attribute');
225
226    foreach ($this->categories as $key => $value)
227    {
228      $title = $key;
229
230      $enabledKey = 'enable_pc';
231      if (sfConfig::get('sf_app') == 'mobile_frontend')
232      {
233        $enabledKey = 'enable_mobile';
234      }
235
236      if (isset($categoryAttributes[$key][$enabledKey]))
237      {
238        if (!$categoryAttributes[$key][$enabledKey])
239        {
240          unset($this->categories[$key]);
241          continue;
242        }
243      }
244
245      if (!empty($categoryAttributes[$key]['caption']))
246      {
247        $title = $categoryAttributes[$key]['caption'];
248      }
249
250      $this->categoryCaptions[$key] = $title;
251    }
252
253    $this->categoryName = $request->getParameter('category', null);
254    if ($this->categoryName)
255    {
256      $this->forward404Unless(array_key_exists($this->categoryName, $this->categories), 'Undefined category');
257      $formClass = 'MemberConfig'.ucfirst($this->categoryName).'Form';
258      $this->form = new $formClass($this->getUser()->getMember());
259    }
260
261    if ($request->isMethod('post'))
262    {
263      $this->form->bind($request->getParameter('member_config'));
264      if ($this->form->isValid())
265      {
266        $this->form->save($this->getUser()->getMemberId());
267        $this->redirect('member/config?category='.$this->categoryName);
268      }
269    }
270
271    return sfView::SUCCESS;
272  }
273
274 /**
275  * Executes invite action
276  *
277  * @param sfRequest $request A request object
278  */
279  public function executeInvite($request)
280  {
281    if (
282      !$this->getUser()->getAuthAdapter()->getAuthConfig('invite_mode')
283      || !opToolkit::isEnabledRegistration()
284    )
285    {
286      return sfView::ERROR;
287    }
288
289    $this->form = new InviteForm(null, array('invited' => true));
290    $this->form->setOption('is_link', true);
291    if ($request->isMethod('post'))
292    {
293      $this->form->bind($request->getParameter('member_config'));
294      if ($this->form->isValid())
295      {
296        $this->form->save();
297
298        return sfView::SUCCESS;
299      }
300    }
301
302    $id = $this->getUser()->getMemberId();
303    $this->invites = $this->getUser()->getMember()->getInvitingMembers();
304
305    $this->listform = new InvitelistForm(
306      array(),
307      array('invites' => $this->invites)
308    );
309    if ($request->isMethod('post'))
310    {
311      $this->listform->bind($request->getParameter('invitelist'));
312      if ($this->listform->isValid())
313      {
314        $this->listform->save();
315        $this->redirect('member/invite');
316      }
317    }
318 
319    return sfView::INPUT;
320  }
321
322 /**
323  * Executes delete action
324  *
325  * @param sfRequest $request A request object
326  */
327  public function executeDelete($request)
328  {
329    if (1 == $this->getUser()->getMemberId())
330    {
331      return sfView::ERROR;
332    }
333
334    $this->form = new sfOpenPNEPasswordForm(array(), array('member' => $this->getUser()->getMember()));
335    if ($request->isMethod('post'))
336    {
337      $this->form->bind($request->getParameter('password'));
338      if ($this->form->isValid())
339      {
340        $member = $this->getUser()->getMember();
341        $this->getUser()->getMember()->delete();
342        $this->sendDeleteAccountMail($member);
343        $this->getUser()->setFlash('notice', '退会が完了しました');
344        $this->getUser()->logout();
345        $this->redirect('member/login');
346      }
347    }
348
349    return sfView::INPUT;
350  }
351
352  public function executeConfigImage($request)
353  {
354    return sfView::SUCCESS;
355  }
356
357  public function executeDeleteImage($request)
358  {
359    $image = MemberImagePeer::retrieveByPk($request->getParameter('member_image_id'));
360    $this->forward404Unless($image);
361    $this->forward404Unless($image->getMemberId() == $this->getUser()->getMemberId());
362
363    $image->delete();
364
365    $this->redirect('member/configImage');
366  }
367
368  public function executeChangeMainImage($request)
369  {
370    $image = MemberImagePeer::retrieveByPk($request->getParameter('member_image_id'));
371    $this->forward404Unless($image);
372    $this->forward404Unless($image->getMemberId() == $this->getUser()->getMemberId());
373
374    $currentImage = $this->getUser()->getMember()->getImage();
375    $currentImage->setIsPrimary(false);
376    $currentImage->save();
377    $image->setIsPrimary(true);
378    $image->save();
379
380    $this->redirect('member/configImage');
381  }
382
383
384  protected function sendDeleteAccountMail($member)
385  {
386    $param = array(
387      'member'   => $member,
388    );
389    $mail = new sfOpenPNEMailSend();
390    $mail->setSubject(opConfig::get('sns_name') . '退会者情報');
391    $mail->setTemplate('global/deleteAccountMail', $param);
392    $mail->send(opConfig::get('admin_mail_address'), opConfig::get('admin_mail_address'));
393  }
394}
Note: See TracBrowser for help on using the repository browser.