public function addMail(Request $request)
{
$input = $request->only('address');
// validation
$this->validate($request, ['address' => 'email|required'], [], ['address' => xe_trans('xe::email')]);
// 이미 인증 요청중인 이메일이 있는지 확인한다.
$useEmailConfirm = $this->handler->usingEmailConfirm();
if ($useEmailConfirm) {
if ($this->user->getPendingEmail() !== null) {
$e = new PendingEmailAlreadyExistsException();
throw new HttpException(400, $e->getMessage(), $e);
}
}
// 이미 존재하는 이메일이 있는지 확인한다.
if ($this->emails->findByAddress($input['address'])) {
$e = new MailAlreadyExistsException();
throw new HttpException(400, $e->getMessage(), $e);
}
//array_set($input, 'userId', $this->user->getId());
XeDB::beginTransaction();
try {
$mail = $this->handler->createEmail($this->user, $input, !$useEmailConfirm);
if ($useEmailConfirm) {
/** @var EmailBroker $broker */
$broker = app('xe.auth.email');
$broker->sendEmailForConfirmation($mail);
}
} catch (\Exception $e) {
XeDB::rollback();
throw $e;
}
XeDB::commit();
\Session::flash('alert', ['type' => 'success', 'message' => '추가되었습니다.']);
return XePresenter::makeApi(['message' => '추가되었습니다']);
}