public function approveRegistration(Request $request, $customerId) { if (!isset($request->request['amount'])) { return JsonErrorResponse::fromKey(JsonErrorResponse::INVALID_REQUEST_PARAMETER); } $amount = $request->request['amount']; if (!filter_var($amount, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^\\d*(\$|\\.\\d\\d\$)/")))) { return JsonErrorResponse::fromKey(JsonErrorResponse::INVALID_AMOUNT); } $amount = floatval($amount); $customerRepository = $this->getCustomerRepository(); $customer = $customerRepository->getCustomerById($customerId); if (is_null($customer)) { return JsonErrorResponse::fromKey(JsonErrorResponse::INVALID_CUSTOMER_ID); } if ($customer->status == 'pending') { $credentials = $customerRepository->getCustomerCredentials($customer); if (is_null($credentials['scs_pin'])) { $password = Helper::randomString(5); $message = "Dear {$customer->firstname} {$customer->lastname}," . PHP_EOL . "your Account was successfully approved!" . "You can now login and make transactions with your tan list" . $password . PHP_EOL . PHP_EOL . "Best Regards," . PHP_EOL . "SitzBank"; $mail = Helper::getPhpMailer(); $mail->addAddress($customer->email, $customer->firstname . ' ' . $customer->lastname); $mail->Subject = "Account approved!"; $mail->Body = $message; if (!$mail->send()) { return JsonErrorResponse::fromKey(JsonErrorResponse::MAIL_ERROR); } } else { // using the scs generator $message = "Dear {$customer->firstname} {$customer->lastname}," . PHP_EOL . "your Account was successfully approved! You chose to use the scs tan generator." . PHP_EOL . "You can download the generator in the logged in area (make a transfer section)." . PHP_EOL . "Your scs pin is " . $credentials['scs_pin'] . PHP_EOL . "Best Regards," . PHP_EOL . "SitzBank"; $mail = Helper::getPhpMailer(); $mail->addAddress($customer->email, $customer->firstname . ' ' . $customer->lastname); $mail->Subject = "Welcome to Sitzbank!"; $mail->Body = $message; if (!$mail->send()) { return JsonErrorResponse::fromKey(JsonErrorResponse::MAIL_ERROR); } } } if ($customerRepository->approveRegistration($customerId)) { if ($amount > 0) { $transaction = Transaction::withData(1, $customer->id, $amount, "Initial Account Balance", 'approved'); $this->getTransactionRepository()->createTransaction($transaction); } return new JsonResponse(array('success' => true)); } return JsonErrorResponse::fromKey(JsonErrorResponse::UNEXPECTED_ERROR); }
public function requestNewPassword(Request $request) { $email = isset($request->request['email']) ? $request->request['email'] : null; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { return JsonErrorResponse::fromKey(JsonErrorResponse::INVALID_REQUEST_EMAIL); } $customer = $this->getCustomerRepository()->getCustomerByEmail($email); if (!is_null($customer)) { $token = Helper::randomString(32); $validUntil = time() + 10800; // 3h if (!$this->getCustomerRepository()->savePasswordReset($customer->id, $token, $validUntil)) { return JsonErrorResponse::fromKey(JsonErrorResponse::UNEXPECTED_ERROR); } $message = "Dear {$customer->firstname} {$customer->lastname}," . PHP_EOL . "You can reset your your password using the following link https://sitzbank.local/#/resetPassword and this token:" . PHP_EOL . PHP_EOL . $token . PHP_EOL . PHP_EOL . "Best Regards," . PHP_EOL . "SitzBank"; $mail = Helper::getPhpMailer(); $mail->addAddress($customer->email, $customer->firstname . ' ' . $customer->lastname); $mail->Subject = "Reset your SecureBank Password."; $mail->Body = $message; if (!$mail->send()) { return JsonErrorResponse::fromKey(JsonErrorResponse::MAIL_ERROR); } } return new JsonResponse(array('message' => 'If an account exists for this email an password rest email has been sent.')); }