public function indexAction(Request $request) { $fields = $request->query->all(); $user = $this->getCurrentUser(); if ($user->isLogin()) { return $this->createMessageResponse('info', '你已经登录了', null, 3000, $this->generateUrl('homepage')); } $registerEnable = $this->getAuthService()->isRegisterEnabled(); if (!$registerEnable) { return $this->createMessageResponse('info', '注册已关闭,请联系管理员', null, 3000, $this->generateUrl('homepage')); } if ($request->getMethod() == 'POST') { $registration = $request->request->all(); // $registration['mobile'] = isset($registration['verifiedMobile']) ? $registration['verifiedMobile'] : ''; if (isset($registration['emailOrMobile']) && SimpleValidator::mobile($registration['emailOrMobile'])) { $registration['verifiedMobile'] = $registration['emailOrMobile']; } $registration['mobile'] = isset($registration['verifiedMobile']) ? $registration['verifiedMobile'] : ''; $registration['createdIp'] = $request->getClientIp(); $authSettings = $this->getSettingService()->get('auth', array()); //验证码校验 $this->captchaEnabledValidator($authSettings, $registration, $request); //手机校验码 if ($this->smsCodeValidator($authSettings, $registration, $request)) { $registration['verifiedMobile'] = ''; $request->request->add(array_merge($request->request->all(), array('mobile' => $registration['mobile']))); list($result, $sessionField, $requestField) = SmsToolkit::smsCheck($request, $scenario = 'sms_registration'); if ($result) { $registration['verifiedMobile'] = $sessionField['to']; } else { return $this->createMessageResponse('info', '手机号码和短信验证码不匹配,请重新注册'); } } //ip次数限制 if ($this->registerLimitValidator($registration, $authSettings, $request)) { return $this->createMessageResponse('info', '由于您注册次数过多,请稍候尝试'); } $user = $this->getAuthService()->register($registration); $authSettings = $this->getSettingService()->get('auth', array()); if ($authSettings && isset($authSettings['email_enabled']) && $authSettings['email_enabled'] == 'closed' || !$this->isEmptyVeryfyMobile($user)) { $this->authenticateUser($user); } $goto = $this->generateUrl('register_submited', array('id' => $user['id'], 'hash' => $this->makeHash($user), 'goto' => $this->getTargetPath($request))); if ($this->getAuthService()->hasPartnerAuth()) { $this->authenticateUser($user); return $this->redirect($this->generateUrl('partner_login', array('goto' => $goto))); } return $this->redirect($goto); } $inviteCode = ''; if (!empty($fields['inviteCode'])) { $inviteUser = $this->getUserService()->getUserByInviteCode($fields['inviteCode']); } if (!empty($inviteUser)) { $inviteCode = $fields['inviteCode']; } return $this->render("TopxiaWebBundle:Register:index.html.twig", array('inviteCode' => $inviteCode, 'isRegisterEnabled' => $registerEnable, 'registerSort' => array(), '_target_path' => $this->getTargetPath($request))); }
public function resetBySmsAction(Request $request) { if ($request->getMethod() == 'POST') { $data = $request->request->all(); list($result, $sessionField, $requestField) = SmsToolkit::smsCheck($request, $scenario = 'sms_forget_password'); if ($result) { $targetUser = $this->getUserService()->getUserByVerifiedMobile($request->request->get('mobile')); if (empty($targetUser)) { return $this->createMessageResponse('error', '用户不存在,请重新找回'); } $token = $this->getUserService()->makeToken('password-reset', $targetUser['id'], strtotime('+1 day')); $request->request->set('token', $token); return $this->redirect($this->generateUrl('password_reset_update', array('token' => $token))); } else { return $this->createMessageResponse('error', '手机短信验证错误,请重新找回'); } } return $this->createJsonResponse('GET method'); }
public function createAction(Request $request) { $fields = $request->request->all(); if (isset($fields['coinPayAmount']) && $fields['coinPayAmount'] > 0) { $scenario = "sms_user_pay"; if ($this->setting('cloud_sms.sms_enabled') == '1' && $this->setting("cloud_sms.{$scenario}") == 'on') { list($result, $sessionField, $requestField) = SmsToolkit::smsCheck($request, $scenario); if (!$result) { return $this->createMessageResponse('error', '短信验证失败。'); } } } $user = $this->getCurrentUser(); if (!$user->isLogin()) { return $this->createMessageResponse('error', '用户未登录,创建订单失败。'); } if (!array_key_exists("targetId", $fields) || !array_key_exists("targetType", $fields)) { return $this->createMessageResponse('error', '订单中没有购买的内容,不能创建!'); } $targetType = $fields["targetType"]; $targetId = $fields["targetId"]; $maxRate = $fields["maxRate"]; $priceType = "RMB"; $coinSetting = $this->setting("coin"); $coinEnabled = isset($coinSetting["coin_enabled"]) && $coinSetting["coin_enabled"]; if ($coinEnabled && isset($coinSetting["price_type"])) { $priceType = $coinSetting["price_type"]; } $cashRate = 1; if ($coinEnabled && isset($coinSetting["cash_rate"])) { $cashRate = $coinSetting["cash_rate"]; } $processor = OrderProcessorFactory::create($targetType); try { if (isset($fields["couponCode"]) && $fields["couponCode"] == "请输入优惠码") { $fields["couponCode"] = ""; } list($amount, $totalPrice, $couponResult) = $processor->shouldPayAmount($targetId, $priceType, $cashRate, $coinEnabled, $fields); $amount = (string) (double) $amount; $shouldPayMoney = (string) (double) $fields["shouldPayMoney"]; //价格比较 if (intval($totalPrice * 100) != intval($fields["totalPrice"] * 100)) { $this->createMessageResponse('error', "实际价格不匹配,不能创建订单!"); } //价格比较 if (intval($amount * 100) != intval($shouldPayMoney * 100)) { return $this->createMessageResponse('error', '支付价格不匹配,不能创建订单!'); } //虚拟币抵扣率比较 if (isset($fields['coinPayAmount']) && intval((double) $fields['coinPayAmount'] * 100) > intval($totalPrice * $maxRate * 100)) { return $this->createMessageResponse('error', '虚拟币抵扣超出限定,不能创建订单!'); } if (isset($couponResult["useable"]) && $couponResult["useable"] == "yes") { $coupon = $fields["couponCode"]; $couponDiscount = $couponResult["decreaseAmount"]; } $orderFileds = array('priceType' => $priceType, 'totalPrice' => $totalPrice, 'amount' => $amount, 'coinRate' => $cashRate, 'coinAmount' => empty($fields["coinPayAmount"]) ? 0 : $fields["coinPayAmount"], 'userId' => $user["id"], 'payment' => 'alipay', 'targetId' => $targetId, 'coupon' => empty($coupon) ? '' : $coupon, 'couponDiscount' => empty($couponDiscount) ? 0 : $couponDiscount); $order = $processor->createOrder($orderFileds, $fields); if ($order["status"] == "paid") { return $this->redirect($this->generateUrl($processor->getRouter(), array('id' => $order["targetId"]))); } return $this->redirect($this->generateUrl('pay_center_show', array('sn' => $order['sn']))); } catch (\Exception $e) { return $this->createMessageResponse('error', $e->getMessage()); } }
public function indexAction(Request $request) { $user = $this->getCurrentUser(); if ($user->isLogin()) { return $this->createMessageResponse('info', '你已经登录了', null, 3000, $this->generateUrl('homepage')); } $registerEnable = $this->getAuthService()->isRegisterEnabled(); if (!$registerEnable) { return $this->createMessageResponse('info', '注册已关闭,请联系管理员', null, 3000, $this->generateUrl('homepage')); } $form = $this->createForm(new RegisterType()); if ($request->getMethod() == 'POST') { $registration = $request->request->all(); $authSettings = $this->getSettingService()->get('auth', array()); //验证码校验 $this->captchaEnabledValidator($authSettings, $registration, $request); //手机校验码 if ($this->smsCodeValidator($authSettings, $registration, $request)) { $registration['verifiedMobile'] = ''; list($result, $sessionField, $requestField) = SmsToolkit::smsCheck($request, $scenario = 'sms_registration'); if ($result) { $registration['verifiedMobile'] = $sessionField['to']; } else { return $this->createMessageResponse('info', '手机短信验证错误,请重新注册'); } } //ip次数限制 if ($this->registerLimitValidator($registration, $authSettings, $request)) { return $this->createMessageResponse('info', '由于您注册次数过多,请稍候尝试'); } $user = $this->getAuthService()->register($registration); if (!isset($registration['nickname'])) { return $this->render("TopxiaWebBundle:Register:nickname-update.html.twig", array('user' => $user)); } else { $authSettings = $this->getSettingService()->get('auth', array()); if ($authSettings && array_key_exists('email_enabled', $authSettings) && $authSettings['email_enabled'] == 'closed' || !$this->isEmptyVeryfyMobile($user)) { $this->authenticateUser($user); $this->sendRegisterMessage($user); } $goto = $this->generateUrl('register_submited', array('id' => $user['id'], 'hash' => $this->makeHash($user), 'goto' => $this->getTargetPath($request))); if ($this->getAuthService()->hasPartnerAuth()) { $this->authenticateUser($user); $this->sendRegisterMessage($user); return $this->redirect($this->generateUrl('partner_login', array('goto' => $goto))); } $mailerSetting = $this->getSettingService()->get('mailer'); if (!$mailerSetting['enabled'] && $this->isEmptyVeryfyMobile($user)) { return $this->redirect($this->getTargetPath($request)); } return $this->redirect($goto); } } $auth = $this->getSettingService()->get('auth'); if (!isset($auth['registerSort'])) { $auth['registerSort'] = ""; } $userFields = $this->getUserFieldService()->getAllFieldsOrderBySeqAndEnabled(); for ($i = 0; $i < count($userFields); $i++) { if (strstr($userFields[$i]['fieldName'], "textField")) { $userFields[$i]['type'] = "text"; } if (strstr($userFields[$i]['fieldName'], "varcharField")) { $userFields[$i]['type'] = "varchar"; } if (strstr($userFields[$i]['fieldName'], "intField")) { $userFields[$i]['type'] = "int"; } if (strstr($userFields[$i]['fieldName'], "floatField")) { $userFields[$i]['type'] = "float"; } if (strstr($userFields[$i]['fieldName'], "dateField")) { $userFields[$i]['type'] = "date"; } } if ($this->setting('cloud_sms.sms_enabled', '0') == '1' && $this->setting('cloud_sms.sms_registration', 'off') == 'on' && !in_array('mobile', $auth['registerSort']) && $this->setting('auth.register_mode') != 'email_or_mobile' && $this->setting('auth.register_mode') != 'mobile') { $auth['registerSort'][] = "mobile"; } return $this->render("TopxiaWebBundle:Register:index.html.twig", array('isRegisterEnabled' => $registerEnable, 'registerSort' => $auth['registerSort'], 'userFields' => $userFields, '_target_path' => $this->getTargetPath($request))); }
public function bindMobileAction(Request $request) { $currentUser = $this->getCurrentUser()->toArray(); $verifiedMobile = ''; $hasVerifiedMobile = isset($currentUser['verifiedMobile']) && strlen($currentUser['verifiedMobile']) > 0; if ($hasVerifiedMobile) { $verifiedMobile = $currentUser['verifiedMobile']; } $setMobileResult = 'none'; $scenario = "sms_bind"; if ($this->setting('cloud_sms.sms_enabled') != '1' || $this->setting("cloud_sms.{$scenario}") != 'on') { return $this->render('TopxiaWebBundle:Settings:edu-cloud-error.html.twig', array()); } if ($request->getMethod() == 'POST') { $password = $request->request->get('password'); if (!$this->getAuthService()->checkPassword($currentUser['id'], $password)) { $this->setFlashMessage('danger', '您的登录密码错误'); SmsToolkit::clearSmsSession($request, $scenario); return $this->bindMobileReturn($hasVerifiedMobile, $setMobileResult, $verifiedMobile); } list($result, $sessionField, $requestField) = SmsToolkit::smsCheck($request, $scenario); if ($result) { $verifiedMobile = $sessionField['to']; $this->getUserService()->changeMobile($currentUser['id'], $verifiedMobile); $setMobileResult = 'success'; $this->setFlashMessage('success', '绑定成功'); } else { $setMobileResult = 'fail'; $this->setFlashMessage('danger', '绑定失败,原短信失效'); } } return $this->bindMobileReturn($hasVerifiedMobile, $setMobileResult, $verifiedMobile); }