Beispiel #1
0
 /**
  * Validate if there is no controll char
  *
  * @param   string
  * @return  true|Exception
  */
 public static function _validation_no_controll($val, $is_accept_line_and_tab = false, $is_throw_input_error = false)
 {
     $accept_char = '[:^cntrl:]';
     if ($is_accept_line_and_tab) {
         $accept_char .= '\\r\\n\\t';
     }
     if (preg_match('/\\A[' . $accept_char . ']*\\z/u', $val) === 1) {
         return true;
     } elseif ($is_throw_input_error) {
         Util_Toolkit::log_error('Invalid control characters: ' . urlencode($value));
         throw new HttpInvalidInputException('Invalid input data');
     }
     return false;
 }
Beispiel #2
0
 public function action_change_password()
 {
     Util_security::check_method('POST');
     Util_security::check_csrf();
     $form = $this->form_setting_password();
     $val = $form->validation();
     if (!$val->run()) {
         Session::set_flash('error', $val->show_errors());
         $this->action_password();
         return;
     }
     $post = $val->validated();
     $error_message = '';
     $is_transaction_rollback = false;
     try {
         DB::start_transaction();
         $this->change_password($post['old_password'], $post['password']);
         DB::commit_transaction();
         $mail = new Site_Mail('memberSettingPassword');
         $mail->send($this->u->member_auth->email, array('to_name' => $this->u->name));
         Session::set_flash('message', term('site.password') . 'を変更しました。');
         Response::redirect('member/setting');
     } 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 (WrongPasswordException $e) {
         $is_transaction_rollback = true;
         $error_message = sprintf('現在の%sが正しくありません。', term('site.password'));
     } catch (\Auth\SimpleUserUpdateException $e) {
         $is_transaction_rollback = true;
         $error_message = term('site.password') . 'の変更に失敗しました。';
     } 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 = $e->getMessage();
     }
     if ($error_message) {
         if ($is_transaction_rollback && DB::in_transaction()) {
             DB::rollback_transaction();
         }
         Session::set_flash('error', $error_message);
     }
     $this->action_password();
 }
Beispiel #3
0
 public function action_delete()
 {
     Util_security::check_method('POST');
     Util_security::check_csrf();
     $form = $this->form_leave();
     $val = $form->validation();
     if (!$val->run()) {
         Session::set_flash('error', $val->show_errors());
         $this->action_index();
         return;
     }
     if (!$this->u->check_registered_oauth(true) && !$this->auth_instance->check_password()) {
         Session::set_flash('error', term('site.password') . 'が正しくありません');
         $this->action_index();
         return;
     }
     $error_message = '';
     $is_transaction_rollback = false;
     try {
         $message = Site_Member::remove($this->u);
         $this->auth_instance->logout();
         Session::set_flash('message', $message);
         Response::redirect(conf('login_uri.site'));
     } 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 (SimpleUserUpdateException $e) {
         $is_transaction_rollback = true;
         $error_message = term('member.view') . 'が存在しません。';
     } catch (Database_Exception $e) {
         $is_transaction_rollback = true;
         $error_message = Site_Controller::get_error_message($e, true);
     } catch (FuelException $e) {
         $is_transaction_rollback = true;
         if (!($error_message = $e->getMessage())) {
             $error_message = term('site.left') . 'に失敗しました。';
         }
     }
     if ($error_message) {
         if ($is_transaction_rollback && DB::in_transaction()) {
             DB::rollback_transaction();
         }
         Session::set_flash('error', $error_message);
     }
     $this->action_index();
 }
