Esempio n. 1
0
 /**
  * 이메일의 인증여부를 체크한다.
  * 주어진 이메일 주소가 등록대기 이메일 목록에 있는지 실제 이메일 목록에 있는지 체크한 후 반환한다.
  *
  * @param string $email 체크할 이메일 주소
  *
  * @return boolean 이메일 인증 여부
  */
 public function checkEmailConfirmation($email)
 {
     $mail = $this->pendingMails->findByAddress($email);
     if ($mail !== null) {
         return false;
     }
     $mail = $this->mails->findByAddress($email);
     if ($mail === null) {
         throw new NotFoundEmailException();
     }
     return true;
 }
 public function addMail(Request $request)
 {
     $input = $request->only('address');
     // validation
     $validate = \Validator::make($request->all(), ['address' => 'email|required']);
     if ($validate->fails()) {
         $e = new InvalidArgumentException();
         $e->setMessage('이메일 형식이 잘못되었습니다.');
         throw $e;
     }
     // 이미 인증 요청중인 이메일이 있는지 확인한다.
     $useEmailConfirm = $this->handler->usingEmailConfirm();
     if ($useEmailConfirm) {
         if ($this->member->getPendingEmail() !== null) {
             throw new AlreadyPendingEmailExistsException();
         }
     }
     // 이미 존재하는 이메일이 있는지 확인한다.
     $exists = $this->mails->findByAddress($input['address']);
     if ($exists !== null) {
         throw new MailAlreadyExistsException();
     }
     array_set($input, 'memberId', $this->member->getId());
     XeDB::beginTransaction();
     try {
         if ($useEmailConfirm) {
             $mail = new PendingMailEntity($input);
             $mail = $this->pendingMails->insert($mail);
             /** @var EmailBroker $broker */
             $broker = app('xe.auth.email');
             $broker->sendEmailForConfirmation($mail);
         } else {
             $mail = new MailEntity($input);
             $mail = $this->mails->insert($mail);
         }
     } catch (\Exception $e) {
         XeDB::rollback();
         throw $e;
     }
     XeDB::commit();
     \Session::flash('alert', ['type' => 'success', 'message' => '추가되었습니다.']);
     return Presenter::makeApi(['message' => '추가되었습니다']);
 }