request->getPost(); /** * 使用[account|phone|email]做账户名字段兼容 */ if (isset($post['phone'])) { $post['account'] = $post['phone']; } elseif (isset($post['email'])) { $post['account'] = $post['email']; } $verifyValidator = new VerifyValidator(); $verifyValidator->checkCode($post['account'], $post['verify_code']); $accountValidator = new AccountValidator(); $accountValidator->checkLoginName($post['account']); $data = []; if (CommonValidator::phone($post['account'])) { $data['phone'] = $accountValidator->checkPhone($post['account']); $accountValidator->checkIfPhoneTaken($post['account']); } elseif (CommonValidator::email($post['account'])) { $data['email'] = $accountValidator->checkEmail($post['account']); $accountValidator->checkIfEmailTaken($post['account']); } $data['password'] = $accountValidator->checkPassword($post['password']); $data['salt'] = PasswordUtil::salt(); $data['password'] = PasswordUtil::hash($data['password'], $data['salt']); try { $this->db->begin(); $account = new AccountModel(); if ($account->create($data) === false) { throw new \RuntimeException('Create Account Failed'); } $this->db->commit(); return $account; } catch (\Exception $e) { $this->db->rollback(); $logger = $this->getLogger(); $logger->error('Register Error ' . kg_json_encode([ 'line' => $e->getLine(), 'code' => $e->getCode(), 'message' => $e->getMessage(), ])); throw new \RuntimeException('sys.trans_rollback'); } } }