53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using Common.Dtos.User;
|
|
using Common.Enums;
|
|
using System.Net.Http.Json;
|
|
|
|
namespace HushianWebApp.Service
|
|
{
|
|
public class VerificationService
|
|
{
|
|
private readonly BaseController _baseController;
|
|
|
|
public VerificationService(BaseController baseController)
|
|
{
|
|
_baseController = baseController;
|
|
}
|
|
|
|
public async Task<int> FromUserName(string mobile, VerificationCodeType type)
|
|
{
|
|
|
|
string route = type switch
|
|
{
|
|
VerificationCodeType.PhoneNumberConfirmed => "PhoneNumberConfirmedFromUserName",
|
|
VerificationCodeType.ForgetPassword => "ForgetPasswordFromUserName",
|
|
VerificationCodeType.ChangeMobile => throw new NotImplementedException(),
|
|
VerificationCodeType.Login => throw new NotImplementedException(),
|
|
_ => throw new NotImplementedException()
|
|
};
|
|
var response = await _baseController.Get($"v1/Verification/{route}/{mobile}");
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
return await response.Content.ReadFromJsonAsync<int>();
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
|
|
}
|
|
public async Task<bool> ConfirmedCode(ConfirmedCodeDto dto)
|
|
{
|
|
var response = await _baseController.Post($"v1/Verification/ConfirmedCode", dto);
|
|
return response.IsSuccessStatusCode;
|
|
|
|
}
|
|
public async Task<bool> ReSendCode(int ID)
|
|
{
|
|
var response = await _baseController.Get($"v1/Verification/ReSendCode/{ID}");
|
|
return response.IsSuccessStatusCode;
|
|
|
|
}
|
|
}
|
|
}
|