Skip to content

Commit

Permalink
Merge pull request #7 from MahdiyarGHD/develop
Browse files Browse the repository at this point in the history
Support for uniqueidentity
  • Loading branch information
Ali-YousefiTelori authored Aug 9, 2023
2 parents b3fbdac + fa752ba commit e467ed9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,80 +209,6 @@ public virtual async System.Threading.Tasks.Task<UserResponseContractMessageCont
}
}

/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task<string> TestAsync()
{
return TestAsync(System.Threading.CancellationToken.None);
}

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual async System.Threading.Tasks.Task<string> TestAsync(System.Threading.CancellationToken cancellationToken)
{
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Users/Test");

var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
request_.Method = new System.Net.Http.HttpMethod("GET");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain"));

PrepareRequest(client_, request_, urlBuilder_);

var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);

PrepareRequest(client_, request_, url_);

var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}

ProcessResponse(client_, response_);

var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync<string>(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}

/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task<UserContractMessageContract> GetByIdAsync(long? id)
Expand Down Expand Up @@ -1558,6 +1484,7 @@ protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.Cal
public partial class UserResponseContract : System.ComponentModel.INotifyPropertyChanged
{
private string _token;
private string _uniqueIdentity;

[Newtonsoft.Json.JsonProperty("token", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string Token
Expand All @@ -1574,6 +1501,21 @@ public string Token
}
}

[Newtonsoft.Json.JsonProperty("uniqueIdentity", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string UniqueIdentity
{
get { return _uniqueIdentity; }

set
{
if (_uniqueIdentity != value)
{
_uniqueIdentity = value;
RaisePropertyChanged();
}
}
}

public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,36 +103,6 @@
}
}
},
"/api/Users/Test": {
"get": {
"tags": [
"Users"
],
"operationId": "Test",
"responses": {
"200": {
"description": "Success",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
},
"application/json": {
"schema": {
"type": "string"
}
},
"text/json": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/api/Users/GetById": {
"get": {
"tags": [
Expand Down Expand Up @@ -664,6 +634,10 @@
"token": {
"type": "string",
"nullable": true
},
"uniqueIdentity": {
"type": "string",
"nullable": true
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.2</Version>
<Version>0.0.0.3</Version>
<Description>client generated code.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>microservice,auth,authentication,client</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EasyMicroservices.Cores.Interfaces;

namespace EasyMicroservices.AuthenticationsMicroservice.Contracts.Responses
{
public class UserResponseContract
public class UserResponseContract : IUniqueIdentitySchema
{
public string Token { get; set; }
public string UniqueIdentity { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,9 @@ public virtual async Task<MessageContract<UserResponseContract>> Login(UserClaim
{
string Password = await AuthenticationHelper.HashPassword(cred.Password);

var usersRecords = await _userLogic.GetAll();
var user = usersRecords.Result.Where(x => x.UserName == cred.UserName && x.Password == Password);
UserContract userData = new();

if (!user.Any())
return (FailedReasonType.AccessDenied, "Username or password is invalid.");
else
userData = user.FirstOrDefault();
var user = await _userLogic.GetBy(x => x.UserName == cred.UserName && x.Password == Password);
if (!user)
return user.ToContract<UserResponseContract>();//"Username or password is invalid."

var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.UTF8.GetBytes(_config.GetValue<string>("JWT:Key"));
Expand All @@ -56,7 +51,8 @@ public virtual async Task<MessageContract<UserResponseContract>> Login(UserClaim

return new UserResponseContract
{
Token = tokenString
Token = tokenString,
UniqueIdentity = user.Result.UniqueIdentity
};
}

Expand Down

0 comments on commit e467ed9

Please sign in to comment.