Skip to content

Commit

Permalink
Merge pull request #214 from weakish/changePhoneNumber
Browse files Browse the repository at this point in the history
feat(User): requestChangePhoneNumber & changePhoneNumber
  • Loading branch information
weakish authored Jul 15, 2020
2 parents 750ccf7 + 8440ad3 commit 1b665d1
Show file tree
Hide file tree
Showing 11 changed files with 897 additions and 692 deletions.
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

0.13.0 Released on 2020-07-15
----

- Add `requestChangePhoneNumber` & `changePhoneNumber` to *verify* mobile number before updating it.
- Add `_messageUpdate` hook.
- Add `setApiTimeout` to specify request timeout.

0.12.0 发布日期:2020-04-21
----

Expand Down
10 changes: 9 additions & 1 deletion Hacking.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@
make test_engine &
make test
```

Run one single test:

```sh
vendor/bin/phpunit --filter testInitializeWithString test/QueryTest.php
```

* `make doc` to build documentation (should running on PHP < 7.2)
* `make doc` to build documentation.
The make task uses PHP 5.6, to install it on recent versions of macOS,
see https://github.com/eXolnet/homebrew-deprecated/pull/25

* Send a pull request at leancloud/php-sdk

Expand Down
89 changes: 63 additions & 26 deletions docs/class-LeanCloud.Client.html

Large diffs are not rendered by default.

88 changes: 82 additions & 6 deletions docs/class-LeanCloud.User.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ <h1>Class User</h1>
<b>Namespace:</b> <a href="namespace-LeanCloud.html">LeanCloud</a><br>


<b>Located at</b> <a href="source-class-LeanCloud.User.html#9-568" title="Go to source code">LeanCloud/User.php</a>
<b>Located at</b> <a href="source-class-LeanCloud.User.html#9-593" title="Go to source code">LeanCloud/User.php</a>
<br>
</div>

Expand Down Expand Up @@ -1368,7 +1368,42 @@ <h4>Parameters</h4>
</div>
</div></td>
</tr>
<tr data-order="signUpOrLoginByMobilePhone" id="_signUpOrLoginByMobilePhone">
<tr data-order="requestChangePhoneNumber" id="_requestChangePhoneNumber">

<td class="attributes"><code>
public static



</code>
</td>

<td class="name"><div>
<a class="anchor" href="#_requestChangePhoneNumber">#</a>
<code><a href="source-class-LeanCloud.User.html#470-479" title="Go to source code">requestChangePhoneNumber</a>( <span>string <var>$phoneNumber</var></span> )</code>

<div class="description short">
<p>Request mobile phone verify before updating it.</p>
</div>

<div class="description detailed hidden">
<p>Request mobile phone verify before updating it.</p>


<h4>Parameters</h4>
<div class="list"><dl>
<dt><var>$phoneNumber</var></dt>
<dd></dd>
</dl></div>





</div>
</div></td>
</tr>
<tr data-order="changePhoneNumber" id="_changePhoneNumber">

<td class="attributes"><code>
public static
Expand All @@ -1378,9 +1413,46 @@ <h4>Parameters</h4>
</code>
</td>

<td class="name"><div>
<a class="anchor" href="#_changePhoneNumber">#</a>
<code><a href="source-class-LeanCloud.User.html#481-492" title="Go to source code">changePhoneNumber</a>( <span>string <var>$smsCode</var></span>, <span>string <var>$phoneNumber</var></span> )</code>

<div class="description short">
<p>Update mobile phone number by SMS code.</p>
</div>

<div class="description detailed hidden">
<p>Update mobile phone number by SMS code.</p>


<h4>Parameters</h4>
<div class="list"><dl>
<dt><var>$smsCode</var></dt>
<dd></dd>
<dt><var>$phoneNumber</var></dt>
<dd></dd>
</dl></div>





</div>
</div></td>
</tr>
<tr data-order="signUpOrLoginByMobilePhone" id="_signUpOrLoginByMobilePhone">

<td class="attributes"><code>
public static

<code><a href="class-LeanCloud.User.html">LeanCloud\User</a></code>

</code>
</td>

<td class="name"><div>
<a class="anchor" href="#_signUpOrLoginByMobilePhone">#</a>
<code><a href="source-class-LeanCloud.User.html#470-485" title="Go to source code">signUpOrLoginByMobilePhone</a>( <span>string <var>$phoneNumber</var></span>, <span>string <var>$smsCode</var></span> )</code>
<code><a href="source-class-LeanCloud.User.html#494-510" title="Go to source code">signUpOrLoginByMobilePhone</a>( <span>string <var>$phoneNumber</var></span>, <span>string <var>$smsCode</var></span> )</code>

<div class="description short">
<p>Sign up user by mobile phone and SMS code</p>
Expand All @@ -1398,6 +1470,10 @@ <h4>Parameters</h4>
<dd></dd>
</dl></div>

<h4>Returns</h4>
<div class="list">
<code><a href="class-LeanCloud.User.html">LeanCloud\User</a></code>
</div>



Expand All @@ -1417,7 +1493,7 @@ <h4>Parameters</h4>

<td class="name"><div>
<a class="anchor" href="#_logInWith">#</a>
<code><a href="source-class-LeanCloud.User.html#502-519" title="Go to source code">logInWith</a>( <span>string <var>$provider</var></span>, <span>array <var>$authToken</var></span> )</code>
<code><a href="source-class-LeanCloud.User.html#527-544" title="Go to source code">logInWith</a>( <span>string <var>$provider</var></span>, <span>array <var>$authToken</var></span> )</code>

<div class="description short">
<p>Log-in with 3rd party auth data</p>
Expand Down Expand Up @@ -1463,7 +1539,7 @@ <h4>Returns</h4>

<td class="name"><div>
<a class="anchor" href="#_linkWith">#</a>
<code><a href="source-class-LeanCloud.User.html#521-542" title="Go to source code">linkWith</a>( <span>string <var>$provider</var></span>, <span>array <var>$authToken</var></span> )</code>
<code><a href="source-class-LeanCloud.User.html#546-567" title="Go to source code">linkWith</a>( <span>string <var>$provider</var></span>, <span>array <var>$authToken</var></span> )</code>

<div class="description short">
<p>Link user with 3rd party provider</p>
Expand Down Expand Up @@ -1504,7 +1580,7 @@ <h4>Returns</h4>

<td class="name"><div>
<a class="anchor" href="#_unlinkWith">#</a>
<code><a href="source-class-LeanCloud.User.html#544-566" title="Go to source code">unlinkWith</a>( <span>string <var>$provider</var></span> )</code>
<code><a href="source-class-LeanCloud.User.html#569-591" title="Go to source code">unlinkWith</a>( <span>string <var>$provider</var></span> )</code>

<div class="description short">
<p>Unlink user with a provider</p>
Expand Down
1,127 changes: 569 additions & 558 deletions docs/source-class-LeanCloud.Client.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/source-class-LeanCloud.Engine.LeanEngine.html
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ <h3>Exceptions</h3>
</span><span id="427" class="l"> <span class="php-keyword1">private</span> <span class="php-keyword1">function</span> dispatchFunc(<span class="php-var">$funcName</span>, <span class="php-var">$body</span>, <span class="php-var">$decodeObj</span>=<span class="php-keyword1">false</span>) {
</span><span id="428" class="l"> <span class="php-comment">// verify hook sign for RTM hooks</span>
</span><span id="429" class="l"> <span class="php-keyword1">if</span> (<span class="php-keyword2">in_array</span>(<span class="php-var">$funcName</span>, <span class="php-keyword1">array</span>(
</span><span id="430" class="l"> <span class="php-quote">'_messageReceived'</span>, <span class="php-quote">'_receiversOffline'</span>, <span class="php-quote">'_messageSent'</span>,
</span><span id="430" class="l"> <span class="php-quote">'_messageReceived'</span>, <span class="php-quote">'_receiversOffline'</span>, <span class="php-quote">'_messageSent'</span>, <span class="php-quote">'_messageUpdate'</span>,
</span><span id="431" class="l"> <span class="php-quote">'_conversationStart'</span>, <span class="php-quote">'_conversationStarted'</span>,
</span><span id="432" class="l"> <span class="php-quote">'_conversationAdd'</span>, <span class="php-quote">'_conversationAdded'</span>, <span class="php-quote">'_conversationRemove'</span>, <span class="php-quote">'_conversationRemoved'</span>, <span class="php-quote">'_conversationUpdate'</span>,
</span><span id="433" class="l"> <span class="php-quote">'_clientOnline'</span>, <span class="php-quote">'_clientOffline'</span>, <span class="php-quote">'_rtmClientSign'</span>
Expand Down
221 changes: 123 additions & 98 deletions docs/source-class-LeanCloud.User.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version="$1"

#### Build new changelog
echo "" >> Changelog.md.0
echo "$version 发布日期:`date +%Y-%m-%d`" >> Changelog.md.0
echo "$version Released on `date +%Y-%m-%d`" >> Changelog.md.0
echo "----" >> Changelog.md.0
git log `git describe --tags --abbrev=0`..HEAD --pretty=%s >> Changelog.md.0

Expand Down
2 changes: 1 addition & 1 deletion src/LeanCloud/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Client {
/**
* Client version
*/
const VERSION = '0.12.0';
const VERSION = '0.13.0';

/**
* API Version string
Expand Down
25 changes: 25 additions & 0 deletions src/LeanCloud/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,36 @@ public static function verifyMobilePhone($smsCode) {
Client::post("/verifyMobilePhone/{$smsCode}", null);
}

/**
* Request mobile phone verify before updating it.
*
* @param string $phoneNumber
*/
public static function requestChangePhoneNumber($phoneNumber) {
Client::post("/requestChangePhoneNumber", array(
"mobilePhoneNumber" => $phoneNumber
));
}

/**
* Update mobile phone number by SMS code.
*
* @param string $smsCode
* @param string $phoneNumber
*/
public static function changePhoneNumber($smsCode, $phoneNumber) {
Client::post("/changePhoneNumber", array(
"mobilePhoneNumber" => $phoneNumber,
"code" => $smsCode
));
}

/**
* Sign up user by mobile phone and SMS code
*
* @param string $phoneNumber
* @param string $smsCode
* @return User
*/
public static function signUpOrLoginByMobilePhone($phoneNumber, $smsCode) {
$resp = Client::post("/usersByMobilePhone", array(
Expand Down
16 changes: 16 additions & 0 deletions test/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ public function testSignUpOrLoginByMobilePhone() {
User::signUpOrLoginByMobilePhone("18612340000", "000000");
}

public function testRequestChangePhoneNumber() {
$this->setExpectedException("LeanCloud\CloudException", null, 600);
// Remember to create this user before hand.
User::logIn("php_test_change_phone_number", "blabla");
// phone number is from https://www.yinsiduanxin.com
User::requestChangePhoneNumber("+8616533875941");
}

public function testChangePhoneNumber() {
$this->setExpectedException("LeanCloud\CloudException", null, 603);
User::changePhoneNumber("992989", "+8616533875941");
// Uncomment the follow lines when manually running the test.
// $user = User::logIn("php_test_change_phone_number", "blabla");
// $this->assertEquals("+8616533875941", $user->getMobilePhoneNumber());
}

public function testLogInWithLinkedService() {
$user = User::logIn("alice", "blabla");

Expand Down

0 comments on commit 1b665d1

Please sign in to comment.