Beispiel #4
0
 /**
  * Mmeber leave
  * 
  * @access  public
  * @return  Response
  */
 public function action_index()
 {
     $val = self::get_validation_object();
     if (\Input::method() == 'POST') {
         \Util_security::check_csrf();
         $success_message = sprintf('%sを%sしました。', term('form.invite', 'site.mail'), term('form.post'));
         $error_message = '';
         $is_transaction_rollback = false;
         try {
             if (!$val->run()) {
                 throw new ValidationFailedException($val->show_errors());
             }
             $post = $val->validated();
             if (Model_MemberPre::get_one4invite_member_id_and_email($this->u->id, $post['email'])) {
                 throw new ValidationFailedException(sprintf('その%sは既に%sです。', term('site.email'), term('form.invited')));
             }
             DB::start_transaction();
             $token = Model_MemberPre::save_with_token($post['email'], null, $this->u->id);
             DB::commit_transaction();
             $mail = new Site_Mail('memberInvite');
             $mail->send($post['email'], array('register_url' => sprintf('%s?token=%s', Uri::create('member/register'), $token), 'invite_member_name' => $this->u->name, 'invite_message' => $post['message']));
             Session::set_flash('message', $success_message);
             Response::redirect('member/invite');
         } 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 (\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 ($is_transaction_rollback && DB::in_transaction()) {
             DB::rollback_transaction();
         }
         if ($error_message) {
             Session::set_flash('error', $error_message);
         }
     }
     $this->set_title_and_breadcrumbs(term('form.invite_friend'), null, $this->u);
     $this->template->content = \View::forge('member/invite', array('val' => $val, 'member_pres' => Model_MemberPre::get4invite_member_id($this->u->id)));
 }
Beispiel #5
0
 public static function check_method($accept_methods, $is_output_log = true)
 {
     if (!$accept_methods) {
         return true;
     }
     if (!is_array($accept_methods)) {
         $accept_methods = (array) $accept_methods;
     }
     $accept_methods = array_map('strtoupper', $accept_methods);
     if (!in_array(Input::method(), $accept_methods)) {
         if ($is_output_log) {
             Util_Toolkit::log_error('METHOD');
         }
         throw new HttpMethodNotAllowed('Method not allowed');
     }
 }
Beispiel #6
0
 public static function check_control($value)
 {
     // 配列の場合は再帰的に処理
     if (is_array($value)) {
         array_map(array('MyInputFilters', 'check_control'), $value);
         return $value;
     }
     // 改行コードとタブを除く制御文字が含まれないか
     if (preg_match('/\\A[\\r\\n\\t[:^cntrl:]]*\\z/u', $value) === 1) {
         return $value;
     } else {
         // 含まれている場合はログに記録
         Util_Toolkit::log_error('Invalid control characters: ' . urlencode($value));
         // エラーを表示して終了
         throw new HttpInvalidInputException('Invalid input data');
     }
 }
Beispiel #7
0
 /**
  * News delete
  * 
  * @access  public
  * @params  integer
  * @return  Response
  */
 public function action_delete($id = null)
 {
     $id = (int) $id;
     \Util_security::check_method('POST');
     \Util_security::check_csrf();
     $error_message = '';
     $is_transaction_rollback = false;
     try {
         $member = \Model_Member::check_authority($id);
         $message = \Site_Member::remove($member);
         \Session::set_flash('message', $message);
     } 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 = term('member.view') . 'が存在しません。';
     } catch (\Database_Exception $e) {
         $is_transaction_rollback = true;
         $error_message = \Site_Controller::get_error_message($e, true);
     } catch (\FuelException $e) {
         $is_transaction_rollback = true;
         if (!($error_message = $e->getMessage())) {
             $error_message = term('site.left') . 'に失敗しました。';
         }
     }
     if ($error_message) {
         if ($is_transaction_rollback && \DB::in_transaction()) {
             \DB::rollback_transaction();
         }
         \Session::set_flash('error', $error_message);
     }
     \Response::redirect(\Site_Util::get_redirect_uri('admin/member'));
 }
Beispiel #8
0
 /**
  * Sent account lock notificaton mail.
  *
  * @return  bool
  */
 private function sent_noticication_mail($email)
 {
     if ($notification_mail_info = \Config::get('uzuraauth.accountLock.isSentNotificationMail', array())) {
         return false;
     }
     if (empty($notification_mail_info['member']) && empty($notification_mail_info['admin'])) {
         return false;
     }
     $send_mails = array();
     $member = null;
     if ($admin_mails = \Config::get('uzuraauth.accountLock.isSentNotificationEmail.admin')) {
         $send_mails = $admin_mails;
     }
     if (\Config::get('uzuraauth.accountLock.isSentNotificationEmail.member') && ($member_id = static::get_member_id4email($email))) {
         $member = static::get_member4id($id);
         $send_mails[] = $email;
     }
     $maildata = array('from_name' => \Config::get('mail.member_setting_common.from_name'), 'from_address' => \Config::get('mail.member_setting_common.from_mail_address'));
     $maildata['member_id'] = $member ? $member->id : '';
     $maildata['member_name'] = $member ? $member->name : '';
     foreach ($send_mails as $send_mail) {
         $maildata['to_address'] = $send_mail;
         $maildata['is_admin'] = in_array($send_mail, $admin_mails);
         if (!$maildata['is_admin'] && $member) {
             $maildata['to_name'] = $member->name;
         }
         try {
             $this->send_account_lock_mail($maildata);
         } catch (EmailValidationFailedException $e) {
             \Util_Toolkit::log_error('account_lock_mail_error: email validation error');
         } catch (EmailSendingFailedException $e) {
             \Util_Toolkit::log_error('account_lock_mail_error: email sending error');
         } catch (FuelException $e) {
             \Util_Toolkit::log_error('account_lock_mail_error');
         }
     }
 }
