コード例 #1
0
ファイル: profile.php プロジェクト: uzura8/flockbird
 /**
  * Mmeber_profile edit
  * 
  * @access  public
  * @return  Response
  */
 public function action_edit($type = null)
 {
     list($type, $is_regist) = self::validate_type($type, $this->u->id);
     $form_member_profile = new Form_MemberProfile($type == 'regist' ? 'regist-config' : 'config', $this->u);
     $form_member_profile->set_validation();
     if (\Input::method() == 'POST') {
         \Util_security::check_csrf();
         try {
             $form_member_profile->validate(true);
             \DB::start_transaction();
             $form_member_profile->seve();
             if ($is_regist) {
                 Model_MemberConfig::delete_value($this->u->id, 'terms_un_agreement');
             }
             \DB::commit_transaction();
             $message = $is_regist ? sprintf('%sが%sしました。', term('site.registration'), term('form.complete')) : term('profile') . 'を編集しました。';
             $redirect_uri = $is_regist ? $this->after_auth_uri : 'member/profile';
             \Session::set_flash('message', $message);
             \Response::redirect($redirect_uri);
         } catch (\FuelException $e) {
             if (\DB::in_transaction()) {
                 \DB::rollback_transaction();
             }
             \Session::set_flash('error', $e->getMessage());
         }
     }
     $this->set_title_and_breadcrumbs(term('profile') . term($is_regist ? 'site.registration' : 'form.edit'), $is_regist ? array() : array('member/profile' => term('common.my', 'profile')), $is_regist ? null : $this->u);
     $this->template->content = View::forge('member/profile/edit', array('is_regist' => $is_regist, 'val' => $form_member_profile->get_validation(), 'member_public_flags' => $form_member_profile->get_member_public_flags(), 'profiles' => $form_member_profile->get_profiles(), 'member_profile_public_flags' => $form_member_profile->get_member_profile_public_flags()));
 }
コード例 #2
0
ファイル: register.php プロジェクト: uzura8/flockbird
 /**
  * Execute index
  * 
  * @access  public
  * @return  Response
  */
 public function action_index()
 {
     // Already logged in
     Auth::check() and Response::redirect('member');
     if (!($member_pre = $this->check_token())) {
         Session::set_flash('error', sprintf('URLが%sです。', term('form.disabled')));
         throw new HttpNotFoundException();
     }
     $form_member_profile = new Form_MemberProfile('regist');
     $add_fields = array();
     $add_fields['token'] = Form_Util::get_model_field('member_pre', 'token');
     $add_fields['password'] = Form_Util::get_model_field('member_auth', 'password');
     if (!$member_pre->password) {
         $add_fields['password_confirm'] = Form_Util::get_model_field('member_auth', 'password', term('site.password', 'form._confirm'));
     }
     $form_member_profile->set_validation($add_fields, 'member_register');
     $form_member_profile->set_validation_message('match_value', ':labelが正しくありません。');
     if (Input::method() == 'POST') {
         Util_security::check_csrf();
         $error_message = '';
         $is_transaction_rollback = false;
         try {
             $form_member_profile->validate();
             $post = $form_member_profile->get_validated_values();
             if ($member_pre->password && $post['password'] != $member_pre->password) {
                 throw new ValidationFailedException(term('site.password') . 'が正しくありません。');
             }
             DB::start_transaction();
             // create new member
             $auth = Auth::instance();
             if (!($member_id = $auth->create_user($member_pre->email, $post['password'], $post['member_name']))) {
                 throw new FuelException('create member error.');
             }
             $member = $auth->get_member();
             // 仮登録情報の削除
             if ($member_pre->invite_member_id) {
                 $member->invite_member_id = $member_pre->invite_member_id;
                 $member->save();
                 // TODO: make friend to invited_member
             }
             $email = $member_pre->email;
             $password = $member_pre->password;
             $member_pre->delete();
             // member_profile 登録
             $form_member_profile->set_member_obj($member);
             $form_member_profile->seve();
             // email が重複する member_pre の削除
             if ($member_pres = \Model_MemberPre::query()->where('email', $email)->get()) {
                 foreach ($member_pres as $member_pre) {
                     $member_pre->delete();
                 }
             }
             // timeline 投稿
             if (is_enabled('timeline')) {
                 \Timeline\Site_Model::save_timeline($member_id, null, 'member_register', $member_id, $member->created_at);
             }
             DB::commit_transaction();
             $mail = new Site_Mail('memberRegister');
             $mail->send($member_pre->email, array('to_name' => $member->name));
             if ($auth->login($email, $password)) {
                 Session::set_flash('message', sprintf('%sが%sしました。', term('site.registration'), term('form.complete')));
                 Response::redirect('member');
             }
             Session::set_flash('error', 'ログインに失敗しました');
             Response::redirect(conf('login_uri.site'));
         } catch (ValidationFailedException $e) {
             $error_message = Site_Controller::get_error_message($e);
         } catch (EmailValidationFailedException $e) {
             Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error');
             $error_message = 'メール送信エラー';
         } catch (EmailSendingFailedException $e) {
             Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error');
             $error_message = 'メール送信エラー';
         } catch (\Auth\SimpleUserUpdateException $e) {
             $is_transaction_rollback = true;
             $error_message = 'そのアドレスは登録できません';
         } catch (\Database_Exception $e) {
             $is_transaction_rollback = true;
             $error_message = \Site_Controller::get_error_message($e, true);
         } catch (FuelException $e) {
             $is_transaction_rollback = true;
             $error_message = Site_Controller::get_error_message($e);
         }
         if ($error_message) {
             if ($is_transaction_rollback && DB::in_transaction()) {
                 DB::rollback_transaction();
             }
             Session::set_flash('error', $error_message);
         }
     }
     $this->set_title_and_breadcrumbs(term('member.view', 'site.registration', 'form.confirm'), array('member/signup' => term('site.signup')));
     $this->template->content = View::forge('member/register/index', array('val' => $form_member_profile->get_validation(), 'member_public_flags' => $form_member_profile->get_member_public_flags(), 'profiles' => $form_member_profile->get_profiles(), 'member_profile_public_flags' => $form_member_profile->get_member_profile_public_flags(), 'member_pre' => $member_pre));
 }