Skip to content

Commit a417bf8

Browse files
author
sisishiliu
committed
1.0 beta-2
1 parent 1f9b53d commit a417bf8

57 files changed

Lines changed: 629 additions & 373 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/config.sample.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
'apiPageSiteInit' => "./index.php?action=installDB",
1717
'apiSiteLogin' => './index.php?action=api.site.login&body_format=pb',
1818
'session_verify_101' => 'http://open.akaxin.com:5208/index.php?action=api.session.verify&body_format=pb',
19-
'session_verify_102' => 'http://127.0.0.1/index.php?action=api.session.verify&body_format=pb',
19+
'session_verify_102' => './index.php?action=api.session.verify&body_format=pb',
2020
"siteAddress" => '',
2121
'passport_cookie_name' => "duckchat_passport_cookie",
2222
'mail' =>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: zhangjun
5+
* Date: 10/09/2018
6+
* Time: 10:46 AM
7+
*/
8+
9+
10+
class Api_Passport_PasswordModifyPasswordController extends BaseController
11+
{
12+
private $classNameForRequest = '\Zaly\Proto\Site\ApiPassportPasswordModifyPasswordRequest';
13+
private $classNameForResponse = '\Zaly\Proto\Site\ApiPassportPasswordModifyPasswordResponse';
14+
15+
public function rpcRequestClassName()
16+
{
17+
return $this->classNameForRequest;
18+
}
19+
20+
/**
21+
* @param \Zaly\Proto\Site\ApiPassportPasswordModifyPasswordRequest $request
22+
* @param \Google\Protobuf\Internal\Message $transportData
23+
*/
24+
public function rpc(\Google\Protobuf\Internal\Message $request, \Google\Protobuf\Internal\Message $transportData)
25+
{
26+
$tag = __CLASS__ . '-' . __FUNCTION__;
27+
try{
28+
$newPassword = $request->getNewPassword();
29+
$password = $request->getPassword();
30+
$loginName = $request->getLoginName();
31+
$this->ctx->Wpf_Logger->error($tag, "error_msg=" . $request->serializeToJsonString());
32+
$this->checkOldPassword($loginName, $password);
33+
$this->updatePasswordByLoginName($loginName, $newPassword);
34+
$this->setRpcError($this->defaultErrorCode, "");
35+
}catch (Exception $ex) {
36+
$this->ctx->Wpf_Logger->error($tag, "error_msg=" . $ex->getMessage());
37+
}
38+
$this->rpcReturn($transportData->getAction(), new $this->classNameForResponse());
39+
}
40+
41+
private function checkOldPassword($loginName, $password)
42+
{
43+
$userInfo = $this->ctx->PassportPasswordTable->getUserByLoginName($loginName);
44+
if($userInfo == false) {
45+
$errorCode = $this->zalyError->errorExistUser;
46+
$errorInfo = $this->zalyError->getErrorInfo($errorCode);
47+
$this->setRpcError($errorCode, $errorInfo);
48+
throw new Exception("user is not exists");
49+
}
50+
51+
if(!password_verify($password, $userInfo['password'])) {
52+
$errorCode = $this->zalyError->errorMatchLogin;
53+
$errorInfo = $this->zalyError->getErrorInfo($errorCode);
54+
$this->setRpcError($errorCode, $errorInfo);
55+
throw new Exception("loginName password is not match");
56+
}
57+
}
58+
59+
private function updatePasswordByLoginName($loginName, $password)
60+
{
61+
$tag = __CLASS__ . '-' . __FUNCTION__;
62+
63+
try{
64+
$where = [
65+
"loginName" => $loginName
66+
];
67+
$data = [
68+
"password" => password_hash($password, PASSWORD_BCRYPT)
69+
];
70+
$this->ctx->PassportPasswordTable->updateUserData($where, $data);
71+
}catch (Exception $ex) {
72+
$this->ctx->Wpf_Logger->error($tag, "error_msg=" . $ex->getMessage());
73+
$errorCode = $this->zalyError->errorUpdatePwd;
74+
$errorInfo = $this->zalyError->getErrorInfo($errorCode);
75+
$this->setRpcError($errorCode, $errorInfo);
76+
throw new Exception("update password failed ");
77+
}
78+
}
79+
}

