Skip to content

Commit 0d57423

Browse files
committed
User#loginAnonymously use installation id to identify current device
1 parent 796457e commit 0d57423

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

core/src/main/java/cn/leancloud/LCUser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public static Observable<? extends LCUser> logIn(String username, String passwor
328328
* @return observable instance.
329329
*/
330330
public static Observable<? extends LCUser> logInAnonymously() {
331-
String anonymousId = UUID.randomUUID().toString().toLowerCase();
331+
String anonymousId = LCInstallation.getCurrentInstallation().getInstallationId();
332332
Map<String, Object> param = new HashMap<>();
333333
param.put("id", anonymousId);
334334
return loginWithAuthData(param, AUTHDATA_PLATFORM_ANONYMOUS);

core/src/test/java/cn/leancloud/LCUserTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ protected void tearDown() throws Exception {
3939
;
4040
}
4141

42+
public void testBunchAnonymousLogin() throws Exception {
43+
LCUser user1 = LCUser.logInAnonymously().blockingFirst();
44+
String anonymousUserId = user1.objectId;
45+
user1.logOut();
46+
for (int i = 0; i < 10; i++) {
47+
user1 = LCUser.logInAnonymously().blockingFirst();
48+
assertEquals(anonymousUserId, user1.objectId);
49+
user1.logOut();
50+
Thread.sleep(200);
51+
}
52+
}
53+
4254
public void testSingupWithEmail() throws Exception {
4355
LCUser user = new LCUser();
4456
user.setEmail(EMAIL);

0 commit comments

Comments
 (0)