467 lines
14 KiB
C#
467 lines
14 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.Application.Sms;
|
|
using AccountManagement.Application.Contracts.Account;
|
|
using AccountManagement.Domain.AccountAgg;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Newtonsoft.Json;
|
|
using System.Security.Claims;
|
|
using _0_Framework.Application.UID;
|
|
using AccountManagement.Application.Contracts.CameraAccount;
|
|
using CompanyManagment.EFCore;
|
|
using Company.Domain.EmployeeAgg;
|
|
using Company.Domain.EmployeeComputeOptionsAgg;
|
|
using Company.Domain.ReportAgg;
|
|
using Company.Domain.RollCallAgg;
|
|
using Company.Domain.RollCallAgg.DomainService;
|
|
using Company.Domain.YearlySalaryAgg;
|
|
using CompanyManagment.App.Contracts.AndroidApkVersion;
|
|
using CompanyManagment.App.Contracts.File1;
|
|
using CompanyManagment.App.Contracts.InstitutionPlan;
|
|
using CompanyManagment.App.Contracts.TemporaryClientRegistration;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using IUidService = _0_Framework.Application.UID.IUidService;
|
|
|
|
|
|
namespace ServiceHost.Pages
|
|
{
|
|
public class IndexModel : PageModel
|
|
{
|
|
|
|
public string Mess { get; set; }
|
|
[BindProperty]
|
|
public string Username { get; set; }
|
|
[BindProperty]
|
|
public string Password { get; set; }
|
|
[BindProperty]
|
|
public string CaptchaResponse { get; set; }
|
|
|
|
public bool HasApkToDownload { get; set; }
|
|
|
|
private static Timer aTimer;
|
|
public Login login;
|
|
public AccountViewModel Search;
|
|
private readonly ILogger<IndexModel> _logger;
|
|
private readonly IAccountApplication _accountApplication;
|
|
private readonly IGoogleRecaptcha _googleRecaptcha;
|
|
private readonly ISmsService _smsService;
|
|
private readonly IWorker _worker;
|
|
private readonly IAuthHelper _authHelper;
|
|
private readonly ICameraAccountApplication _cameraAccountApplication;
|
|
private readonly IWebHostEnvironment _webHostEnvironment;
|
|
private readonly IAndroidApkVersionApplication _androidApkVersionApplication;
|
|
private readonly ITemporaryClientRegistrationApplication _clientRegistrationApplication;
|
|
private readonly IYearlySalaryRepository _yearlySalaryRepository;
|
|
private readonly IEmployeeComputeOptionsRepository _computeOptions;
|
|
private readonly IFileApplication _fileApplication;
|
|
|
|
|
|
|
|
|
|
public IndexModel(ILogger<IndexModel> logger, IAccountApplication accountApplication, IGoogleRecaptcha googleRecaptcha, ISmsService smsService, IWorker worker,
|
|
IAuthHelper authHelper, ICameraAccountApplication cameraAccountApplication, IWebHostEnvironment webHostEnvironment,
|
|
IAndroidApkVersionApplication androidApkVersionApplication, ITemporaryClientRegistrationApplication clientRegistrationApplication, IYearlySalaryRepository yearlySalaryRepository, IEmployeeComputeOptionsRepository computeOptions, IFileApplication fileApplication)
|
|
{
|
|
_logger = logger;
|
|
_accountApplication = accountApplication;
|
|
_googleRecaptcha = googleRecaptcha;
|
|
_smsService = smsService;
|
|
_worker = worker;
|
|
_authHelper = authHelper;
|
|
_cameraAccountApplication = cameraAccountApplication;
|
|
_webHostEnvironment = webHostEnvironment;
|
|
_androidApkVersionApplication = androidApkVersionApplication;
|
|
_clientRegistrationApplication = clientRegistrationApplication;
|
|
_yearlySalaryRepository = yearlySalaryRepository;
|
|
_computeOptions = computeOptions;
|
|
_fileApplication = fileApplication;
|
|
}
|
|
|
|
public async Task<IActionResult> OnGet()
|
|
{
|
|
// _computeOptions.GetAllByWorkshopId(170);
|
|
//_yearlySalaryRepository.TestDayliFeeCompute();
|
|
bool ex = false;
|
|
//while (!ex)
|
|
//{
|
|
// Console.WriteLine("enter National code ... ");
|
|
// var nationalCode = Console.ReadLine();
|
|
// Console.WriteLine("enter DateOfBirth ... ");
|
|
// var dateOfBirth = Console.ReadLine();
|
|
// Console.WriteLine("enter phoneNumber ... ");
|
|
// var phone = Console.ReadLine();
|
|
// var res = _clientRegistrationApplication.CreateContractingPartyTemp(nationalCode, dateOfBirth, phone).GetAwaiter().GetResult();
|
|
// if (res.IsSuccedded)
|
|
// {
|
|
// var updateAddress =
|
|
// _clientRegistrationApplication.UpdateAddress(res.Data.Id, "gilan", "rasht", "hajiabad").GetAwaiter().GetResult();
|
|
// if (updateAddress.IsSuccedded)
|
|
// {
|
|
// var workshopSelected = _clientRegistrationApplication.GetWorkshopTemp(res.Data.Id).GetAwaiter().GetResult();
|
|
// if (workshopSelected.Count > 0)
|
|
// {
|
|
// var result = _clientRegistrationApplication.GetTotalPaymentAndWorkshopList(res.Data.Id).GetAwaiter().GetResult();
|
|
// Console.WriteLine("sumOfWorkshopPayment : " + result.SumOfWorkshopsPaymentDouble);
|
|
// Console.WriteLine("sumOfWorkshopPayment : " + result.TotalPaymentDouble);
|
|
// }
|
|
// else
|
|
// {
|
|
// var workshops = new List<WorkshopTempViewModel>();
|
|
// workshops.Add(new WorkshopTempViewModel
|
|
// {
|
|
// ContractAndCheckout = true,
|
|
// ContractingPartyTempId = res.Data.Id,
|
|
// CountPerson = 10,
|
|
// CustomizeCheckout = true,
|
|
// Insurance = true,
|
|
// RollCall = true,
|
|
// WorkshopName = "dadmehr",
|
|
|
|
// });
|
|
// workshops.Add(new WorkshopTempViewModel
|
|
// {
|
|
// ContractAndCheckout = true,
|
|
// ContractingPartyTempId = res.Data.Id,
|
|
// CountPerson = 20,
|
|
// CustomizeCheckout = true,
|
|
// Insurance = true,
|
|
// RollCall = true,
|
|
// WorkshopName = "kababMahdi",
|
|
|
|
// });
|
|
// var creteWorkshops = _clientRegistrationApplication.CreateOrUpdateWorkshopTemp(workshops)
|
|
// .GetAwaiter().GetResult();
|
|
|
|
// if (creteWorkshops.IsSuccedded)
|
|
// {
|
|
// var result = _clientRegistrationApplication.GetTotalPaymentAndWorkshopList(res.Data.Id).GetAwaiter().GetResult();
|
|
// Console.WriteLine("sumOfWorkshopPayment : " + result.SumOfWorkshopsPaymentDouble);
|
|
// Console.WriteLine("sumOfWorkshopPayment : " + result.TotalPaymentDouble);
|
|
// }
|
|
// }
|
|
|
|
// }
|
|
// }
|
|
// Console.WriteLine("do you want to exit ... ");
|
|
// var exitCheck = Console.ReadLine();
|
|
// if (exitCheck == "yes")
|
|
// ex = true;
|
|
//}
|
|
|
|
// while (!ex)
|
|
// {
|
|
// var onGet = _institutionPlanApplication.GetByFirst();
|
|
// Console.WriteLine("enter ContractAndCheckoutInPersonPercent ... " + onGet.ContractAndCheckoutInPersonPercent);
|
|
// var ContractAndCheckoutInPersonPercent = Console.ReadLine();
|
|
// Console.WriteLine("enter ContractAndCheckoutPercent ... " + onGet.ContractAndCheckoutPercent);
|
|
// var ContractAndCheckoutPercent = Console.ReadLine();
|
|
|
|
// Console.WriteLine("enter InsurancePercent ... " + onGet.InsurancePercent);
|
|
// var InsurancePercent = Console.ReadLine();
|
|
// Console.WriteLine("enter InsuranceInPersonPercent ... " + onGet.InsuranceInPersonPercent);
|
|
// var InsuranceInPersonPercent = Console.ReadLine();
|
|
|
|
// Console.WriteLine("enter CustomizeCheckoutPercent ... " + onGet.CustomizeCheckoutPercent);
|
|
// var CustomizeCheckoutPercent = Console.ReadLine();
|
|
// Console.WriteLine("enter RollCallPercent ... " + onGet.RollCallPercent);
|
|
// var RollCallPercent = Console.ReadLine();
|
|
// //var res = _institutionPlanApplication.GetInstitutionPlanList(Convert.ToInt32(pageIndex),
|
|
// // Convert.ToInt32(countPerson));
|
|
|
|
// var res = _institutionPlanApplication.CreateInstitutionPlanPercentage(new CreateInstitutionPlanPercentage()
|
|
// {
|
|
// ContractAndCheckoutInPersonPercentStr = ContractAndCheckoutInPersonPercent,
|
|
// ContractAndCheckoutPercentStr = ContractAndCheckoutPercent,
|
|
// InsurancePercentStr = InsurancePercent,
|
|
// InsuranceInPersonPercentStr = InsuranceInPersonPercent,
|
|
// CustomizeCheckoutPercentStr = CustomizeCheckoutPercent,
|
|
// RollCallPercentStr = RollCallPercent
|
|
// });
|
|
|
|
// Console.WriteLine("do you want to exit ... ");
|
|
// var exitCheck = Console.ReadLine();
|
|
// if (exitCheck == "y")
|
|
// ex = true;
|
|
//}
|
|
// _reportRepository.GetAllActiveWorkshopsNew("1403", "12");
|
|
|
|
//var test = _uidService.GetPersonalInfo("2669318622", "1363/02/25");
|
|
HasApkToDownload = _androidApkVersionApplication.HasAndroidApkToDownload();
|
|
if (User.Identity is { IsAuthenticated: true })
|
|
{
|
|
if (User.FindFirstValue("IsCamera") == "true")
|
|
{
|
|
return Redirect("/Camera");
|
|
}
|
|
else if ((User.FindFirstValue("ClientAriaPermission") == "true") && (User.FindFirstValue("AdminAreaPermission") == "false"))
|
|
{
|
|
return Redirect("/Client");
|
|
}
|
|
else
|
|
{
|
|
return Redirect("/Admin");
|
|
}
|
|
}
|
|
_authHelper.SignOut();
|
|
return Page();
|
|
}
|
|
|
|
|
|
public IActionResult OnPostLogin(Login command)
|
|
{
|
|
|
|
var result = _accountApplication.Login(command);
|
|
if (result.IsSuccedded)
|
|
return RedirectToPage("/Admin");
|
|
|
|
|
|
ModelState.AddModelError("Username", "اطلاعات وارد شده اشتباه است");
|
|
TempData["h"] = "n";
|
|
Mess = result.Message;
|
|
return null;
|
|
|
|
}
|
|
|
|
public IActionResult OnPostEnter(Login command)
|
|
{
|
|
|
|
bool captchaResult = true;
|
|
//if (!_webHostEnvironment.IsDevelopment())
|
|
// captchaResult = _googleRecaptcha.IsSatisfy(CaptchaResponse).Result;
|
|
|
|
|
|
if (captchaResult)
|
|
{
|
|
var result = _accountApplication.Login(command);
|
|
if (result.IsSuccedded)
|
|
{
|
|
switch (result.SendId)
|
|
{
|
|
case 1:
|
|
return Redirect("/Admin");
|
|
break;
|
|
case 2:
|
|
return Redirect("/Client");
|
|
break;
|
|
case 3:
|
|
return Redirect("/Camera");
|
|
//return
|
|
// var verfiyResult = _accountApplication.GetByVerifyCode(code);
|
|
break;
|
|
case 0:
|
|
result.Message = "امکان ورود با این حساب کاربری وجود ندارد";
|
|
break;
|
|
}
|
|
}
|
|
|
|
Mess = result.Message;
|
|
}
|
|
else
|
|
{
|
|
Mess = "دستگاه شما ربات تشخیص داده شد";
|
|
}
|
|
|
|
|
|
|
|
//ModelState.AddModelError("Username", "اطلاعات وارد شده اشتباه است");
|
|
|
|
return Page();
|
|
}
|
|
|
|
public async Task<JsonResult> OnPostCheckCaptcha(string response)
|
|
{
|
|
var result = await _googleRecaptcha.IsSatisfy(response);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
isNotRobot = result,
|
|
|
|
});
|
|
}
|
|
|
|
public IActionResult OnPostRegisterClient(string name, string user, string pass, string phone, string nationalcode)
|
|
{
|
|
var command = new RegisterAccount()
|
|
{
|
|
Fullname = name,
|
|
Username = user,
|
|
Password = pass,
|
|
Mobile = phone,
|
|
NationalCode = nationalcode,
|
|
};
|
|
var result = _accountApplication.RegisterClient(command);
|
|
return new JsonResult(new
|
|
{
|
|
isSucceded = result.IsSuccedded,
|
|
message = result.Message
|
|
});
|
|
}
|
|
public IActionResult OnGetLogout()
|
|
{
|
|
_accountApplication.Logout();
|
|
return RedirectToPage("/Index");
|
|
}
|
|
|
|
|
|
public async Task<IActionResult> OnPostCheckPhoneValid(string phone)
|
|
{
|
|
var result = _accountApplication.Search(new AccountSearchModel() { Mobile = phone }).FirstOrDefault();
|
|
if (result == null)
|
|
{
|
|
return new JsonResult(new
|
|
{
|
|
exist = false,
|
|
});
|
|
}
|
|
else
|
|
{
|
|
SendSms(phone);
|
|
return new JsonResult(new
|
|
{
|
|
exist = true,
|
|
});
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public void SendSms(string phone)
|
|
{
|
|
|
|
var result = _accountApplication.Search(new AccountSearchModel() { Mobile = phone }).FirstOrDefault();
|
|
if (result != null)
|
|
{
|
|
_accountApplication.SetVerifyCode(phone, result.Id);
|
|
|
|
}
|
|
}
|
|
|
|
public IActionResult OnPostWithMobile(string code, string phone)
|
|
{
|
|
//bool captchaResult = true;
|
|
//if (!_webHostEnvironment.IsDevelopment())
|
|
// captchaResult = _googleRecaptcha.IsSatisfy(CaptchaResponse).Result;
|
|
//if (captchaResult)
|
|
//{
|
|
var verfiyResult = _accountApplication.GetByVerifyCode(code, phone);
|
|
if (verfiyResult != null)
|
|
{
|
|
|
|
var result = _accountApplication.LoginWithMobile(verfiyResult.Id);
|
|
if (result.IsSuccedded && result.SendId == 1)
|
|
{
|
|
return new JsonResult(new
|
|
{
|
|
exist = true,
|
|
url = "/Admin",
|
|
});
|
|
}
|
|
|
|
|
|
if (result.IsSuccedded && result.SendId == 2)
|
|
{
|
|
return new JsonResult(new
|
|
{
|
|
exist = true,
|
|
url = "/Client",
|
|
});
|
|
}
|
|
|
|
}
|
|
//}
|
|
//else
|
|
//{
|
|
// Mess = "دستگاه شما ربات تشخیص داده شد";
|
|
//}
|
|
|
|
|
|
|
|
return new JsonResult(new
|
|
{
|
|
exist = false,
|
|
});
|
|
|
|
}
|
|
public IActionResult OnPostVerify(string code, string phone)
|
|
{
|
|
var result = _accountApplication.GetByVerifyCode(code, phone);
|
|
if (result != null)
|
|
{
|
|
return new JsonResult(new
|
|
{
|
|
exist = true,
|
|
user = result.Username,
|
|
verfyId = result.Id
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
return new JsonResult(new
|
|
{
|
|
exist = false,
|
|
});
|
|
}
|
|
}
|
|
|
|
public IActionResult OnPostChangePass(long id, string username, string newpass)
|
|
{
|
|
var result = _accountApplication.GetByUserNameAndId(id, username);
|
|
if (result != null)
|
|
{
|
|
var command = new ChangePassword()
|
|
{
|
|
Id = id,
|
|
Password = newpass,
|
|
RePassword = newpass
|
|
};
|
|
var finalResult = _accountApplication.ChangePassword(command);
|
|
if (finalResult.IsSuccedded)
|
|
{
|
|
return new JsonResult(new
|
|
{
|
|
exist = true,
|
|
changed = true
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
return new JsonResult(new
|
|
{
|
|
exist = true,
|
|
changed = false
|
|
|
|
});
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
return new JsonResult(new
|
|
{
|
|
exist = false,
|
|
changed = false
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public class RecaptchaResponse
|
|
{
|
|
[JsonProperty("success")]
|
|
public bool Success { get; set; }
|
|
|
|
[JsonProperty("challenge_ts")]
|
|
public DateTimeOffset ChallengeTs { get; set; }
|
|
|
|
[JsonProperty("hostname")]
|
|
public string HostName { get; set; }
|
|
|
|
}
|
|
|