src/controller/Api/Plugin/Api_Plugin_ProxyController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ private function getPluginRequestUrl($reqUrl, $pluginId)
105105
$port = empty($pluginUrl["port"]) ? "" : ":{$pluginUrl["port"]}";
106106
$host = $host . $port;
107107
}
108-
109-
$url = "{$schema}://{$host}/{$reqUrl}";
108+
if(strpos($reqUrl, "/") == 0) {
109+
$url = "{$schema}://{$host}{$reqUrl}";
110+
} else {
111+
$url = "{$schema}://{$host}/{$reqUrl}";
112+
}
110113
return $url;
111114
} catch (Exception $e) {
112115
$this->ctx->Wpf_Logger->info($tag, " error_msg=" . $e->getMessage());

src/controller/Api/Site/Api_Site_LoginController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function rpc(\Google\Protobuf\Internal\Message $request, \Google\Protobuf
4848
throw new Exception("with error parameters");
4949
}
5050

51-
$this->ctx->Wpf_Logger->info("api.site.login", " =========preSessionId=" . $preSessionId);
51+
$this->ctx->Wpf_Logger->info("api.site.login", "preSessionId=" . $preSessionId);
5252
// $this->ctx->Wpf_Logger->info("api.site.login", " -devicePubkPem=" . $devicePubkPem);
5353

5454
if (!$preSessionId) {
@@ -58,8 +58,8 @@ public function rpc(\Google\Protobuf\Internal\Message $request, \Google\Protobuf
5858
throw new Exception($errorInfo);
5959
}
6060

61-
//get user profile from platform
62-
$userProfile = $this->ctx->Site_Login->checkPreSessionIdFromPlatform($preSessionId, $devicePubkPem);
61+
//get user profile from platform clientSiteType=1:mobile client
62+
$userProfile = $this->ctx->Site_Login->checkPreSessionIdFromPlatform($preSessionId, $devicePubkPem, 1);
6363

6464
$realSessionId = $userProfile['sessionId'];
6565
$this->ctx->Wpf_Logger->info("api.site.login", "get platform sessionid=" . $realSessionId);

src/controller/BaseController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ abstract class BaseController extends \Wpf_Controller
3636
"api.passport.passwordFindPassword",
3737
"api.passport.passwordResetPassword",
3838
"api.passport.passwordUpdateInvitationCode",
39+
"api.passport.passwordModifyPassword",
3940
"api.plugin.proxy",
4041
];
4142
protected $sessionIdTimeOut = 36000000; //10个小时的毫秒
@@ -226,7 +227,6 @@ public function doIndex()
226227
$this->handleHeader();
227228

228229
$this->getAndSetClientLang();
229-
$this->getZalyErrorLang();
230230

231231
$this->checkSessionId($this->action);
232232
$this->rpc($requestMessage, $this->requestTransportData);
@@ -363,15 +363,18 @@ protected function getAndSetClientLang()
363363
$requestTransportData = $this->requestTransportData;
364364
$headers = $requestTransportData->getHeader();
365365

366-
367366
$headLang = isset($headers[TransportDataHeaderKey::HeaderUserClientLang]) ? $headers[TransportDataHeaderKey::HeaderUserClientLang] : "";
368367

369368
$this->ctx->Wpf_Logger->info("client-language", "==" . $headLang);
370369

371370
if (isset($headLang) && $headLang == Zaly\Proto\Core\UserClientLangType::UserClientLangZH) {
372371
$this->language = Zaly\Proto\Core\UserClientLangType::UserClientLangZH;
372+
$this->zalyError = $this->ctx->ZalyErrorZh;
373+
374+
} else {
375+
$this->language = Zaly\Proto\Core\UserClientLangType::UserClientLangEN;
376+
$this->zalyError = $this->ctx->ZalyErrorEn;
373377
}
374378

375379
}
376-
377380
}

src/controller/Duckchat/Duckchat_MiniProgramController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ public function doIndex()
139139
$this->handleHeader();
140140

141141
$this->getAndSetClientLang();
142-
$this->getZalyErrorLang();
143142

144143
$this->rpc($requestMessage, $this->requestTransportData);
145144
}
@@ -260,15 +259,17 @@ protected function getAndSetClientLang()
260259
$requestTransportData = $this->requestTransportData;
261260
$headers = $requestTransportData->getHeader();
262261

263-
264262
$headLang = isset($headers[TransportDataHeaderKey::HeaderUserClientLang]) ? $headers[TransportDataHeaderKey::HeaderUserClientLang] : "";
265263

266264
$this->ctx->Wpf_Logger->info("client-language", "==" . $headLang);
267265

268266
if (isset($headLang) && $headLang == Zaly\Proto\Core\UserClientLangType::UserClientLangZH) {
269267
$this->language = Zaly\Proto\Core\UserClientLangType::UserClientLangZH;
268+
$this->zalyError = $this->ctx->ZalyErrorZh;
269+
} else {
270+
$this->language = \Zaly\Proto\Core\UserClientLangType::UserClientLangEN;
271+
$this->zalyError = $this->ctx->ZalyErrorEn;
270272
}
271-
272273
}
273274

