diff --git a/Storage/Storage.Test/UserTest.cs b/Storage/Storage.Test/UserTest.cs
index 1cbd89b..f839c47 100644
--- a/Storage/Storage.Test/UserTest.cs
+++ b/Storage/Storage.Test/UserTest.cs
@@ -28,9 +28,47 @@ namespace LeanCloudTests {
}
[Test]
- public async Task Login() {
- AVUser user = await AVUser.LogInAsync("hello", "world");
- TestContext.Out.WriteLine($"{user.ObjectId} login");
+ public async Task LoginWithUsername() {
+ AVUser user = await AVUser.LogInAsync("hello", "111111");
+ TestContext.Out.WriteLine($"{user.ObjectId}, {user.SessionToken} login");
+ }
+
+ [Test]
+ public async Task LoginWithEmail() {
+ AVUser user = await AVUser.LogInByEmailAsync("111111@qq.com", "111111");
+ Assert.AreEqual(user, AVUser.CurrentUser);
+ TestContext.Out.WriteLine($"{AVUser.CurrentUser.SessionToken} login");
+ }
+
+ [Test]
+ public async Task Become() {
+ AVUser user = await AVUser.BecomeAsync("36idbfnt8hlmdo4rki0f5hevq");
+ Assert.AreEqual(user, AVUser.CurrentUser);
+ TestContext.Out.WriteLine($"{AVUser.CurrentUser.SessionToken} login");
+ }
+
+ [Test]
+ public async Task IsAuthenticated() {
+ AVUser user = await AVUser.LogInByEmailAsync("111111@qq.com", "111111");
+ Assert.IsTrue(user.IsCurrent);
+ Assert.AreEqual(user, AVUser.CurrentUser);
+ bool authenticated = await user.IsAuthenticatedAsync();
+ Assert.IsTrue(authenticated);
+ }
+
+ [Test]
+ public async Task RefreshSessionToken() {
+ AVUser user = await AVUser.LogInByEmailAsync("111111@qq.com", "111111");
+ Assert.IsTrue(user.IsCurrent);
+ await user.RefreshSessionTokenAsync();
+ TestContext.Out.WriteLine(user.SessionToken);
+ }
+
+ [Test]
+ public async Task UpdatePassword() {
+ AVUser user = await AVUser.LogInAsync("111111", "111111");
+ await user.UpdatePasswordAsync("111111", "222222");
+ await user.UpdatePasswordAsync("222222", "111111");
}
}
}
diff --git a/Storage/Storage/Internal/Command/AVCommand.cs b/Storage/Storage/Internal/Command/AVCommand.cs
index 5676e2d..085ec6c 100644
--- a/Storage/Storage/Internal/Command/AVCommand.cs
+++ b/Storage/Storage/Internal/Command/AVCommand.cs
@@ -1,17 +1,8 @@
using System;
using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using LeanCloud.Storage.Internal;
-using System.Linq;
using System.Net.Http;
-namespace LeanCloud.Storage.Internal
-{
- ///
- /// AVCommand is an with pre-populated
- /// headers.
- ///
+namespace LeanCloud.Storage.Internal {
public class AVCommand {
// 不同服务对应的服务器地址不同
public virtual string Server => AVClient.CurrentConfiguration.ApiServer;
@@ -25,21 +16,14 @@ namespace LeanCloud.Storage.Internal
}
public Dictionary Headers {
- get {
- if (AVUser.CurrentUser != null) {
- return new Dictionary {
- { "X-LC-Session", AVUser.CurrentUser.SessionToken }
- };
- }
- return null;
- }
+ get; set;
}
public object Content {
get; set;
}
- public Uri Uri {
+ internal Uri Uri {
get {
return new Uri($"{Server}/{AVClient.APIVersion}/{Path}");
}
diff --git a/Storage/Storage/Internal/Command/AVCommandRunner.cs b/Storage/Storage/Internal/Command/AVCommandRunner.cs
index 0a8585a..660d51b 100644
--- a/Storage/Storage/Internal/Command/AVCommandRunner.cs
+++ b/Storage/Storage/Internal/Command/AVCommandRunner.cs
@@ -65,6 +65,10 @@ namespace LeanCloud.Storage.Internal {
request.Headers.Add(header.Key, header.Value);
}
}
+ // Session Token
+ if (AVUser.CurrentUser != null && !string.IsNullOrEmpty(AVUser.CurrentUser.SessionToken)) {
+ request.Headers.Add("X-LC-Session", AVUser.CurrentUser.SessionToken);
+ }
PrintRequest(httpClient, request, content);
var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
diff --git a/Storage/Storage/Internal/File/Controller/AVFileController.cs b/Storage/Storage/Internal/File/Controller/AVFileController.cs
index c76f7d7..1423890 100644
--- a/Storage/Storage/Internal/File/Controller/AVFileController.cs
+++ b/Storage/Storage/Internal/File/Controller/AVFileController.cs
@@ -52,7 +52,6 @@ namespace LeanCloud.Storage.Internal {
}
internal Task>> GetFileToken(FileState fileState, CancellationToken cancellationToken) {
- string currentSessionToken = AVUser.CurrentSessionToken;
string str = fileState.Name;
IDictionary parameters = new Dictionary();
parameters.Add("name", str);
diff --git a/Storage/Storage/Internal/File/Controller/QiniuUploader.cs b/Storage/Storage/Internal/File/Controller/QiniuUploader.cs
index 5a83f79..a64fdee 100644
--- a/Storage/Storage/Internal/File/Controller/QiniuUploader.cs
+++ b/Storage/Storage/Internal/File/Controller/QiniuUploader.cs
@@ -108,7 +108,6 @@ namespace LeanCloud.Storage.Internal {
return key;
}
internal Task>> GetQiniuToken(FileState state, CancellationToken cancellationToken) {
- string currentSessionToken = AVUser.CurrentSessionToken;
string str = state.Name;
IDictionary parameters = new Dictionary();
diff --git a/Storage/Storage/Internal/User/Controller/AVUserController.cs b/Storage/Storage/Internal/User/Controller/AVUserController.cs
index 3c409c6..fa5ae7a 100644
--- a/Storage/Storage/Internal/User/Controller/AVUserController.cs
+++ b/Storage/Storage/Internal/User/Controller/AVUserController.cs
@@ -20,7 +20,7 @@ namespace LeanCloud.Storage.Internal {
return serverState;
}
- public async Task LogInAsync(string username, string email, string password, CancellationToken cancellationToken) {
+ public async Task LogInAsync(string username, string email, string password) {
var data = new Dictionary{
{ "password", password}
};
@@ -35,7 +35,7 @@ namespace LeanCloud.Storage.Internal {
Method = HttpMethod.Post,
Content = data
};
- var ret = await AVPlugins.Instance.CommandRunner.RunCommandAsync>(command, cancellationToken);
+ var ret = await AVPlugins.Instance.CommandRunner.RunCommandAsync>(command);
var serverState = AVObjectCoder.Instance.Decode(ret.Item2, AVDecoder.Instance);
serverState = serverState.MutatedClone(mutableClone => {
mutableClone.IsNew = ret.Item1 == System.Net.HttpStatusCode.Created;
@@ -63,16 +63,19 @@ namespace LeanCloud.Storage.Internal {
return serverState;
}
- public async Task GetUserAsync(string sessionToken, CancellationToken cancellationToken) {
+ public async Task GetUserAsync(string sessionToken) {
var command = new AVCommand {
Path = "users/me",
- Method = HttpMethod.Get
+ Method = HttpMethod.Get,
+ Headers = new Dictionary {
+ { "X-LC-Session", sessionToken }
+ }
};
- var ret = await AVPlugins.Instance.CommandRunner.RunCommandAsync>(command, cancellationToken);
+ var ret = await AVPlugins.Instance.CommandRunner.RunCommandAsync>(command);
return AVObjectCoder.Instance.Decode(ret.Item2, AVDecoder.Instance);
}
- public async Task RequestPasswordResetAsync(string email, CancellationToken cancellationToken) {
+ public async Task RequestPasswordResetAsync(string email) {
var command = new AVCommand {
Path = "requestPasswordReset",
Method = HttpMethod.Post,
@@ -80,16 +83,16 @@ namespace LeanCloud.Storage.Internal {
{ "email", email}
}
};
- await AVPlugins.Instance.CommandRunner.RunCommandAsync>(command, cancellationToken);
+ await AVPlugins.Instance.CommandRunner.RunCommandAsync>(command);
}
- public async Task LogInWithParametersAsync(string relativeUrl, IDictionary data, CancellationToken cancellationToken) {
+ public async Task LogInWithParametersAsync(string relativeUrl, IDictionary data) {
var command = new AVCommand {
Path = relativeUrl,
Method = HttpMethod.Post,
Content = data
};
- var ret = await AVPlugins.Instance.CommandRunner.RunCommandAsync>(command, cancellationToken);
+ var ret = await AVPlugins.Instance.CommandRunner.RunCommandAsync>(command);
var serverState = AVObjectCoder.Instance.Decode(ret.Item2, AVDecoder.Instance);
serverState = serverState.MutatedClone(mutableClone => {
mutableClone.IsNew = ret.Item1 == System.Net.HttpStatusCode.Created;
@@ -97,7 +100,7 @@ namespace LeanCloud.Storage.Internal {
return serverState;
}
- public async Task UpdatePasswordAsync(string userId, string sessionToken, string oldPassword, string newPassword, CancellationToken cancellationToken) {
+ public async Task UpdatePasswordAsync(string userId, string oldPassword, string newPassword) {
var command = new AVCommand {
Path = $"users/{userId}/updatePassword",
Method = HttpMethod.Put,
@@ -106,10 +109,11 @@ namespace LeanCloud.Storage.Internal {
{ "new_password", newPassword },
}
};
- await AVPlugins.Instance.CommandRunner.RunCommandAsync>(command, cancellationToken);
+ var ret = await AVPlugins.Instance.CommandRunner.RunCommandAsync>(command);
+ return AVObjectCoder.Instance.Decode(ret.Item2, AVDecoder.Instance);
}
- public async Task RefreshSessionTokenAsync(string userId, string sessionToken, CancellationToken cancellationToken) {
+ public async Task RefreshSessionTokenAsync(string userId) {
var command = new AVCommand {
Path = $"users/{userId}/refreshSessionToken",
Method = HttpMethod.Put
diff --git a/Storage/Storage/Public/AVFile.cs b/Storage/Storage/Public/AVFile.cs
index e4f06bc..004c49a 100644
--- a/Storage/Storage/Public/AVFile.cs
+++ b/Storage/Storage/Public/AVFile.cs
@@ -337,7 +337,7 @@ namespace LeanCloud
return this.SaveExternal();
return taskQueue.Enqueue(
- toAwait => FileController.SaveAsync(state, dataStream, AVUser.CurrentSessionToken, progress, cancellationToken), cancellationToken)
+ toAwait => FileController.SaveAsync(state, dataStream, AVUser.CurrentUser.SessionToken, progress, cancellationToken), cancellationToken)
.OnSuccess(t =>
{
state = t.Result;
@@ -641,7 +641,7 @@ namespace LeanCloud
///
public static Task GetFileWithObjectIdAsync(string objectId, CancellationToken cancellationToken)
{
- string currentSessionToken = AVUser.CurrentSessionToken;
+ string currentSessionToken = AVUser.CurrentUser.SessionToken;
return FileController.GetAsync(objectId, currentSessionToken, cancellationToken).OnSuccess(_ =>
{
var filestate = _.Result;
@@ -717,7 +717,7 @@ namespace LeanCloud
return Task.FromResult(0);
}
- string sessionToken = AVUser.CurrentSessionToken;
+ string sessionToken = AVUser.CurrentUser.SessionToken;
return toAwait.OnSuccess(_ =>
{
diff --git a/Storage/Storage/Public/AVObject.cs b/Storage/Storage/Public/AVObject.cs
index 12ac035..c2addcb 100644
--- a/Storage/Storage/Public/AVObject.cs
+++ b/Storage/Storage/Public/AVObject.cs
@@ -570,7 +570,7 @@ string propertyName
// Get the JSON representation of the object.
currentOperations = StartSave();
- sessionToken = AVUser.CurrentSessionToken;
+ sessionToken = AVUser.CurrentUser.SessionToken;
deepSaveTask = DeepSaveAsync(estimatedData, sessionToken, cancellationToken);
}
@@ -621,7 +621,7 @@ string propertyName
queryString = new Dictionary();
}
- return ObjectController.FetchAsync(state, queryString, AVUser.CurrentSessionToken, cancellationToken);
+ return ObjectController.FetchAsync(state, queryString, AVUser.CurrentUser.SessionToken, cancellationToken);
}).Unwrap().OnSuccess(t => {
HandleFetchResult(t.Result);
return this;
@@ -709,7 +709,7 @@ string propertyName
/// The cancellation token.
public static Task SaveAllAsync(
IEnumerable objects, CancellationToken cancellationToken) where T : AVObject {
- return DeepSaveAsync(objects.ToList(), AVUser.CurrentSessionToken, cancellationToken);
+ return DeepSaveAsync(objects.ToList(), AVUser.CurrentUser.SessionToken, cancellationToken);
}
#endregion
@@ -856,8 +856,8 @@ string propertyName
if (ObjectId == null) {
return Task.FromResult(0);
}
-
- string sessionToken = AVUser.CurrentSessionToken;
+
+ string sessionToken = AVUser.CurrentUser.SessionToken;
return toAwait.OnSuccess(_ => {
return ObjectController.DeleteAsync(State, sessionToken, cancellationToken);
@@ -902,7 +902,7 @@ string propertyName
var states = uniqueObjects.Select(t => t.state).ToList();
return toAwait.OnSuccess(_ => {
var deleteTasks = ObjectController.DeleteAllAsync(states,
- AVUser.CurrentSessionToken,
+ AVUser.CurrentUser.SessionToken,
cancellationToken);
return Task.WhenAll(deleteTasks);
diff --git a/Storage/Storage/Public/AVUser.cs b/Storage/Storage/Public/AVUser.cs
index c16b94f..5149688 100644
--- a/Storage/Storage/Public/AVUser.cs
+++ b/Storage/Storage/Public/AVUser.cs
@@ -7,17 +7,13 @@ using System.Threading.Tasks;
namespace LeanCloud {
///
- /// Represents a user for a LeanCloud application.
+ /// 用户类
///
[AVClassName("_User")]
public class AVUser : AVObject {
private static readonly IDictionary authProviders =
new Dictionary();
- private static readonly HashSet readOnlyKeys = new HashSet {
- "sessionToken", "isNew"
- };
-
internal static AVUserController UserController {
get {
return AVPlugins.Instance.UserController;
@@ -25,20 +21,8 @@ namespace LeanCloud {
}
///
- /// Whether the AVUser has been authenticated on this device. Only an authenticated
- /// AVUser can be saved and deleted.
+ /// 判断是否是当前用户
///
- [Obsolete("This property is deprecated, please use IsAuthenticatedAsync instead.")]
- public bool IsAuthenticated {
- get {
- lock (mutex) {
- return SessionToken != null &&
- CurrentUser != null &&
- CurrentUser.ObjectId == ObjectId;
- }
- }
- }
-
public bool IsCurrent {
get {
return CurrentUser == this;
@@ -46,34 +30,34 @@ namespace LeanCloud {
}
///
- /// Whether the AVUser has been authenticated on this device, and the AVUser's session token is expired.
- /// Only an authenticated AVUser can be saved and deleted.
+ /// 判断当前用户的 Session Token 是否有效
///
- public Task IsAuthenticatedAsync() {
+ ///
+ public async Task IsAuthenticatedAsync() {
lock (mutex) {
if (SessionToken == null || CurrentUser == null || CurrentUser.ObjectId != ObjectId) {
- return Task.FromResult(false);
+ return false;
}
}
var command = new AVCommand {
- Path = $"users/me?session_token={CurrentSessionToken}",
+ Path = $"users/me?session_token={SessionToken}",
Method = HttpMethod.Get
};
- return AVPlugins.Instance.CommandRunner.RunCommandAsync>(command);
+ await AVPlugins.Instance.CommandRunner.RunCommandAsync>(command);
+ return true;
}
///
- /// Refresh this user's session token, and current session token will be invalid.
+ /// 刷新用户的 Session Token,刷新后 Session Token 将会改变
///
- public Task RefreshSessionTokenAsync(CancellationToken cancellationToken) {
- return UserController.RefreshSessionTokenAsync(ObjectId, SessionToken, cancellationToken).OnSuccess(t => {
- var serverState = t.Result;
- HandleSave(serverState);
- });
+ ///
+ public async Task RefreshSessionTokenAsync() {
+ var serverState = await UserController.RefreshSessionTokenAsync(ObjectId);
+ HandleSave(serverState);
}
///
- /// authenticated token.
+ /// 获取 Session Token
///
public string SessionToken {
get {
@@ -84,53 +68,47 @@ namespace LeanCloud {
}
}
- internal static string CurrentSessionToken {
- get {
- return CurrentUser?.SessionToken;
- }
- }
-
- internal void SetSessionTokenAsync(string newSessionToken) {
- SetSessionTokenAsync(newSessionToken, CancellationToken.None);
- }
-
- internal void SetSessionTokenAsync(string newSessionToken, CancellationToken cancellationToken) {
- MutateState(mutableClone => {
- mutableClone.ServerData["sessionToken"] = newSessionToken;
- });
-
- CurrentUser = this;
- }
-
///
- /// Gets or sets the username.
+ /// 用户名
///
[AVFieldName("username")]
public string Username {
- get { return GetProperty(null, "Username"); }
- set { SetProperty(value, "Username"); }
+ get {
+ return GetProperty(null, "Username");
+ }
+ set {
+ SetProperty(value, "Username");
+ }
}
///
- /// Sets the password.
+ /// 密码
///
[AVFieldName("password")]
public string Password {
- private get { return GetProperty(null, "Password"); }
- set { SetProperty(value, "Password"); }
+ private get {
+ return GetProperty(null, "Password");
+ }
+ set {
+ SetProperty(value, "Password");
+ }
}
///
- /// Sets the email address.
+ /// Email
///
[AVFieldName("email")]
public string Email {
- get { return GetProperty(null, "Email"); }
- set { SetProperty(value, "Email"); }
+ get {
+ return GetProperty(null, "Email");
+ }
+ set {
+ SetProperty(value, "Email");
+ }
}
///
- /// 用户手机号。
+ /// 手机号。
///
[AVFieldName("mobilePhoneNumber")]
public string MobilePhoneNumber {
@@ -138,21 +116,21 @@ namespace LeanCloud {
return GetProperty(null, "MobilePhoneNumber");
}
set {
- SetProperty(value, "MobilePhoneNumber");
+ SetProperty(value, "MobilePhoneNumber");
}
}
///
- /// 用户手机号是否已经验证
+ /// 手机号是否已经验证
///
/// true if mobile phone verified; otherwise, false.
[AVFieldName("mobilePhoneVerified")]
public bool MobilePhoneVerified {
get {
- return GetProperty(false, "MobilePhoneVerified");
+ return GetProperty(false, "MobilePhoneVerified");
}
set {
- SetProperty(value, "MobilePhoneVerified");
+ SetProperty(value, "MobilePhoneVerified");
}
}
@@ -161,11 +139,7 @@ namespace LeanCloud {
///
public bool IsAnonymous {
get {
- bool rtn = false;
- if (this.AuthData != null) {
- rtn = this.AuthData.Keys.Contains("anonymous");
- }
- return rtn;
+ return AuthData != null && AuthData.Keys.Contains("anonymous");
}
}
@@ -285,68 +259,38 @@ namespace LeanCloud {
return GetFolloweeQuery().FindAsync(CancellationToken.None);
}
-
- //public Task SendStatusAsync()
- //{
-
- //}
-
#endregion
///
- /// Logs in a user with a username and password. On success, this saves the session to disk so you
- /// can retrieve the currently logged in user using .
+ /// 使用用户名和密码登陆。登陆成功后,将用户设置为当前用户
///
- /// The username to log in with.
- /// The password to log in with.
- /// The newly logged-in user.
- public static Task LogInAsync(string username, string password) {
- return LogInAsync(username, password, CancellationToken.None);
- }
-
- public static async Task LogInAsync(string username, string password, CancellationToken cancellationToken) {
- var ret = await UserController.LogInAsync(username, null, password, cancellationToken);
+ /// 用户名
+ /// 密码
+ ///
+ public static async Task LogInAsync(string username, string password) {
+ var ret = await UserController.LogInAsync(username, null, password);
AVUser user = FromState(ret, "_User");
CurrentUser = user;
return user;
}
///
- /// Logs in a user with a username and password. On success, this saves the session to disk so you
- /// can retrieve the currently logged in user using .
+ /// 使用 Session Token 登录。
///
- /// The session token to authorize with
- /// The user if authorization was successful
- public static Task BecomeAsync(string sessionToken) {
- return BecomeAsync(sessionToken, CancellationToken.None);
- }
-
- ///
- /// Logs in a user with a username and password. On success, this saves the session to disk so you
- /// can retrieve the currently logged in user using .
- ///
- /// The session token to authorize with
- /// The cancellation token.
- /// The user if authorization was successful
- public static async Task BecomeAsync(string sessionToken, CancellationToken cancellationToken) {
- var ret = await UserController.GetUserAsync(sessionToken, cancellationToken);
+ /// Session Token
+ ///
+ public static async Task BecomeAsync(string sessionToken) {
+ var ret = await UserController.GetUserAsync(sessionToken);
AVUser user = FromState(ret, "_User");
CurrentUser = user;
return user;
}
///
- /// Logs out the currently logged in user session. This will remove the session from disk, log out of
- /// linked services, and future calls to will return null.
+ /// 用户登出
///
- ///
- /// Typically, you should use , unless you are managing your own threading.
- ///
public static void LogOut() {
CurrentUser = null;
-
- // TODO (hallucinogen): this will without a doubt fail in Unity. But what else can we do?
- //LogOutAsync().Wait();
}
private static void LogOutWithProviders() {
@@ -355,13 +299,16 @@ namespace LeanCloud {
}
}
+ ///
+ /// 获取当前用户
+ ///
public static AVUser CurrentUser {
get;
internal set;
}
///
- /// Constructs a for AVUsers.
+ /// 创建一个 AVUser 查询对象
///
public static AVQuery Query {
get {
@@ -370,34 +317,23 @@ namespace LeanCloud {
}
///
- /// Requests a password reset email to be sent to the specified email address associated with the
- /// user account. This email allows the user to securely reset their password on the LeanCloud site.
+ /// 通过绑定的邮箱请求重置密码
+ /// 邮件可以在 LeanCloud 站点安全的重置密码
///
- /// The email address associated with the user that forgot their password.
+ /// 绑定的邮箱地址
+ ///
public static Task RequestPasswordResetAsync(string email) {
- return RequestPasswordResetAsync(email, CancellationToken.None);
+ return UserController.RequestPasswordResetAsync(email);
}
///
- /// Requests a password reset email to be sent to the specified email address associated with the
- /// user account. This email allows the user to securely reset their password on the LeanCloud site.
+ /// 更新用户的密码,需要用户的旧密码
///
- /// The email address associated with the user that forgot their password.
- /// The cancellation token.
- public static Task RequestPasswordResetAsync(string email,
- CancellationToken cancellationToken) {
- return UserController.RequestPasswordResetAsync(email, cancellationToken);
- }
-
- ///
- /// Updates current user's password. Need the user's old password,
- ///
- /// The password.
/// Old password.
/// New password.
- /// Cancellation token.
- public Task UpdatePassword(string oldPassword, string newPassword, CancellationToken cancellationToken) {
- return UserController.UpdatePasswordAsync(ObjectId, SessionToken, oldPassword, newPassword, cancellationToken);
+ public async Task UpdatePasswordAsync(string oldPassword, string newPassword) {
+ IObjectState state = await UserController.UpdatePasswordAsync(ObjectId, oldPassword, newPassword);
+ HandleFetchResult(state);
}
///
@@ -545,42 +481,22 @@ namespace LeanCloud {
#region 手机号登录
- internal static async Task LogInWithParametersAsync(Dictionary strs, CancellationToken cancellationToken) {
- var ret = await UserController.LogInWithParametersAsync("login", strs, cancellationToken);
+ internal static async Task LogInWithParametersAsync(Dictionary strs) {
+ var ret = await UserController.LogInWithParametersAsync("login", strs);
var user = CreateWithoutData(null);
user.HandleFetchResult(ret);
CurrentUser = user;
return CurrentUser;
}
- ///
- /// 以手机号和密码实现登陆。
- ///
- /// 手机号
- /// 密码
- ///
- public static Task LogInByMobilePhoneNumberAsync(string mobilePhoneNumber, string password) {
- return AVUser.LogInByMobilePhoneNumberAsync(mobilePhoneNumber, password, CancellationToken.None);
- }
-
- ///
- /// 以手机号和验证码匹配登陆
- ///
- /// 手机号
- /// 短信验证码
- ///
- public static Task LogInBySmsCodeAsync(string mobilePhoneNumber, string smsCode) {
- return AVUser.LogInBySmsCodeAsync(mobilePhoneNumber, smsCode, CancellationToken.None);
- }
-
///
/// 用邮箱作和密码匹配登录
///
/// 邮箱
/// 密码
///
- public static async Task LogInByEmailAsync(string email, string password, CancellationToken cancellationToken = default(CancellationToken)) {
- var ret = await UserController.LogInAsync(null, email, password, cancellationToken);
+ public static async Task LogInByEmailAsync(string email, string password) {
+ var ret = await UserController.LogInAsync(null, email, password);
AVUser user = FromState(ret, "_User");
CurrentUser = user;
return CurrentUser;
@@ -588,35 +504,31 @@ namespace LeanCloud {
///
- /// 以手机号和密码匹配登陆
+ /// 用手机号和密码匹配登陆
///
/// 手机号
/// 密码
- ///
///
- public static Task LogInByMobilePhoneNumberAsync(string mobilePhoneNumber, string password, CancellationToken cancellationToken) {
- Dictionary strs = new Dictionary()
- {
+ public static Task LogInByMobilePhoneNumberAsync(string mobilePhoneNumber, string password) {
+ Dictionary strs = new Dictionary {
{ "mobilePhoneNumber", mobilePhoneNumber },
{ "password", password }
};
- return AVUser.LogInWithParametersAsync(strs, cancellationToken);
+ return LogInWithParametersAsync(strs);
}
///
- /// 以手机号和验证码登陆
+ /// 用手机号和验证码登陆
///
/// 手机号
/// 短信验证码
- ///
///
- public static Task LogInBySmsCodeAsync(string mobilePhoneNumber, string smsCode, CancellationToken cancellationToken = default(CancellationToken)) {
- Dictionary strs = new Dictionary()
- {
+ public static Task LogInBySmsCodeAsync(string mobilePhoneNumber, string smsCode) {
+ Dictionary strs = new Dictionary {
{ "mobilePhoneNumber", mobilePhoneNumber },
{ "smsCode", smsCode }
};
- return AVUser.LogInWithParametersAsync(strs, cancellationToken);
+ return LogInWithParametersAsync(strs);
}
///
@@ -672,34 +584,27 @@ namespace LeanCloud {
}
///
- /// 手机号一键登录
+ /// 手机号注册和登录
///
/// 手机号
/// 短信验证码
///
- public static async Task SignUpOrLogInByMobilePhoneAsync(string mobilePhoneNumber, string smsCode, CancellationToken cancellationToken) {
+ public static async Task SignUpOrLogInByMobilePhoneAsync(string mobilePhoneNumber, string smsCode) {
Dictionary strs = new Dictionary {
{ "mobilePhoneNumber", mobilePhoneNumber },
{ "smsCode", smsCode }
};
- var ret = await UserController.LogInWithParametersAsync("usersByMobilePhone", strs, cancellationToken);
+ var ret = await UserController.LogInWithParametersAsync("usersByMobilePhone", strs);
var user = CreateWithoutData(null);
user.HandleFetchResult(ret);
CurrentUser = user;
return CurrentUser;
}
- ///
- /// 手机号一键登录
- ///
- /// signup or login by mobile phone async.
- /// 手机号
- /// 短信验证码
- public static Task SignUpOrLogInByMobilePhoneAsync(string mobilePhoneNumber, string smsCode) {
- return AVUser.SignUpOrLogInByMobilePhoneAsync(mobilePhoneNumber, smsCode, CancellationToken.None);
- }
+ #endregion
+
+ #region 手机短信
- #region mobile sms shortcode sign up & log in.
///
/// Send sign up sms code async.
///
@@ -716,7 +621,7 @@ namespace LeanCloud {
/// Mobile phone number.
/// Sms code.
public static Task SignUpByMobilePhoneAsync(string mobilePhoneNumber, string smsCode) {
- return AVUser.SignUpOrLogInByMobilePhoneAsync(mobilePhoneNumber, smsCode);
+ return SignUpOrLogInByMobilePhoneAsync(mobilePhoneNumber, smsCode);
}
///
@@ -725,7 +630,7 @@ namespace LeanCloud {
/// The log in sms code async.
/// Mobile phone number.
public static Task SendLogInSmsCodeAsync(string mobilePhoneNumber) {
- return AVUser.RequestLogInSmsCodeAsync(mobilePhoneNumber);
+ return RequestLogInSmsCodeAsync(mobilePhoneNumber);
}
///
@@ -735,14 +640,15 @@ namespace LeanCloud {
/// Mobile phone number.
/// Sms code.
public static Task LogInByMobilePhoneAsync(string mobilePhoneNumber, string smsCode) {
- return AVUser.LogInBySmsCodeAsync(mobilePhoneNumber, smsCode);
+ return LogInBySmsCodeAsync(mobilePhoneNumber, smsCode);
}
- #endregion
+
#endregion
#region 重置密码
+
///
- /// 请求重置密码,需要传入注册时使用的手机号。
+ /// 请求重置密码,需要传入注册时使用的手机号。
///
/// 注册时使用的手机号
///
@@ -751,7 +657,7 @@ namespace LeanCloud {
}
///
- /// 请求重置密码,需要传入注册时使用的手机号。
+ /// 请求重置密码,需要传入注册时使用的手机号。
///
/// 注册时使用的手机号
/// cancellationToken
@@ -761,7 +667,7 @@ namespace LeanCloud {
}
///
- /// 请求重置密码,需要传入注册时使用的手机号。
+ /// 请求重置密码,需要传入注册时使用的手机号。
///
/// 注册时使用的手机号
/// Validate token.
@@ -771,7 +677,7 @@ namespace LeanCloud {
}
///
- /// 请求重置密码,需要传入注册时使用的手机号。
+ /// 请求重置密码,需要传入注册时使用的手机号。
///
/// 注册时使用的手机号
/// Validate token.
@@ -822,42 +728,12 @@ namespace LeanCloud {
}
///
- /// 发送认证码到需要认证的手机上
+ /// 发送验证码到用户绑定的手机上
///
/// 手机号
+ /// 验证码
///
- public static Task RequestMobilePhoneVerifyAsync(string mobilePhoneNumber) {
- return RequestMobilePhoneVerifyAsync(mobilePhoneNumber, null, CancellationToken.None);
- }
-
- ///
- /// 发送认证码到需要认证的手机上
- ///
- /// 手机号
- /// Validate token.
- ///
- public static Task RequestMobilePhoneVerifyAsync(string mobilePhoneNumber, string validateToken) {
- return RequestMobilePhoneVerifyAsync(mobilePhoneNumber, validateToken, CancellationToken.None);
- }
-
- ///
- /// 发送认证码到需要认证的手机上
- ///
- /// 手机号
- /// CancellationToken
- ///
- public static Task RequestMobilePhoneVerifyAsync(string mobilePhoneNumber, CancellationToken cancellationToken) {
- return RequestMobilePhoneVerifyAsync(mobilePhoneNumber, null, cancellationToken);
- }
-
- ///
- /// 发送认证码到需要认证的手机上
- ///
- /// 手机号
- /// Validate token.
- /// CancellationToken
- ///
- public static Task RequestMobilePhoneVerifyAsync(string mobilePhoneNumber, string validateToken, CancellationToken cancellationToken) {
+ public static Task RequestMobilePhoneVerifyAsync(string mobilePhoneNumber, string validateToken = null) {
Dictionary strs = new Dictionary {
{ "mobilePhoneNumber", mobilePhoneNumber }
};
@@ -872,31 +748,6 @@ namespace LeanCloud {
return AVPlugins.Instance.CommandRunner.RunCommandAsync>(command);
}
- ///
- /// 验证手机验证码是否为有效值
- ///
- /// 手机收到的验证码
- /// 手机号
- ///
- public static Task VerifyMobilePhoneAsync(string code, string mobilePhoneNumber) {
- return VerifyMobilePhoneAsync(code, mobilePhoneNumber, CancellationToken.None);
- }
-
- ///
- /// 验证手机验证码是否为有效值
- ///
- /// 手机收到的验证码
- /// 手机号,可选
- ///
- ///
- public static Task VerifyMobilePhoneAsync(string code, string mobilePhoneNumber, CancellationToken cancellationToken) {
- var command = new AVCommand {
- Path = $"verifyMobilePhone/{code.Trim()}?mobilePhoneNumber={mobilePhoneNumber.Trim()}",
- Method = HttpMethod.Post
- };
- return AVPlugins.Instance.CommandRunner.RunCommandAsync>(command);
- }
-
///
/// 验证手机验证码是否为有效值
///
@@ -910,19 +761,10 @@ namespace LeanCloud {
return AVPlugins.Instance.CommandRunner.RunCommandAsync>(command);
}
- ///
- /// 验证手机验证码是否为有效值
- ///
- /// 手机收到的验证码
- /// cancellationToken
- ///
- public static Task VerifyMobilePhoneAsync(string code, CancellationToken cancellationToken) {
- return AVUser.VerifyMobilePhoneAsync(code, CancellationToken.None);
- }
-
#endregion
#region 邮箱验证
+
///
/// 申请发送验证邮箱的邮件,一周之内有效
/// 如果该邮箱已经验证通过,会直接返回 True,并不会真正发送邮件
@@ -931,8 +773,7 @@ namespace LeanCloud {
/// 邮箱地址
///
public static Task RequestEmailVerifyAsync(string email) {
- Dictionary strs = new Dictionary()
- {
+ Dictionary strs = new Dictionary {
{ "email", email }
};
var command = new AVCommand {
@@ -942,6 +783,7 @@ namespace LeanCloud {
};
return AVPlugins.Instance.CommandRunner.RunCommandAsync>(command);
}
+
#endregion
#region in no-local-storage enviroment
@@ -988,9 +830,11 @@ namespace LeanCloud {
return t;
}).Unwrap();
}
+
#endregion
#region AVUser Extension
+
public IDictionary> GetAuthData() {
return AuthData;
}
@@ -1009,7 +853,7 @@ namespace LeanCloud {
if (options == null) {
options = new AVUserAuthDataLogInOption();
}
- return AVUser.LogInWithAsync(platform, data, options.FailOnNotExist, cancellationToken);
+ return LogInWithAsync(platform, data, options.FailOnNotExist, cancellationToken);
}
public static Task LogInWithAuthDataAndUnionIdAsync(
@@ -1022,7 +866,7 @@ namespace LeanCloud {
options = new AVUserAuthDataLogInOption();
}
MergeAuthData(authData, unionId, options);
- return AVUser.LogInWithAsync(platform, authData, options.FailOnNotExist, cancellationToken);
+ return LogInWithAsync(platform, authData, options.FailOnNotExist, cancellationToken);
}
public static Task LogInAnonymouslyAsync(CancellationToken cancellationToken = default(System.Threading.CancellationToken)) {
@@ -1035,13 +879,12 @@ namespace LeanCloud {
[Obsolete("please use LogInWithAuthDataAsync instead.")]
public static Task LogInWithAsync(string authType, IDictionary data, CancellationToken cancellationToken) {
- return AVUser.LogInWithAsync(authType, data, false, cancellationToken);
+ return LogInWithAsync(authType, data, false, cancellationToken);
}
///
/// link a 3rd auth account to the user.
///
- /// AVUser instance
/// OAuth data, like {"accessToken":"xxxxxx"}
/// auth platform,maybe "facebook"/"twiiter"/"weibo"/"weixin" .etc
///
@@ -1066,7 +909,6 @@ namespace LeanCloud {
///
/// unlink a 3rd auth account from the user.
///
- /// AVUser instance
/// auth platform,maybe "facebook"/"twiiter"/"weibo"/"weixin" .etc
///
///
@@ -1080,6 +922,7 @@ namespace LeanCloud {
authData["main_account"] = options.AsMainAccount;
authData["unionid"] = unionId;
}
+
#endregion
}
}