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

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

Last change on this file since 10907 was 10907, checked in by ShogoKawahara, 13 years ago

#3278:added ability to render admin icon for community administrator on profile

File size: 8.5 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   
116    $this->forward404Unless($this->member, 'Undefined member.');
117
118    $this->communities = CommunityPeer::retrievesByMemberId($id);
119    $this->crownIds = CommunityMemberPeer::getCommunityIdsOfAdminByMemberId($id);
120
121    return sfView::SUCCESS;
122  }
123
124 /**
125  * Executes editProfile action
126  *
127  * @param sfRequest $request A request object
128  */
129  public function executeEditProfile($request)
130  {
131    $this->memberForm = new MemberForm($this->getUser()->getMember());
132
133    $profiles = $this->getUser()->getMember()->getProfiles();
134    $this->profileForm = new MemberProfileForm($profiles);
135    $this->profileForm->setConfigWidgets();
136
137    if ($request->isMethod('post'))
138    {
139      $this->memberForm->bind($request->getParameter('member'));
140      $this->profileForm->bind($request->getParameter('profile'));
141      if ($this->memberForm->isValid() && $this->profileForm->isValid())
142      {
143        $this->memberForm->save();
144        $this->profileForm->save($this->getUser()->getMemberId());
145        $this->redirect('member/profile');
146      }
147    }
148
149    return sfView::SUCCESS;
150  }
151
152 /**
153  * Executes config complete action
154  *
155  * @param sfRequest $request A request object
156  */
157  public function executeConfigComplete($request)
158  {
159    $type = $request->getParameter('type');
160    $this->forward404Unless($type);
161
162    $memberId = $request->getParameter('id');
163
164    $memberConfig = MemberConfigPeer::retrieveByNameAndMemberId($type.'_token', $memberId);
165    $this->forward404Unless($memberConfig);
166    $this->forward404Unless((bool)$request->getParameter('token') !== $memberConfig->getValue());
167
168    $option = array('member' => $memberConfig->getMember());
169    $this->form = new sfOpenPNEPasswordForm(array(), $option);
170
171    if ($request->isMethod('post'))
172    {
173      $this->form->bind($request->getParameter('password'));
174      if ($this->form->isValid())
175      {
176        $config = MemberConfigPeer::retrieveByNameAndMemberId($type, $memberId);
177        $pre = MemberConfigPeer::retrieveByNameAndMemberId($type.'_pre', $memberId);
178
179        if (!$config)
180        {
181          $config = new MemberConfig();
182          $config->setName($type);
183          $config->setMemberId($memberId);
184        }
185        $config->setValue($pre->getValue());
186
187        if ($config->save())
188        {
189          $pre->delete();
190          $token = MemberConfigPeer::retrieveByNameAndMemberId($type.'_token', $memberId);
191          $token->delete();
192        }
193
194        $this->redirect('member/home');
195      }
196    }
197
198    return sfView::SUCCESS;
199  }
200
201 /**
202  * Executes config action
203  *
204  * @param sfRequest $request A request object
205  */
206  public function executeConfig($request)
207  {
208    $this->categories = sfConfig::get('openpne_member_category');
209
210    $this->categoryCaptions = array();
211    $categoryAttributes = sfConfig::get('openpne_member_category_attribute');
212    foreach ($this->categories as $key => $value)
213    {
214      $title = $key;
215
216      if (!empty($categoryAttributes[$key]['caption']))
217      {
218        $title = $categoryAttributes[$key]['caption'];
219      }
220
221      $this->categoryCaptions[$key] = $title;
222    }
223
224    $this->categoryName = $request->getParameter('category', null);
225    if ($this->categoryName)
226    {
227      $this->forward404Unless(array_key_exists($this->categoryName, $this->categories), 'Undefined category');
228      $formClass = 'MemberConfig'.ucfirst($this->categoryName).'Form';
229      $this->form = new $formClass($this->getUser()->getMember());
230    }
231
232    if ($request->isMethod('post'))
233    {
234      $this->form->bind($request->getParameter('member_config'));
235      if ($this->form->isValid())
236      {
237        $this->form->save($this->getUser()->getMemberId());
238        $this->redirect('member/config?category='.$this->categoryName);
239      }
240    }
241
242    return sfView::SUCCESS;
243  }
244
245 /**
246  * Executes invite action
247  *
248  * @param sfRequest $request A request object
249  */
250  public function executeInvite($request)
251  {
252    if (
253      !$this->getUser()->getAuthAdapter()->getAuthConfig('invite_mode')
254      || !opToolkit::isEnabledRegistration()
255    )
256    {
257      return sfView::ERROR;
258    }
259
260    $this->form = new InviteForm(null, array('invited' => true));
261    $this->form->setOption('is_link', true);
262    if ($request->isMethod('post'))
263    {
264      $this->form->bind($request->getParameter('member_config'));
265      if ($this->form->isValid())
266      {
267        $this->form->save();
268
269        return sfView::SUCCESS;
270      }
271    }
272
273    $id = $this->getUser()->getMemberId();
274    $this->invites = $this->getUser()->getMember()->getInvitingMembers();
275
276    $this->listform = new InvitelistForm(
277      array(),
278      array('invites' => $this->invites)
279    );
280    if ($request->isMethod('post'))
281    {
282      $this->listform->bind($request->getParameter('invitelist'));
283      if ($this->listform->isValid())
284      {
285        $this->listform->save();
286        $this->redirect('member/invite');
287      }
288    }
289 
290    return sfView::INPUT;
291  }
292
293 /**
294  * Executes delete action
295  *
296  * @param sfRequest $request A request object
297  */
298  public function executeDelete($request)
299  {
300    if (1 == $this->getUser()->getMemberId())
301    {
302      return sfView::ERROR;
303    }
304
305    $this->form = new sfOpenPNEPasswordForm(array(), array('member' => $this->getUser()->getMember()));
306    if ($request->isMethod('post'))
307    {
308      $this->form->bind($request->getParameter('password'));
309      if ($this->form->isValid())
310      {
311        $this->getUser()->getMember()->delete();
312        $this->getUser()->setFlash('notice', '退会が完了しました');
313        $this->getUser()->logout();
314        $this->redirect('member/login');
315      }
316    }
317
318    return sfView::INPUT;
319  }
320}
Note: See TracBrowser for help on using the repository browser.