274275
/**

src/controller/HttpBaseController.php

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract class HttpBaseController extends \Wpf_Controller
3232
private $u2Type = "u";
3333
private $jumpRoomType = "";
3434
private $jumpRoomId = "";
35-
private $jumpRelation="";
35+
private $jumpRelation = "";
3636
private $siteCookieName = "zaly_site_user";
3737

3838
public function __construct(Wpf_Ctx $context)
@@ -96,8 +96,7 @@ public function handlePreSessionId()
9696
$preSessionId = isset($_GET['preSessionId']) ? $_GET['preSessionId'] : "";
9797
if($preSessionId) {
9898
$userProfile = $this->ctx->Site_Login->checkPreSessionIdFromPlatform($preSessionId);
99-
$this->userId = $userProfile["userId"];
100-
$this->setCookieBase64($this->userId, $this->siteCookieName);
99+
$this->setCookieBase64($userProfile["sessionId"], $this->siteCookieName);
101100
}
102101
}
103102
}
@@ -145,33 +144,31 @@ public function checkUserCookie()
145144
{
146145
$tag = __CLASS__ . "-" . __FUNCTION__;
147146

148-
$cookie = isset($_COOKIE['zaly_site_user'] ) ? $_COOKIE['zaly_site_user'] : "";
149-
if(!$cookie) {
147+
$this->sessionId = isset($_COOKIE['zaly_site_user'] ) ? $_COOKIE['zaly_site_user'] : "";
148+
if(!$this->sessionId) {
150149
throw new Exception("cookie is not found");
151150
}
152-
$cookieDecode = base64_decode($cookie);
153151

154-
$this->userId = $this->ctx->ZalyAes->decrypt($cookieDecode, $this->ctx->ZalyAes->cookieKey);
155-
156-
$this->userInfo = $this->ctx->SiteUserTable->getUserByUserId($this->userId);
157-
if (!$this->userInfo) {
158-
throw new Exception("user not exists");
159-
}
160-
161-
$sessionInfo = $this->ctx->SiteSessionTable->getWebUserSessionInfo($this->userId);
162-
$this->ctx->Wpf_Logger->info($tag, json_encode($sessionInfo));
163-
if (!$sessionInfo) {
152+
$this->sessionInfo = $this->ctx->SiteSessionTable->getSessionInfoBySessionId($this->sessionId);
153+
if (!$this->sessionInfo) {
164154
throw new Exception("session is not ok");
165155
}
166-
$timeActive = $sessionInfo['timeActive'];
156+
$timeActive = $this->sessionInfo['timeActive'];
167157

168158
$nowTime = $this->ctx->ZalyHelper->getMsectime();
169159

170160
if (($nowTime - $timeActive) > $this->sessionIdTimeOut) {
171161
throw new Exception("session is not ok");
172162
}
173163

174-
$this->sessionId = $sessionInfo['sessionId'];
164+
$this->userInfo = $this->ctx->SiteUserTable->getUserByUserId($this->sessionInfo['userId']);
165+
if (!$this->userInfo) {
166+
throw new Exception("user is not ok");
167+
}
168+
169+
$this->sessionId = $this->sessionInfo['sessionId'];
170+
$this->userId = $this->userInfo['userId'];
171+
175172
}
176173

177174
public function setLogout()

src/controller/Im/Cts/Im_Cts_UpdatePointerController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public function doRequest(\Google\Protobuf\Internal\Message $request, Zaly\Proto
6565
$currentU2Pointer = $maxU2Pointer;
6666
}
6767
$this->ctx->Wpf_Logger->info("im.cts.updatePointer", "pointer=" . $currentU2Pointer);
68+
69+
//clientSideType=1: 手机客户端 clientSideType=2:web端
6870
$this->ctx->SiteU2MessageTable->updatePointer($userId, $deviceId, "1", $currentU2Pointer);
6971
}
7072
}

src/controller/InstallDBController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class InstallDBController
1111
private $logger;
1212
private $_dbPath = ".";
1313
private $loginPluginIds = [101, 102];
14-
private $passportAccountSafePluginId = 104;
14+
private $passportAccountSafePluginId = 105;
1515
private $configName = "config.php";
1616
private $sampleConfigName = "config.sample.php";
1717
private $_dbName;
@@ -63,14 +63,11 @@ public function doIndex()
6363
$scheme = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : "http";
6464

6565
$siteAddress = $scheme . "://" . $serverHost;
66-
$sessionVerifyUrl = $siteAddress . '/index.php?action=api.session.verify&body_format=pb';
67-
6866
$loginPluginId = $_POST['pluginId'];
6967
$dbNameKey = ZalyHelper::generateStrKey(8);
7068
$sqliteName = "db." . md5($dbNameKey) . ".sqlite3";
7169
$config['sqlite']['sqliteDBName'] = $sqliteName;
7270
$config['loginPluginId'] = in_array($loginPluginId, $this->loginPluginIds) ? $loginPluginId : 101;
73-
$config['session_verify_102'] = $sessionVerifyUrl;
7471
$config['msectime'] = ZalyHelper::getMsectime();
7572
$config['siteAddress'] = $siteAddress;
7673

src/controller/Manage/Manage_CommonController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ protected function preRequest()
2828
}
2929
}
3030

31+
/**
32+
* @param Exception $ex
33+
* @return mixed|void
34+
*/
3135
protected function requestException($ex)
3236
{
37+
echo $ex->getMessage();
3338
$this->showPermissionPage();
3439
}
3540

0 commit comments

Comments
 (0)