Beispiel #9
0
 /**
  * Execute confirm signup
  * 
  * @access  public
  * @return  Response
  */
 public function action_confirm_signup()
 {
     Util_security::check_method('POST');
     Util_security::check_csrf();
     if (!($form = Fieldset::instance('confirm_signup'))) {
         $form = $this->get_form_signup_confirm();
     }
     $val = $form->validation();
     $val->fieldset()->field('email')->delete_rule('unique');
     $redirect_uri = conf('login_uri.site');
     $success_message = '仮登録が完了しました。受信したメール内に記載された URL より本登録を完了してください。';
     $error_message = '';
     $is_transaction_rollback = false;
     try {
         if (!$val->run()) {
             throw new \FuelException($val->show_errors());
         }
         $post = $val->validated();
         if (Model_MemberAuth::get4email($post['email'])) {
             if (conf('member.register.email.hideUniqueCheck')) {
                 Session::set_flash('message', $success_message);
                 Response::redirect($redirect_uri);
             }
             throw new FuelException('その' . term('site.email') . 'は登録できません。');
         }
         DB::start_transaction();
         $token = Model_MemberPre::save_with_token($post['email'], $post['password']);
         DB::commit_transaction();
         $mail = new Site_Mail('memberSignup');
         $mail->send($post['email'], array('register_url' => sprintf('%s?token=%s', Uri::create('member/register'), $token)));
         Session::set_flash('message', $success_message);
         Response::redirect($redirect_uri);
     } 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 (\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 = $e->getMessage();
     }
     if ($is_transaction_rollback && DB::in_transaction()) {
         DB::rollback_transaction();
     }
     Session::set_flash('error', $error_message);
     $this->action_signup();
 }
Beispiel #10
0
 protected function controller_common_api(callable $func)
 {
     try {
         $this->check_response_format($this->api_accept_formats);
         if (Input::method() != 'GET' && !$this->api_not_check_csrf) {
             Util_security::check_csrf();
         }
         $this->response_body = $func() ?: $this->response_body;
         // execute main.
         if (Site_Model::check_is_orm_obj($this->response_body)) {
             throw new \FuelException('Response body not allowed Orm obj.');
         }
         $status_code = 200;
     } catch (\HttpNotFoundException $e) {
         $status_code = 404;
     } catch (\ApiNotAuthorizedException $e) {
         $status_code = 401;
     } catch (\HttpForbiddenException $e) {
         $status_code = 403;
     } catch (\HttpMethodNotAllowed $e) {
         $status_code = 405;
     } catch (\HttpBadRequestException $e) {
         $status_code = 400;
     } catch (\HttpInvalidInputException $e) {
         $status_code = 400;
     } catch (\ValidationFailedException $e) {
         $this->response_body['errors']['message'] = Site_Controller::get_error_message($e);
         $status_code = 400;
     } catch (\DisableToUpdateException $e) {
         $this->response_body['errors']['message'] = $e->getMessage() ?: term('form.update') . 'が禁止されています。';
         $status_code = 400;
     } catch (\Database_Exception $e) {
         $this->response_body['errors']['message'] = Site_Controller::get_error_message($e, true);
         $status_code = 500;
     } catch (\FuelException $e) {
         $status_code = 500;
     } catch (\Exception $e) {
         $status_code = 500;
     }
     if ($status_code == 500) {
         if (!empty($e)) {
             Util_Toolkit::log_error($e->getMessage());
         }
         if (\DB::in_transaction()) {
             \DB::rollback_transaction();
         }
     }
     $response_body = Site_Controller::supply_response_body($this->response_body, $status_code, $this->format);
     return self::response($response_body, $status_code);
 }
