{
"info": {
"_postman_id": "82c63f15-f241-46b4-b7a3-b3245ee52bb3",
"name": "www.lesegais.ru",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "https://www.lesegais.ru/open-area/graphql",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"query\": \"query SearchContractLease($size: Int!, $number: Int!, $filter: Filter, $orders: [Order!]) { searchContractLease(filter: $filter, pageable: {number: $number, size: $size}, orders: $orders) {\\n content {\\n companyName\\n inn\\n dealDate\\n constituentName\\n forestryName\\n subForestryName\\n tractName\\n forestBlockNumbers\\n woodVolume\\n __typename\\n }\\n __typename\\n }\\n}\\n\",\r\n \"variables\": {\r\n \"size\": 20,\r\n \"number\": 0,\r\n \"filter\": null,\r\n \"orders\": null\r\n },\r\n \"operationName\": \"SearchContractLease\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://www.lesegais.ru/open-area/graphql",
"protocol": "https",
"host": [
"www",
"lesegais",
"ru"
],
"path": [
"open-area",
"graphql"
]
}
},
"response": []
}
]
}
{
"query": "query SearchContractLease($size: Int!, $number: Int!, $filter: Filter, $orders: [Order!]) { searchContractLease(filter: $filter, pageable: {number: $number, size: $size}, orders: $orders) {\n content {\n companyName\n inn\n dealDate\n constituentName\n forestryName\n subForestryName\n tractName\n forestBlockNumbers\n woodVolume\n __typename\n }\n __typename\n }\n}\n",
"variables": {
"size": 20,
"number": 0,
"filter": null,
"orders": null
},
"operationName": "SearchContractLease"
}
using EggCloud.Code;
using EggCloud.Data.Abstract;
using EggCloud.Model.Entities;
using EggCloud.Services.Abstraction;
using EggCloud.ViewModels.Auth;
using Microsoft.AspNetCore.Mvc;
namespace EggCloud.Controllers;
/// <summary>
/// Контроллер аутентификации
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class AuthController : ControllerBase
{
private readonly IAuthService authService;
private readonly IUserRepository userRepository;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="authService">сервис авторизации</param>
/// <param name="userRepository">пользовательский репозиторий</param>
public AuthController(IAuthService authService, IUserRepository userRepository)
{
this.authService = authService;
this.userRepository = userRepository;
}
/// <summary>
/// Вход в систему
/// </summary>
/// <param name="model">Модель входа в систему</param>
/// <returns></returns>
[HttpPost("login")]
public ActionResult<AuthData> Post([FromBody] LoginViewModel model)
{
if (!ModelState.IsValid) return BadRequest(ModelState);
var user = userRepository.GetSingle(u => u.Email == model.Email);
if (user == null)
{
return BadRequest(new { error = "no user with this email" });
}
var passwordValid = authService.VerifyPassword(model.Password, user.Password);
if (!passwordValid)
{
return BadRequest(new { error = "invalid password" });
}
return authService.GetAuthData(user.Id, user.IsAdmin,user.Username);
}
/// <summary>
/// Регистрация в системе
/// </summary>
/// <param name="model">Модель регистрации</param>
/// <returns></returns>
[HttpPost("register")]
public ActionResult<AuthData> Post([FromBody] RegisterViewModel model)
{
if (!ModelState.IsValid) return BadRequest(ModelState);
var emailUniq = userRepository.isEmailUniq(model.Email);
if (!emailUniq) return BadRequest(new { error = "user with this email already exists" });
var user = new User
{
Username = model.Username,
Email = model.Email,
Password = authService.HashPassword(model.Password),
RateId = Rate.Default.Id,
PaidUntil = Utils.GetTimeStamp()
};
userRepository.Add(user);
userRepository.Commit();
return authService.GetAuthData(user.Id, user.IsAdmin, user.Username);
}
}
public class VersionController : ApiController
{
public Version GetVersion ()
{
var version = new Versions();
return version;
}
}