1 | <?php |
||
16 | class Confirmation extends ConfirmationAbstract |
||
17 | { |
||
18 | /** |
||
19 | * {@inheritdoc} |
||
20 | */ |
||
21 | protected function sendToken(ConfirmationSubjectInterface $subject, $token) |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | public function verify(Request $request, $token) |
||
48 | { |
||
49 | $form = $this->createVerifyForm(); |
||
50 | |||
51 | /** @var VerificationInterface $data */ |
||
52 | $data = $form->getData(); |
||
53 | $data->setToken($token); |
||
54 | |||
55 | if (in_array($request->getMethod(), array('POST', 'PUT', 'PATCH'))) { |
||
56 | $form->submit($request, !$request->isMethod('PATCH')); |
||
57 | |||
58 | $data->setSubject($this->findSubjectWithToken($data->getToken())); |
||
59 | |||
60 | if (!$form->isValid()) { |
||
61 | return $form; |
||
62 | } |
||
63 | |||
64 | if (!$this->validateTimeAware($subject = $data->getSubject())) { |
||
65 | $form->addError(new FormError('ui.trans.user.confirmation.verify.invalid_time')); |
||
66 | } |
||
67 | |||
68 | if (!$otp = $this->findOtp($data->getSubject())) { |
||
69 | $form->addError(new FormError('ui.trans.user.confirmation.verify.invalid_token')); |
||
70 | } |
||
71 | |||
72 | if ($otp->getVerify() !== $data->getVerifyValue()) { |
||
73 | $form->addError(new FormError('ui.trans.user.confirmation.verify.invalid_otp')); |
||
74 | } |
||
75 | |||
76 | if (!$form->getErrors(true)->count()) { |
||
77 | $otp->setConfirmed(true); |
||
78 | $this->successVerify($subject); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | return $form; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @param ConfirmationSubjectInterface $subject |
||
87 | * |
||
88 | * @return \DoS\UserBundle\Model\OneTimePasswordInterface |
||
89 | */ |
||
90 | protected function findOtp(ConfirmationSubjectInterface $subject) |
||
91 | { |
||
92 | $er = $this->manager->getRepository($this->options['otp_class']); |
||
93 | |||
94 | return $er->findOneBy(array( |
||
95 | 'subject' => $subject, |
||
96 | 'token' => $subject->getConfirmationToken(), |
||
97 | )); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | protected function configureOptions(OptionsResolver $resolver) |
||
104 | { |
||
105 | parent::configureOptions($resolver); |
||
106 | |||
107 | $resolver->setDefaults(array( |
||
108 | 'otp_class' => 'DoS\UserBundle\Model\OneTimePassword', |
||
109 | 'channel_path' => 'customer.mobile', |
||
110 | 'token_resend_form' => 'dos_resend_confirmation_otp', |
||
111 | 'token_verify_form' => 'dos_verification_otp', |
||
112 | )); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function getResendModel() |
||
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | public function getVerifyModel() |
||
130 | |||
131 | /** |
||
132 | * {@inheritdoc} |
||
133 | */ |
||
134 | public function getType() |
||
138 | } |
||
139 |