Beispiel #11
0
 /**
  * Execute reset password.
  * 
  * @access  public
  * @return  Response
  */
 public function action_reset_password()
 {
     // Already logged in
     Auth::check() and Response::redirect('member');
     $member_password_pre = Model_MemberPasswordPre::get4token(Input::param('token'));
     if (!$member_password_pre || !Site_Util::check_token_lifetime($member_password_pre->updated_at, conf('member.recover.password.token_lifetime'))) {
         Session::set_flash('error', sprintf('URLが%sです。', term('form.disabled')));
         throw new HttpNotFoundException();
     }
     $form = $this->form_reset_password();
     $val = $form->validation();
     if (Input::method() == 'POST') {
         Util_security::check_csrf();
         $auth = Auth::instance();
         $error_message = '';
         $is_transaction_rollback = false;
         try {
             if (!$val->run()) {
                 throw new FuelException($val->show_errors() ?: term('site.password') . 'が正しくありません');
             }
             $post = $val->validated();
             $to_email = $member_password_pre->email;
             $to_name = $member_password_pre->member->name;
             DB::start_transaction();
             $auth->change_password_simple($member_password_pre->member_id, $post['password']);
             $member_password_pre->delete();
             // 仮登録情報の削除
             DB::commit_transaction();
             $mail = new Site_Mail('memberResetPassword');
             $mail->send($to_email, array('to_name' => $to_name));
             $auth->login($to_email, $post['password']);
             Session::set_flash('message', term('site.password') . 'を登録しました。');
             Response::redirect('member');
         } 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 = term('site.password') . 'の登録に失敗しました。';
         } 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 = $e->getMessage();
         }
         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('site.password') . 'の再登録');
     $data = array('val' => $val, 'member_password_pre' => $member_password_pre);
     $this->template->content = View::forge('member/recover/reset_password', $data);
     $this->template->content->set_safe('html_form', $form->build('member/recover/reset_password'));
     // form の action に入る
 }
Beispiel #12
0
 protected function handle_file_upload($uploaded_file, $original_name, $size, $type, $error, $index = null, $content_range = null)
 {
     $file = new \stdClass();
     $file->is_tmp = $this->options['is_tmp'];
     $file->original_name = $original_name;
     $file->size = $this->fix_integer_overflow(intval($size));
     $file->type = $type;
     if (!($extention = Util_file::check_file_type($uploaded_file, \Site_Upload::get_accept_format($this->options['upload_type']), $type, $this->options['upload_type']))) {
         $file->error = $this->get_error_message('accept_file_types');
         return $file;
     }
     if (!($filename_with_prefix = Site_Upload::make_unique_filename($extention, $this->options['filename_prefix'], $original_name))) {
         $file->error = 'ファイル名の作成に失敗しました。';
         return $file;
     }
     $file->name = $this->remove_filename_prefix($filename_with_prefix);
     $file->name_prefix = $this->options['filename_prefix'];
     if (!\Site_Upload::check_and_make_uploaded_dir($this->options['upload_dir'], null, $this->options['mkdir_mode'])) {
         $file->error = 'ディレクトリの作成に失敗しました。';
         return $file;
     }
     if (!$this->validate($uploaded_file, $file, $error, $index)) {
         return $file;
     }
     if ($this->options['upload_type'] == 'img') {
         $file->thumbnail_uri = $this->options['image_versions']['thumbnail']['upload_url'] . $file->name;
     }
     $this->handle_form_data($file, $index);
     $upload_dir = $this->get_upload_path();
     $file_path = $this->get_upload_path($file->name);
     $append_file = $content_range && is_file($file_path) && $file->size > $this->get_file_size($file_path);
     if ($uploaded_file && is_uploaded_file($uploaded_file)) {
         // multipart/formdata uploads (POST method uploads)
         if ($append_file) {
             file_put_contents($file_path, fopen($uploaded_file, 'r'), FILE_APPEND);
         } else {
             $res = move_uploaded_file($uploaded_file, $file_path);
         }
     } else {
         // Non-multipart uploads (PUT method support)
         file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0);
     }
     $file_size = $this->get_file_size($file_path, $append_file);
     if ($file_size === $file->size) {
         $file->url = $this->get_download_url($file->name);
         if ($this->is_valid_image_file($file_path)) {
             $this->handle_image_file($file_path, $file);
         }
     } else {
         $file->size = $file_size;
         if (!$content_range && $this->options['discard_aborted_uploads']) {
             $this->delete_file($filename_with_prefix, $this->options['storage_type']);
             $file->error = 'abort';
         }
     }
     $this->set_additional_file_properties($file);
     // exif データの取得
     $exif = array();
     if ($this->options['is_save_exif_to_db'] && $extention == 'jpg') {
         $exif = \Util_Exif::get_exif($file_path, $this->options['exif_accept_tags'], $this->options['exif_ignore_tags']);
     }
     if ($this->options['upload_type'] == 'img') {
         // 大きすぎる場合はリサイズ & 保存ファイルから exif 情報削除
         $file_size_before = $file->size;
         if ($this->options['member_id'] && $this->options['user_type'] === 0 && ($max_size = Site_Upload::get_accepted_max_size($this->options['member_id']))) {
             $file->size = Site_Upload::check_max_size_and_resize($file_path, $max_size);
         }
         // Exif情報の削除
         $is_resaved = $file->size != $file_size_before;
         if ($this->options['is_clear_exif_on_file'] && !$is_resaved) {
             Site_Upload::clear_exif($file_path);
             $file->size = File::get_size($file_path);
         }
         if (!empty($this->options['accept_sizes'])) {
             $file->accept_sizes = $this->options['accept_sizes'];
         }
     }
     try {
         if ($this->options['storage_type'] != 'normal') {
             $this->save_file2storage($file_path, $filename_with_prefix);
             $this->delete_file($filename_with_prefix, $this->options['storage_type'], false, false);
         }
         $file->id = $this->save_file($file, $exif);
     } catch (\Exception $e) {
         if ($this->options['is_output_log_save_error']) {
             \Util_Toolkit::log_error(sprintf('file save error: %s', $e->getMessage()));
         }
         $this->delete_file($filename_with_prefix, $this->options['storage_type']);
         $file->error = 'ファイルの保存に失敗しました。';
     }
     return $file;
 }
