Initial Commit ...
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Extensions;
|
||||
using xHttpService.Constants;
|
||||
using xIdentityModels.Dtos;
|
||||
using xIdentityModels.Models;
|
||||
using xIdentityService.Constants;
|
||||
|
||||
namespace xIdentityService.Providers {
|
||||
public partial class XIdentityProvider {
|
||||
//
|
||||
#region Admin ...
|
||||
/// <summary>
|
||||
/// Ban Specific Users
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="model">an instance of <see>XUserNameIdRequest</see> which represents user identifier list to Ban</param>
|
||||
/// <returns>a list of banned users identifiers</returns>
|
||||
public async Task<IEnumerable<string>> Ban (
|
||||
XTokenResponse tokens,
|
||||
XUserNameIdRequest model
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (
|
||||
tokens,
|
||||
model
|
||||
)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.AddNotZeroChilds (model.Ids)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.Ban);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<IEnumerable<string>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UnBann Specific Users
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="model">an instance of <see>XUserNameIdRequest</see> which represents user identifier list to Ban</param>
|
||||
/// <returns>a list of unbanned users identifiers</returns>
|
||||
public async Task<IEnumerable<string>> UnBan (
|
||||
XTokenResponse tokens,
|
||||
XUserNameIdRequest model
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (
|
||||
tokens,
|
||||
model
|
||||
)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.AddNotZeroChilds (model.Ids)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.UnBan);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<IEnumerable<string>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Specific User is Banned or not
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="userSelectByParam">specified user's identifier</param>
|
||||
/// <returns>a boolean value which represent user banned or not</returns>
|
||||
public async Task<bool> IsBanned (
|
||||
XTokenResponse tokens,
|
||||
string userSelectByParam
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
userSelectByParam,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.IsBanned,
|
||||
@params : new Dictionary<string, string> { { XParam.XUserSelectByParam.GetStringValue (), userSelectByParam } }
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<bool> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using IdentityModel.Client;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xHttpService.Constants;
|
||||
using xIdentityModels.Extensions;
|
||||
using xIdentityModels.Models;
|
||||
using xIdentityService.Constants;
|
||||
|
||||
namespace xIdentityService.Providers {
|
||||
public partial class XIdentityProvider {
|
||||
//
|
||||
#region Authentication Handlers ...
|
||||
/// <summary>
|
||||
/// Request for Discovery Document
|
||||
/// </summary>
|
||||
/// <returns>an instance of DiscoveryDocumentResponse</returns>
|
||||
public async Task<DiscoveryDocumentResponse> RequestDiscoveryDocument () {
|
||||
//
|
||||
var httpClient = GetHttpClient ();
|
||||
|
||||
//
|
||||
try {
|
||||
//
|
||||
var result = httpClient
|
||||
.GetDiscoveryDocumentAsync (identityConfiguration.Authority)
|
||||
.ContinueWith (docTask => {
|
||||
//
|
||||
httpClient.Dispose ();
|
||||
return docTask.Result;
|
||||
});
|
||||
|
||||
//
|
||||
return await result;
|
||||
} catch {
|
||||
throw XException.ActionFailed.ToException ();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request AccessToken for Specific XApiScope
|
||||
/// </summary>
|
||||
/// <param name="scope">a member of <see>XApiScope</see></param>
|
||||
/// <returns>an instance of <see>XTokenResponse</see></returns>
|
||||
public async Task<XTokenResponse> RequestScopeAccessToken (string scope) {
|
||||
//
|
||||
// Validate Args ...
|
||||
var scopeName = string.Empty;
|
||||
try {
|
||||
scopeName = scope; // scope.GetStringValue ();
|
||||
} catch { }
|
||||
if (scopeName.IsNullOrEmpty ()) {
|
||||
XException.InvalidArgs.Throw ();
|
||||
}
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.RequestScopeAccessToken,
|
||||
headers : new Dictionary<string, string> { { XParam.XScope.GetStringValue (), scope.ToString () } });
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XTokenResponse> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
|
||||
//
|
||||
// Save Token ...
|
||||
if (!response.IsNull ()) {
|
||||
await tokenProvider.AddOrUpdateToken (response);
|
||||
}
|
||||
|
||||
//
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a token
|
||||
/// </summary>
|
||||
/// <param name="model">Authentication Tokens</param>
|
||||
/// <returns>an instance of TokenIntrospectionResponse</returns>
|
||||
public async Task<TokenIntrospectionResponse> Introspection (XTokenResponse model) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (model)
|
||||
.AddNotEmpty (model.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var httpClient = GetHttpClient ();
|
||||
|
||||
//
|
||||
try {
|
||||
//
|
||||
var discoDoc = await RequestDiscoveryDocument ();
|
||||
if (discoDoc.IsError) {
|
||||
XException.ActionFailed.Throw ();
|
||||
}
|
||||
|
||||
//
|
||||
var response = await httpClient.IntrospectTokenAsync (new TokenIntrospectionRequest {
|
||||
//
|
||||
Address = discoDoc.IntrospectionEndpoint,
|
||||
ClientId = identityConfiguration.ClientId,
|
||||
ClientSecret = identityConfiguration.ClientSecret,
|
||||
|
||||
//
|
||||
Token = model.AccessToken
|
||||
});
|
||||
if (response.IsError) {
|
||||
throw new Exception (response.Error);
|
||||
}
|
||||
|
||||
//
|
||||
return response;
|
||||
} catch {
|
||||
throw XException.ActionFailed.ToException ();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Authenticate a User
|
||||
/// </summary>
|
||||
/// <param name="model">User Login Required Info, an instance of <see>XLoginRequest</see></param>
|
||||
/// <returns>an instance of <see>XTokenResponse</see></returns>
|
||||
public async Task<XTokenResponse> Authenticate (XLoginRequest model) {
|
||||
//
|
||||
// Validate Args ...
|
||||
validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (model)
|
||||
.AddNotEmpty (
|
||||
model.UserSelectBy,
|
||||
model.Password
|
||||
)
|
||||
.ValidateGroup ();
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
var request = GetRestRequet (XApiAccountEndpoint.Authenticate);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XTokenResponse> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
|
||||
//
|
||||
// Save Token ...
|
||||
if (!response.IsNull ()) {
|
||||
await tokenProvider.AddOrUpdateToken (response);
|
||||
}
|
||||
|
||||
//
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do Login based on XLoginRequest
|
||||
/// </summary>
|
||||
/// <param name="model">User Login Required Info, an instance of <see>XLoginRequest</see></param>
|
||||
/// <returns>an instance of <see>XTokenResponse</see></returns>
|
||||
public async Task<XLoginResponse> Login (XLoginRequest model) {
|
||||
//
|
||||
// Validate Args ...
|
||||
validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (model, model.Device)
|
||||
.AddNotEmpty (
|
||||
model.UserSelectBy,
|
||||
model.Password
|
||||
)
|
||||
.ValidateGroup ();
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
var request = GetRestRequet (XApiAccountEndpoint.Login);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XLoginResponse> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
|
||||
//
|
||||
if (!response.IsNull ()) {
|
||||
//
|
||||
var tokens = response.ToXTokenResponse ();
|
||||
await tokenProvider.AddOrUpdateToken (tokens);
|
||||
}
|
||||
|
||||
//
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logout from System
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Logout (XTokenResponse model) {
|
||||
//
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (model)
|
||||
.AddNotEmpty (model.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var isExists = await tokenProvider
|
||||
.IsTokenExists (model.AccessToken);
|
||||
if (isExists) {
|
||||
await tokenProvider
|
||||
.RemoveToken (model.AccessToken);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refresh Tokens
|
||||
/// </summary>
|
||||
/// <param name="model">Authentication Tokens</param>
|
||||
/// <returns>an instance of <see>XTokenResponse</see></returns>
|
||||
public async Task<XTokenResponse> RefreshTokens (XTokenResponse model) {
|
||||
//
|
||||
// Validate Args ...
|
||||
validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (model)
|
||||
.AddNotEmpty (
|
||||
model.AccessToken,
|
||||
model.RefreshToken
|
||||
)
|
||||
.ValidateGroup ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (model);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.RefreshTokens,
|
||||
headers : model.ToHeaderDictionary ());
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XTokenResponse> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
if (!response.IsNull ()) {
|
||||
await tokenProvider.UpdateToken (response);
|
||||
}
|
||||
|
||||
//
|
||||
return response;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Password Actions Handlers ...
|
||||
/// <summary>
|
||||
/// Change Password
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
||||
/// <returns></returns>
|
||||
public async Task ChangePassword (
|
||||
XTokenResponse tokens,
|
||||
XActionRequest model
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens, model)
|
||||
.AddNotEmpty (
|
||||
model.Lang,
|
||||
model.Password,
|
||||
model.NewPassword,
|
||||
model.ReturnUrl)
|
||||
.AddNotNull (model.Device)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
// Validate User Select By Param ...
|
||||
var userSelectByParam = GetUserSelectByParam (
|
||||
model,
|
||||
forceNotNull : true,
|
||||
excludes : null);
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.ChangePassword,
|
||||
headers : tokens.ToHeaderDictionary ());
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<Object> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,803 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Extensions;
|
||||
using xHttpService.Constants;
|
||||
using xIdentityModels.Constants;
|
||||
using xIdentityModels.Dtos;
|
||||
using xIdentityModels.Models;
|
||||
using xIdentityModels.Navigations;
|
||||
using xIdentityService.Constants;
|
||||
|
||||
namespace xIdentityService.Providers {
|
||||
public partial class XIdentityProvider {
|
||||
//
|
||||
#region Friendship ...
|
||||
/// <summary>
|
||||
/// Follow a User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns>an instance of <see>XFriendshipFollowing</see></returns>
|
||||
public async Task<XFriendshipFollowing> Follow (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.Follow,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XFriendshipFollowing> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancel Following Request
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns>a boolean value</returns>
|
||||
public async Task<bool> Cancel (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.Cancel,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<bool> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unfollow a Follower
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns></returns>
|
||||
public async Task UnFollowFollower (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.UnFollowFollower,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<object> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unfollow Following
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns></returns>
|
||||
public async Task UnFollowFollowing (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.UnFollowFollowing,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<object> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Block a Follower
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns>an instance of <see>XFriendshipFollowing</see></returns>
|
||||
public async Task<XFriendshipFollowing> Block (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.Block,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XFriendshipFollowing> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unblock a Blocked User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns>an instance of <see>XFriendshipFollowing</see></returns>
|
||||
public async Task<XFriendshipFollowing> UnBlock (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.UnBlock,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XFriendshipFollowing> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Accept a Following Request
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns>an instance of <see>XFriendshipFollower</see></returns>
|
||||
public async Task<XFriendshipFollower> AcceptRequest (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.AcceptRequest,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XFriendshipFollower> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reject a Following Request
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns>an instance of <see>XFriendshipFollower</see></returns>
|
||||
public async Task<XFriendshipFollower> RejectRequest (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.RejectRequest,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XFriendshipFollower> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check a User IsFollower of Requested User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns>a boolean value</returns>
|
||||
public async Task<bool> IsFollower (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.IsFollower,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<bool> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Specific Follower
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns>an instance of <see>XFriendshipFollower</see></returns>
|
||||
public async Task<XFriendshipFollower> GetFollower (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.Follower,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XFriendshipFollower> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Follower State of a User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns>an instance of <see>XFriendshipState</see></returns>
|
||||
public async Task<XFriendshipState> GetFollowerState (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.FollowerState,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XFriendshipState> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Followers List Of Current User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <returns>a collection of <see>XFriendshipFollower</see></returns>
|
||||
public async Task<IEnumerable<XFriendshipFollower>> GetFollowers (
|
||||
XTokenResponse tokens
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.Followers);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<IEnumerable<XFriendshipFollower>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get All Followers List Includes Blocked, Requested and etc
|
||||
/// of Current User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <returns>a collection of <see>XFriendshipFollower</see></returns>
|
||||
public async Task<IEnumerable<XFriendshipFollower>> GetAllFollowers (
|
||||
XTokenResponse tokens
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.AllFollowers);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<IEnumerable<XFriendshipFollower>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check a User is in Followings of Current User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns>a boolean value</returns>
|
||||
public async Task<bool> IsFollowing (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.IsFollowing,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<bool> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Specific Following Model
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns>an instance of <see>XFriendshipFollowing</see></returns>
|
||||
public async Task<XFriendshipFollowing> GetFollowing (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.Following,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XFriendshipFollowing> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Following State Relation between Specific User
|
||||
/// and Current User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns>an instance of <see>XFriendshipState</see></returns>
|
||||
public async Task<XFriendshipState> GetFollowingState (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.FollowingState,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XFriendshipState> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Followings of Current User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <returns>a collection of <see>XFriendshipFollowing</see></returns>
|
||||
public async Task<IEnumerable<XFriendshipFollowing>> GetFollowings (
|
||||
XTokenResponse tokens
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.Followings);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<IEnumerable<XFriendshipFollowing>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get All Following List Includes Blocked, Requested and etc
|
||||
/// of Current User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <returns>a collection of <see>XFriendshipFollowing</see></returns>
|
||||
public async Task<IEnumerable<XFriendshipFollowing>> GetAllFollowings (
|
||||
XTokenResponse tokens
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.AllFollowings);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<IEnumerable<XFriendshipFollowing>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return Following UserName's List of Current User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <returns>a collection of UserNames</returns>
|
||||
public async Task<IEnumerable<string>> GetFollowingList (
|
||||
XTokenResponse tokens
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.FollowingsList);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<IEnumerable<string>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return Followers UserName's List of Current User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <returns>a collection of UserNames</returns>
|
||||
public async Task<IEnumerable<string>> GetFollowersList (
|
||||
XTokenResponse tokens
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.FollowersList);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<IEnumerable<string>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Friendship Info Model between Specific User and Current User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="destUser">a user identifier which represent destination user</param>
|
||||
/// <returns>an instance of <see>XFriendshipInfoDto</see></returns>
|
||||
public async Task<XFriendshipInfoDto> GetFriendshipInfo (
|
||||
XTokenResponse tokens,
|
||||
string destUser
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
destUser,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.FriendshipInfo,
|
||||
@params : new Dictionary<string, string> { { XParam.XDestUser.GetStringValue (), destUser }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XFriendshipInfoDto> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,496 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using xCommons.Extensions;
|
||||
using xHttpService.Constants;
|
||||
using xHttpService.Extensions;
|
||||
using xIdentityModels.Dtos;
|
||||
using xIdentityModels.Models;
|
||||
using xIdentityModels.Navigations;
|
||||
using xIdentityService.Constants;
|
||||
using xModels.Dtos;
|
||||
|
||||
namespace xIdentityService.Providers {
|
||||
public partial class XIdentityProvider {
|
||||
//
|
||||
#region User Actions ...
|
||||
/// <summary>
|
||||
/// Retrieve User Names based on UserIds
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="ids">a comma seperated list of UserIds</param>
|
||||
/// <returns>a collection of UserNames</returns>
|
||||
public async Task<IEnumerable<string>> GetUserNames (
|
||||
XTokenResponse tokens,
|
||||
string ids
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (ids, tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.GetNames,
|
||||
@params : new Dictionary<string, string> { { XParam.XIds.GetStringValue (), ids } }
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<IEnumerable<string>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get user ids and retrieve corresponding user names
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="model">an instance of <see>XUserNameIdRequest</see> which represent required UserIds collection</param>
|
||||
/// <returns>a collection of <see>XUserNameIdResponse</see> instance</returns>
|
||||
public async Task<IEnumerable<XUserNameIdResponse>> GetUserNameIds (
|
||||
XTokenResponse tokens,
|
||||
XUserNameIdRequest model
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (model, tokens)
|
||||
.AddNotZeroChilds (model.Ids)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
var request = GetRestRequet (XApiAccountEndpoint.GetNameIds);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<IEnumerable<XUserNameIdResponse>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Profile Actions ...
|
||||
/// <summary>
|
||||
/// Get Profile Object of Specific User
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="userSelectByParam">determine's which user profile must be retrieved</param>
|
||||
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
||||
public async Task<XUserProfileDto> GetUserProfile (
|
||||
XTokenResponse tokens,
|
||||
string userSelectByParam
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (userSelectByParam, tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.GetProfile,
|
||||
@params : new Dictionary<string, string> { { XParam.XUserSelectByParam.GetStringValue (), userSelectByParam } }
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XUserProfileDto> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Users Based On Query
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="query">how to filter results based on <see>XQuery</see> structure</param>
|
||||
/// <returns>an instance of <see>XQueryResult</see> of <see>XUserProfileDto</see></returns>
|
||||
public async Task<XQueryResult<XUserProfileDto>> QueryUsers (
|
||||
XTokenResponse tokens,
|
||||
XQuery query
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens, query)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.QueryProfiles);
|
||||
|
||||
//
|
||||
// Attach XQuery to Request ...
|
||||
request = request.AttachXQuery (query);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XQueryResult<XUserProfileDto>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Users Based On Query and Specified role
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="role">an string which represent user role</param>
|
||||
/// <param name="query">how to filter results based on <see>XQuery</see> structure</param>
|
||||
/// <param name="forceRole">if it's true the user must has exact role, otherwise top level users also listed</param>
|
||||
/// <returns>an instance of <see>XQueryResult</see> of <see>XUserProfileDto</see></returns>
|
||||
public async Task<XQueryResult<XUserProfileDto>> QueryInRoleUsers (
|
||||
XTokenResponse tokens,
|
||||
string role,
|
||||
XQuery query,
|
||||
bool forceRole = false
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens, query)
|
||||
.AddNotEmpty (tokens.AccessToken, role)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.QueryProfiles,
|
||||
headers : new Dictionary<string, string> { { XParam.XRole.GetStringValue (), role },
|
||||
{ XParam.XForceRole.GetStringValue (), forceRole.AsHttpParamString () }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
// Attach XQuery to Request ...
|
||||
request = request.AttachXQuery (query);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XQueryResult<XUserProfileDto>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query Specified User's Profile Images
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="userSelectByParam">determine's which user profile must be retrieved</param>
|
||||
/// <param name="query">how to filter results based on <see>XQuery</see> structure</param>
|
||||
/// <returns>an instance of <see>XQueryResult</see> of <see>XProfileImage</see></returns>
|
||||
public async Task<XQueryResult<XProfileImage>> QueryAvatars (
|
||||
XTokenResponse tokens,
|
||||
string userSelectByParam,
|
||||
XQuery query
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens, query)
|
||||
.AddNotEmpty (tokens.AccessToken, userSelectByParam)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.QueryAvatars,
|
||||
@params : new Dictionary<string, string> { { XParam.XUserSelectByParam.GetStringValue (), userSelectByParam }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
// Attach XQuery to Request ...
|
||||
request = request.AttachXQuery (query);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XQueryResult<XProfileImage>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update User Profile based on <see>XProfileUpdateRequest</see> (FirstName/LastName/DateOfBirth)
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="userSelectByParam">determine's which user profile must be retrieved</param>
|
||||
/// <param name="model">user update info, an instance of <see>XProfileUpdateRequest</see></param>
|
||||
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
||||
public async Task<XUserProfileDto> ProfileUpdateAsync (
|
||||
XTokenResponse tokens,
|
||||
string userSelectByParam,
|
||||
XProfileUpdateRequest model
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens, model)
|
||||
.AddNotEmpty (tokens.AccessToken, userSelectByParam)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.UpdateProfile,
|
||||
@params : new Dictionary<string, string> { { XParam.XUserSelectByParam.GetStringValue (), userSelectByParam }
|
||||
}
|
||||
);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XUserProfileDto> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update a User Profile based on <see>XProfileUpdateRequest</see> Full
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="userSelectByParam">determine's which user profile must be retrieved</param>
|
||||
/// <param name="model">user update info, an instance of <see>XProfileUpdateRequest</see></param>
|
||||
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
||||
public async Task<XUserProfileDto> FullProfileUpdateAsync (
|
||||
XTokenResponse tokens,
|
||||
string userSelectByParam,
|
||||
XProfileUpdateRequest model
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens, model)
|
||||
.AddNotEmpty (tokens.AccessToken, userSelectByParam)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.FullUpdateProfile,
|
||||
@params : new Dictionary<string, string> { { XParam.XUserSelectByParam.GetStringValue (), userSelectByParam }
|
||||
}
|
||||
);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XUserProfileDto> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a New Profile Image
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="file">an specific File to upload, <see>IFormFile</see></param>
|
||||
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
||||
public async Task<XUserProfileDto> AddAvatar (
|
||||
XTokenResponse tokens,
|
||||
IFormFile file
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens, file)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.AddAvatar);
|
||||
request.AlwaysMultipartFormData = true;
|
||||
request.AddFileBytes (
|
||||
XParam.XFile.GetStringValue (),
|
||||
file.ToByteArray (),
|
||||
file.FileName,
|
||||
file.ContentType
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XUserProfileDto> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a New Collection of Profile Images
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="files">a collection of Files to upload, <see>IFormFileCollection</see></param>
|
||||
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
||||
public async Task<XUserProfileDto> AddAvatars (
|
||||
XTokenResponse tokens,
|
||||
IFormFileCollection files
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotZeroChilds (files)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.AddAvatars);
|
||||
request.AlwaysMultipartFormData = true;
|
||||
|
||||
//
|
||||
// Add Files ...
|
||||
foreach (var file in files) {
|
||||
//
|
||||
// Add Single file ...
|
||||
request.AddFileBytes (
|
||||
XParam.XFiles.GetStringValue (),
|
||||
file.ToByteArray (),
|
||||
file.FileName,
|
||||
file.ContentType
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XUserProfileDto> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// set Specified Profile Image as Avatar
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="id">an integer which reperesent AvatarId to set as current Avatar</param>
|
||||
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
||||
public async Task<XUserProfileDto> SetAvatar (
|
||||
XTokenResponse tokens,
|
||||
int id
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
id.ValidateIntId ();
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.SetAvatar,
|
||||
@params : new Dictionary<string, string> { { XParam.XId.GetStringValue (), id.ToString () }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XUserProfileDto> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Profile Images
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="avatarIds">a comma seperated list of avatarIds to remove</param>
|
||||
/// <returns>an instance of <see>XUserProfileDto</see></returns>
|
||||
public async Task<XUserProfileDto> RemoveAvatars (
|
||||
XTokenResponse tokens,
|
||||
string avatarIds
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (avatarIds, tokens.AccessToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.RemoveAvatars,
|
||||
@params : new Dictionary<string, string> { { XParam.XIds.GetStringValue (), avatarIds }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XUserProfileDto> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.DELETE
|
||||
);
|
||||
return response;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,653 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xHttpService.Constants;
|
||||
using xIdentityModels.Constants;
|
||||
using xIdentityModels.Extensions;
|
||||
using xIdentityModels.Models;
|
||||
using xIdentityService.Constants;
|
||||
|
||||
namespace xIdentityService.Providers {
|
||||
public partial class XIdentityProvider {
|
||||
//
|
||||
#region Registration ...
|
||||
/// <summary>
|
||||
/// Check a User Selector is Available for Registration or Not
|
||||
/// </summary>
|
||||
/// <param name="userSelectByParam">an string value which reperesent a user</param>
|
||||
/// <returns>a boolean value</returns>
|
||||
public async Task<bool> CanRegister (string userSelectByParam) {
|
||||
//
|
||||
// Validate ARgs ...
|
||||
validationProvider.NotEmpty (userSelectByParam);
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
|
||||
//
|
||||
// Check Endpoint ...
|
||||
var endpoint = XApiAccountEndpoint.CanRegisterUserName;
|
||||
var @params = new Dictionary<string, string> { { XParam.XUserName.GetStringValue (), userSelectByParam } };
|
||||
|
||||
//
|
||||
// Check UserSelectByType ...
|
||||
var type = userSelectByParam.GetUserSelectByType ();
|
||||
switch (type) {
|
||||
//
|
||||
case XUserSelectBy.Username:
|
||||
break;
|
||||
|
||||
//
|
||||
case XUserSelectBy.MobileNumber:
|
||||
//
|
||||
endpoint = XApiAccountEndpoint.CanRegisterMobileNumber;
|
||||
@params = new Dictionary<string, string> { { XParam.XMobileNumber.GetStringValue (), userSelectByParam } };
|
||||
break;
|
||||
|
||||
//
|
||||
case XUserSelectBy.Email:
|
||||
//
|
||||
endpoint = XApiAccountEndpoint.CanRegisterEmail;
|
||||
@params = new Dictionary<string, string> { { XParam.XEmail.GetStringValue (), userSelectByParam } };
|
||||
break;
|
||||
|
||||
//
|
||||
default:
|
||||
throw XException.InvalidData.ToException ();
|
||||
}
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
endpoint,
|
||||
@params: @params
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<bool> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invite a User to Register on Dashboard
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
||||
/// <returns>an instance of <see>XActionResponse</see></returns>
|
||||
public async Task<XActionResponse> InviteUser (
|
||||
XTokenResponse tokens,
|
||||
XActionRequest model
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (
|
||||
tokens,
|
||||
model,
|
||||
model.Device)
|
||||
.AddNotEmpty (
|
||||
tokens.AccessToken,
|
||||
model.Lang,
|
||||
model.Email,
|
||||
model.ReturnUrl)
|
||||
.AddEmailAddress (model.Email)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.InviteUser);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XActionResponse> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recieve some Basic Informations and Start Registration Proccess
|
||||
/// if they Valid
|
||||
///
|
||||
/// Registration Proccess Starts with Invoking this Action
|
||||
/// </summary>
|
||||
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
||||
/// <returns>an instance of <see>XActionResponse</see></returns>
|
||||
public async Task<XActionResponse> RequestRegistration (
|
||||
XActionRequest model
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (
|
||||
model,
|
||||
model.Device,
|
||||
model.DateOfBirth)
|
||||
.AddNotEmpty (
|
||||
model.Lang,
|
||||
model.FirstName,
|
||||
model.LastName)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.RequestRegistration);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XActionResponse> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add User Account Informations
|
||||
/// </summary>
|
||||
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
||||
/// <returns>an instance of <see>XActionResponse</see></returns>
|
||||
public async Task<XActionResponse> AddAccountInfo (
|
||||
XActionRequest model
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (
|
||||
model,
|
||||
model.Device)
|
||||
.AddNotEmpty (
|
||||
model.Lang,
|
||||
model.UserName,
|
||||
model.Password,
|
||||
model.ActionToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.AddAccountInfo);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XActionResponse> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upload and Attach a Profile Image for User. this is an Optional Step
|
||||
/// </summary>
|
||||
/// <param name="actionToken">user's requested action token</param>
|
||||
/// <param name="file">an instance of <see>IFormFile</see> for user's Avatar</param>
|
||||
/// <returns>an instance of <see>XActionResponse</see></returns>
|
||||
public async Task<XActionResponse> AttachProfileImage (
|
||||
string actionToken,
|
||||
IFormFile file
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (file)
|
||||
.AddNotEmpty (actionToken)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.AttachProfileImage);
|
||||
|
||||
//
|
||||
// Prepare Request Data ...
|
||||
request.AddParameter (XParam.XActionToken.GetStringValue (), actionToken);
|
||||
request.AddFileBytes (
|
||||
XParam.XFile.GetStringValue (),
|
||||
file.ToByteArray (),
|
||||
file.FileName,
|
||||
file.ContentType
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XActionResponse> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finish Registrationn Proccess
|
||||
/// </summary>
|
||||
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
||||
/// <returns></returns>
|
||||
public async Task FinishRegistration (XActionRequest model) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotEmpty (
|
||||
model.Lang,
|
||||
model.Password,
|
||||
model.ReturnUrl)
|
||||
.AddNotNull (model.Device)
|
||||
.AddUrl (model.ReturnUrl)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
// Create Http Client ...
|
||||
var client = GetRestClient ();
|
||||
|
||||
//
|
||||
// Create Request ...
|
||||
var request = GetRestRequet (XApiAccountEndpoint.FinishRegistration);
|
||||
|
||||
//
|
||||
// Prepare Request Data ...
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<object> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check User is Confirmed Email or not
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="userSelectByParam">an string value which reperesent a user</param>
|
||||
/// <returns>a boolean value</returns>
|
||||
public async Task<bool> IsConfirmedEmail (
|
||||
XTokenResponse tokens,
|
||||
string userSelectByParam
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
tokens.AccessToken,
|
||||
userSelectByParam)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.IsConfirmedEmail);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<bool> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check User is Confirmed Mobile or not
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="userSelectByParam">an string value which reperesent a user</param>
|
||||
/// <returns>a boolean value</returns>
|
||||
public async Task<bool> IsConfirmedMobile (
|
||||
XTokenResponse tokens,
|
||||
string userSelectByParam
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
tokens.AccessToken,
|
||||
userSelectByParam)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.IsConfirmedMobile);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<bool> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request Registration Confirm
|
||||
/// </summary>
|
||||
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
||||
/// <returns></returns>
|
||||
public async Task RequestConfirmRegistration (XActionRequest model) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotEmpty (
|
||||
model.Lang,
|
||||
model.Password,
|
||||
model.ReturnUrl)
|
||||
.AddNotNull (model.Device)
|
||||
.AddUrl (model.ReturnUrl)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
// Get UserSelect By Param ...
|
||||
var userSelectByParam = model.GetUserSelectByParam ();
|
||||
validationProvider.NotEmpty (userSelectByParam);
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.RequestConfirmRegistration);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<object> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Confirm Registration
|
||||
/// </summary>
|
||||
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
||||
/// <returns></returns>
|
||||
public async Task ConfirmRegistration (
|
||||
XActionRequest model
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotEmpty (
|
||||
model.Lang,
|
||||
model.ActionToken,
|
||||
model.ReturnUrl
|
||||
)
|
||||
.AddNotNull (model.Device)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.ConfirmRegistration);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<object> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request For Mobile Number Change/Confirm
|
||||
/// </summary>
|
||||
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
||||
/// <returns>an instance of <see>XActionResponse</see></returns>
|
||||
public async Task<XActionResponse> RequestConfirmMobile (XActionRequest model) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotEmpty (
|
||||
model.Lang,
|
||||
model.Password,
|
||||
model.MobileNumber
|
||||
)
|
||||
.AddNotNull (model.Device)
|
||||
.AddMobileNumber (model.MobileNumber)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
// Get UserSelect By Param ...
|
||||
var userSelectByParam = GetUserSelectByParam (
|
||||
model,
|
||||
excludes : new List<XUserSelectBy> {
|
||||
XUserSelectBy.Email,
|
||||
XUserSelectBy.MobileNumber
|
||||
});
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.RequestConfirmMobile);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XActionResponse> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Confirm Requested Mobile Number
|
||||
/// </summary>
|
||||
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
||||
/// <returns>an instance of <see>XActionResponse</see></returns>
|
||||
public async Task<XActionResponse> ConfirmMobileNumber (XActionRequest model) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotEmpty (
|
||||
model.Lang,
|
||||
model.ActionToken,
|
||||
model.MobileVerificationCode
|
||||
)
|
||||
.AddNotNull (model.Device)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.ConfirmMobileNumber);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XActionResponse> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request For Email Address Change/Confirm
|
||||
/// </summary>
|
||||
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
||||
/// <returns>an instance of <see>XActionResponse</see></returns>
|
||||
public async Task<XActionResponse> RequestConfirmEmail (XActionRequest model) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotEmpty (
|
||||
model.Lang,
|
||||
model.Email,
|
||||
model.Password)
|
||||
.AddNotNull (model.Device)
|
||||
.AddEmailAddress (model.Email)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
// Get UserSelect By Param ...
|
||||
var userSelectByParam = GetUserSelectByParam (
|
||||
model,
|
||||
excludes : new List<XUserSelectBy> {
|
||||
XUserSelectBy.Email,
|
||||
XUserSelectBy.MobileNumber
|
||||
});
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.RequestConfirmEmail);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XActionResponse> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Confirm Requested Email Address
|
||||
/// </summary>
|
||||
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
||||
/// <returns>an instance of <see>XActionResponse</see></returns>
|
||||
public async Task<XActionResponse> ConfirmEmailAddress (XActionRequest model) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotEmpty (
|
||||
model.Lang,
|
||||
model.ActionToken,
|
||||
model.EmailVerificationCode
|
||||
)
|
||||
.AddNotNull (model.Device)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.ConfirmEmailAddress);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XActionResponse> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request Reset Password Action
|
||||
/// </summary>
|
||||
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
||||
/// <returns>an instance of <see>XActionResponse</see></returns>
|
||||
public async Task<XActionResponse> RequestResetPassword (XActionRequest model) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotEmpty (
|
||||
model.Lang,
|
||||
model.ReturnUrl)
|
||||
.AddNotNull (model.Device)
|
||||
.AddUrl (model.ReturnUrl)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
// Get UserSelect By Param ...
|
||||
var userSelectByParam = GetUserSelectByParam (
|
||||
model,
|
||||
excludes : new List<XUserSelectBy> {
|
||||
XUserSelectBy.Email,
|
||||
XUserSelectBy.MobileNumber
|
||||
});
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.RequestResetPassword);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<XActionResponse> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset a User's Password
|
||||
/// </summary>
|
||||
/// <param name="model">an instance of <see>XActionRequest</see> class which provider requirement for action</param>
|
||||
/// <returns></returns>
|
||||
public async Task ResetPassword (XActionRequest model) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (model)
|
||||
.AddNotEmpty (
|
||||
model.Lang,
|
||||
model.ActionToken,
|
||||
model.NewPassword,
|
||||
model.ReturnUrl)
|
||||
.AddNotNull (model.Device)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient ();
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.ResetPassword);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<object> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user