public async Task UserReadAndWrite() { await LCUser.Login("hello", "world"); LCObject account = new LCObject("Account"); LCUser currentUser = await LCUser.GetCurrent(); LCACL acl = LCACL.CreateWithOwner(currentUser); account.ACL = acl; account["balance"] = 512; await account.Save(); Assert.IsTrue(acl.GetUserReadAccess(currentUser)); Assert.IsTrue(acl.GetUserWriteAccess(currentUser)); LCQuery <LCObject> query = new LCQuery <LCObject>("Account"); LCObject result = await query.Get(account.ObjectId); TestContext.WriteLine(result.ObjectId); Assert.NotNull(result.ObjectId); await LCUser.Logout(); result = await query.Get(account.ObjectId); Assert.IsNull(result); }
public async Task RoleReadAndWrite() { LCUser currentUser = await LCUser.Login(TestPhone, TestPhone); string name = $"role_{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}"; LCACL roleACL = new LCACL(); roleACL.SetUserReadAccess(currentUser, true); roleACL.SetUserWriteAccess(currentUser, true); LCRole role = LCRole.Create(name, roleACL); role.AddRelation("users", currentUser); await role.Save(); account = new Account(); LCACL acl = new LCACL(); acl.SetRoleReadAccess(role, true); acl.SetRoleWriteAccess(role, true); account.ACL = acl; await account.Save(); Assert.IsTrue(acl.GetRoleReadAccess(role)); Assert.IsTrue(acl.GetRoleWriteAccess(role)); }
public async Task UserReadAndWrite() { await LCUser.Login(TestPhone, TestPhone); account = new Account(); LCUser currentUser = await LCUser.GetCurrent(); account.ACL = LCACL.CreateWithOwner(currentUser); account.Balance = 512; await account.Save(); Assert.IsTrue(account.ACL.GetUserReadAccess(currentUser)); Assert.IsTrue(account.ACL.GetUserWriteAccess(currentUser)); LCQuery <LCObject> query = new LCQuery <LCObject>("Account"); LCObject result = await query.Get(account.ObjectId); TestContext.WriteLine(result.ObjectId); Assert.NotNull(result.ObjectId); await LCUser.Logout(); try { await query.Get(account.ObjectId); } catch (LCException e) { Assert.AreEqual(e.Code, 403); } }
public async Task UpdatePassword() { LCUser currentUser = await LCUser.Login("hello", "world"); await currentUser.UpdatePassword("world", "newWorld"); await currentUser.UpdatePassword("newWorld", "world"); }
public async Task IsAuthenticated() { LCUser currentUser = await LCUser.Login("hello", "world"); bool isAuthenticated = await currentUser.IsAuthenticated(); TestContext.WriteLine(isAuthenticated); Assert.IsTrue(isAuthenticated); }
public async Task Query() { await LCUser.Login("game", "play"); LCQuery <LCObject> query = new LCQuery <LCObject>("Account"); LCObject account = await query.Get("5e144525dd3c13006a8f8de2"); TestContext.WriteLine(account.ObjectId); Assert.NotNull(account.ObjectId); }
public async Task Query() { await LCUser.Login(TestPhone, TestPhone); LCQuery <LCObject> query = new LCQuery <LCObject>("Account"); Account queryAccount = (await query.Get(account.ObjectId)) as Account; TestContext.WriteLine(queryAccount.ObjectId); Assert.NotNull(queryAccount.ObjectId); }
public async Task Login() { await LCUser.Login("hello", "world"); LCUser current = await LCUser.GetCurrent(); Assert.NotNull(current.ObjectId); Assert.IsFalse(current.EmailVerified); Assert.IsFalse(current.MobileVerified); Assert.AreEqual(current.Mobile, "15101006008"); }
public async Task AssociateAuthDataWithUnionId() { LCUser currentUser = await LCUser.Login("hello", "world"); string uuid = Guid.NewGuid().ToString(); Dictionary <string, object> authData = new Dictionary <string, object> { { "expires_in", 7200 }, { "openid", uuid }, { "access_token", uuid } }; string unionId = Guid.NewGuid().ToString(); await currentUser.AssociateAuthDataAndUnionId(authData, "qq", unionId); }
public async Task <LCUser> Login(string username, string password) { try { User = await LCUser.Login(username, password); IMClient = new LCIMClient(User); await IMClient.Open(); return(User); } catch (LCException e) { LCUtils.LogException(e); throw e; } }
public async Task GetStatistics() { int today = DateTimeOffset.Now.DayOfYear; string username = $"{today}_0"; string password = "******"; LCUser user = await LCUser.Login(username, password); ReadOnlyCollection <LCStatistic> statistics = await LCLeaderboard.GetStatistics(user); foreach (LCStatistic statistic in statistics) { WriteLine($"{statistic.Name} : {statistic.Value}"); } }
public async Task NewRole() { LCUser currentUser = await LCUser.Login("game", "play"); LCACL acl = new LCACL(); acl.PublicReadAccess = true; acl.SetUserWriteAccess(currentUser, true); string name = $"role_{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}"; LCRole role = LCRole.Create(name, acl); role.AddRelation("users", currentUser); await role.Save(); }
public async Task AssociateAuthData() { string uuid = Guid.NewGuid().ToString(); LCUser currentUser = await LCUser.Login("hello", "world"); Dictionary <string, object> authData = new Dictionary <string, object> { { "expires_in", 7200 }, { "openid", uuid }, { "access_token", uuid } }; await currentUser.AssociateAuthData(authData, "weixin"); TestContext.WriteLine(currentUser.AuthData); TestContext.WriteLine(currentUser.AuthData["weixin"]); }
public async Task GetResultsOfMe() { int today = DateTimeOffset.Now.DayOfYear; string username = $"{today}_0"; string password = "******"; await LCUser.Login(username, password); LCLeaderboard leaderboard = LCLeaderboard.CreateWithoutData(leaderboardName); ReadOnlyCollection <LCRanking> rankings = await leaderboard.GetResultsAroundUser(limit : 5); foreach (LCRanking ranking in rankings) { WriteLine($"{ranking.Rank} : {ranking.User.ObjectId}, {ranking.Value}"); } }
public async Task OpenAndCloseByLCUser() { LCUser user = await LCUser.Login(USERNAME1, PASSWORD1); LCIMClient client = new LCIMClient(user); await client.Open(); LCUser game = await LCUser.Login(USERNAME2, PASSWORD2); LCIMClient client2 = new LCIMClient(game); await client2.Open(); await client.Close(); await client2.Close(); }
public async Task Serialization() { await LCUser.Login("hello", "world"); LCQuery <LCObject> query = new LCQuery <LCObject>("Account") { IncludeACL = true }; query.OrderByDescending("createdAt"); ReadOnlyCollection <LCObject> accounts = await query.Find(); foreach (LCObject account in accounts) { TestContext.WriteLine($"public read access: {account.ACL.PublicReadAccess}"); TestContext.WriteLine($"public write access: {account.ACL.PublicWriteAccess}"); } }
private async Task NewUser(string username, string password) { try { await LCUser.Login(username, password); } catch (LCException e) { if (e.Code == 211) { LCUser user1 = new LCUser { Username = username, Password = password }; await user1.SignUp(); } else { throw e; } } }
public async Task ObjectWithFile() { LCUser user = await LCUser.Login("hello", "world"); ObjectWithFile obj = new ObjectWithFile() { File = new LCFile("avatar", "../../../../../assets/hello.png"), Owner = user }; await obj.Save(); LCQuery <ObjectWithFile> query = new LCQuery <ObjectWithFile>("ObjectWithFile"); ObjectWithFile obj2 = await query.Get(obj.ObjectId); TestContext.WriteLine(obj2.File.Url); TestContext.WriteLine(obj2.Owner.ObjectId); Assert.IsNotNull(obj2.File.Url); Assert.IsNotNull(obj2.Owner.ObjectId); }
static void Main(string[] args) { WriteLine("Hello World!"); SingleThreadSynchronizationContext.Run(async() => { LCLogger.LogDelegate += Print; LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com"); await LCUser.Login("hello", "world"); LCQuery <LCUser> userQuery = LCUser.GetQuery(); userQuery.WhereEqualTo("username", "hello"); LCLiveQuery userLiveQuery = await userQuery.Subscribe(); userLiveQuery.OnLogin = (user) => { WriteLine($"login: {user.Username}"); }; LCQuery <LCObject> query = new LCQuery <LCObject>("Account"); query.WhereGreaterThan("balance", 100); LCLiveQuery liveQuery = await query.Subscribe(); liveQuery.OnCreate = (obj) => { WriteLine($"create: {obj}"); }; liveQuery.OnUpdate = (obj, keys) => { WriteLine($"update: {obj}"); WriteLine(keys.Count); }; liveQuery.OnDelete = (objId) => { WriteLine($"delete: {objId}"); }; liveQuery.OnEnter = (obj, keys) => { WriteLine($"enter: {obj}"); WriteLine(keys.Count); }; liveQuery.OnLeave = (obj, keys) => { WriteLine($"leave: {obj}"); WriteLine(keys.Count); }; }); }
public async Task Update() { for (int i = 0; i < 10; i++) { int today = DateTimeOffset.Now.DayOfYear; string username = $"{today}_{i}"; string password = "******"; LCUser user; try { user = await LCUser.Login(username, password); } catch (Exception) { user = new LCUser { Username = username, Password = password }; await user.SignUp(); } await LCLeaderboard.UpdateStatistics(user, new Dictionary <string, double> { { leaderboardName, i * 10 } }); } }
public async Task Login() { TaskCompletionSource <object> tcs = new TaskCompletionSource <object>(); await LCUser.Login("hello", "world"); LCQuery <LCUser> userQuery = LCUser.GetQuery(); userQuery.WhereEqualTo("username", "hello"); LCLiveQuery userLiveQuery = await userQuery.Subscribe(); userLiveQuery.OnLogin = (user) => { WriteLine($"login: {user}"); tcs.SetResult(null); }; // 模拟 REST API string url = "https://ikggdre2.lc-cn-n1-shared.com/1.1/login"; HttpRequestMessage request = new HttpRequestMessage { RequestUri = new Uri(url), Method = HttpMethod.Post }; request.Headers.Add("X-LC-Id", "ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz"); request.Headers.Add("X-LC-Key", "NUKmuRbdAhg1vrb2wexYo1jo"); string content = JsonConvert.SerializeObject(new Dictionary <string, object> { { "username", "hello" }, { "password", "world" } }); StringContent requestContent = new StringContent(content); requestContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); request.Content = requestContent; HttpClient client = new HttpClient(); await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); await tcs.Task; }
async Task Login() { await LCUser.Login("hello", "world"); }
public async Task DisassociateAuthData() { LCUser currentUser = await LCUser.Login("hello", "world"); await currentUser.DisassociateWithAuthData("weixin"); }