Beispiel #13
0
 public function provider_signup($provider, $response = null)
 {
     $service_name = isset($response['auth']['info']['name']) ? $response['auth']['info']['name'] : $response['auth']['info']['nickname'];
     $input = array('uid' => (string) $response['auth']['uid'], 'token' => $response['auth']['credentials']['token'], 'service_name' => $response['auth']['info']['name']);
     if (!empty($response['auth']['credentials']['expires'])) {
         $input['expires'] = strtotime($response['auth']['credentials']['expires']);
     }
     if ($service_url = $this->get_service_url($provider, $response)) {
         $input['service_url'] = $service_url;
     }
     try {
         $member_oauth = Model_MemberOauth::forge();
         $val = Validation::forge('provider_signup');
         $val->add_model($member_oauth);
         $val->fieldset()->field('member_id')->delete_rule('required');
         if (!$val->run($input)) {
             throw new \FuelException($val->show_errors());
         }
         $input = $val->validated();
         $provider_id = Model_OauthProvider::get_id($provider);
         \DB::start_transaction();
         $member = Model_Member::forge();
         $member->name = str_replace(' ', '', $input['service_name']);
         list($member->sex, $member->sex_public_flag) = Site_Oauth::get_sex($response, $provider);
         list($member->birthyear, $member->birthyear_public_flag) = Site_Oauth::get_birthyear($response, $provider);
         list($member->birthday, $member->birthday_public_flag) = Site_Oauth::get_birthday($response, $provider);
         $member->filesize_total = 0;
         $member->register_type = $provider_id;
         if ($member->save() === false) {
             throw new \FuelException('Member save failed.');
         }
         $member_oauth->member_id = $member->id;
         $member_oauth->oauth_provider_id = $provider_id;
         $member_oauth->uid = $input['uid'];
         $member_oauth->token = $input['token'];
         $member_oauth->secret = $input['secret'];
         $member_oauth->service_name = $input['service_name'];
         if (!empty($input['expires'])) {
             $member_oauth->expires = $input['expires'];
         }
         if (!empty($input['service_url'])) {
             $member_oauth->service_url = $input['service_url'];
         }
         if ($member_oauth->save() === false) {
             throw new \FuelException('Oauth data save failed.');
         }
         if (!empty($response['auth']['info']['email'])) {
             Model_Memberauth::save_email($response['auth']['info']['email'], $member->id);
         }
         if (conf('auth.oauth.saveTermsUnAgreement')) {
             Model_MemberConfig::set_value($member->id, 'terms_un_agreement', 1);
         }
         // timeline 投稿
         if (is_enabled('timeline')) {
             \Timeline\Site_Model::save_timeline($member->id, null, 'member_register', $member->id, $member->created_at);
         }
         \DB::commit_transaction();
         if (!empty($response['auth']['info']['image'])) {
             $this->save_profile_image($response['auth']['provider'], $response['auth']['info']['image'], $member);
         }
     } catch (\FuelException $e) {
         if (\DB::in_transaction()) {
             \DB::rollback_transaction();
         }
         if (conf('auth.oauth.log.isOutputErrorLog.provider_signup')) {
             \Util_Toolkit::log_error('OAuth provider_signup error: ' . isset($e) ? $e->getMessage() : '');
         }
         return $this->login_failed();
     }
     $this->force_login($member->id);
     if (conf('auth.oauth.forceSetRememberMe')) {
         Auth::remember_me();
     }
     return $this->login_succeeded();
 }
Beispiel #14
0
 /**
  * Execute register email.
  * 
  * @access  public
  * @return  Response
  */
 public function action_register($mode = null)
 {
     Util_security::check_method('POST');
     Util_security::check_csrf();
     list($mode, $is_registerd, $is_regist_mode, $action_name, $is_oauth_registerd_user) = $this->get_common_vals($mode);
     $this->set_validation_email($is_oauth_registerd_user);
     $this->set_validation_code();
     $error_message = '';
     $is_transaction_rollback = false;
     try {
         if (!$this->val_obj->run()) {
             throw new ValidationFailedException($this->val_obj->show_errors());
         }
         $post = $this->val_obj->validated();
         if (!$is_oauth_registerd_user && !$this->auth_instance->check_password()) {
             throw new ValidationFailedException(term('site.password') . 'が正しくありません');
         }
         $member_email_pre = Model_MemberEmailPre::get4member_id($this->u->id);
         $code_error_message = sprintf('%sが正しくないか、%sが過ぎてます。再度%sを%sしてください。', term('form.confirm', 'site.code'), term('form.enabled', 'common.timelimit'), term('form.for_confirm', 'site.mail'), term('form.send'));
         $this->check_email_registered($member_email_pre ? $member_email_pre->email : $post['email'], $mode, $code_error_message, true);
         if (!$member_email_pre || !self::check_confirmation_code($member_email_pre, $post['code'])) {
             throw new ValidationFailedException($code_error_message);
         }
         $email = $member_email_pre->email;
         $values = array('email' => $email);
         if (!$is_oauth_registerd_user) {
             $values['password'] = $post['password'];
             $values['old_password'] = $post['password'];
         }
         DB::start_transaction();
         if (!$this->auth_instance->update_user($values, $this->u->id)) {
             throw new FuelException('Change email error.');
         }
         $member_email_pre->delete();
         // 仮登録情報の削除
         DB::commit_transaction();
         $this->set_current_user();
         $mail = new Site_Mail('memberRegisterEmailConfirm');
         $mail->send($email, array('to_name' => $this->u->name));
         Session::set_flash('message', sprintf('%sを%sしました。', term('site.email'), $action_name));
         Response::redirect('member/setting');
     } catch (ValidationFailedException $e) {
         $error_message = $e->getMessage();
     } 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 = term('site.email') . 'の変更に失敗しました。';
     } catch (\Database_Exception $e) {
         $is_transaction_rollback = true;
         $error_message = \Site_Controller::get_error_message($e, true);
     } catch (FuelException $e) {
         $is_transaction_rollback = true;
         if (!($error_message = $e->getMessage())) {
             $error_message = sprintf('%sの%sに失敗しました。', term('site.email'), $action_name);
         }
     }
     if ($error_message) {
         if ($is_transaction_rollback && DB::in_transaction()) {
             DB::rollback_transaction();
         }
         Session::set_flash('error', $error_message);
     }
     $this->action_register_confirm($mode);
 }