Compare commits
38 Commits
1
...
0e9084ce2e
| Author | SHA1 | Date | |
|---|---|---|---|
| 0e9084ce2e | |||
| f2aadf43a6 | |||
| 48b79ce6ea | |||
| 81bf05e3fc | |||
| 445a1f7fa4 | |||
| 2f79bd336a | |||
| cf463a5d94 | |||
| f6500670c0 | |||
| 1f0bc01dc6 | |||
| 18e6fcc883 | |||
| 10d0a83e15 | |||
| 3b8278ba66 | |||
| 86cad2beec | |||
| 4b223ecf98 | |||
| d041fd870b | |||
| 6d5c327747 | |||
| 7e24a7444e | |||
| cb481e6af6 | |||
| cc559a4aa3 | |||
| 904fa634c6 | |||
| 9fc1fadff5 | |||
| 333eeab756 | |||
| 0ba1f4e736 | |||
| a868cb3e5c | |||
| a32bfb6e99 | |||
| e4c7df9714 | |||
| 54393e2e0f | |||
| e82cc31b4e | |||
| 362074faa4 | |||
| 0dae5a2a13 | |||
| 60db714a32 | |||
| 0826eb5898 | |||
| fcdc4476df | |||
| bae7a0267d | |||
| 1d5b171479 | |||
| 5b81ad2084 | |||
| f9a154be6f | |||
| 20c24c1fdb |
25
.gitea/workflows/deploy-dev.yml
Normal file
25
.gitea/workflows/deploy-dev.yml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
name: Publish JOBot on dev
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- dev
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build and deploy:
|
||||||
|
runs-on: host
|
||||||
|
name: Build and deploy
|
||||||
|
volumes:
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Update repo
|
||||||
|
run: |
|
||||||
|
pwd
|
||||||
|
cd /home/dockeruser/jobot-stack
|
||||||
|
git checkout dev
|
||||||
|
git pull
|
||||||
|
docker compose -f compose.dev.yml up -d postgres
|
||||||
|
|
||||||
|
cd /home/dockeruser/jobot-stack/JOBot.Backend
|
||||||
|
dotnet ef database update -- --environment Development
|
||||||
|
docker compose up --build -d
|
||||||
|
|
||||||
@@ -10,9 +10,9 @@ public class HeadHunterHookController(HeadHunterService hhService)
|
|||||||
{
|
{
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> Get(int userId, string? error, string authorizationCode)
|
public async Task<IActionResult> Get(int userId, string? error, string code)
|
||||||
{
|
{
|
||||||
var res = await hhService.AuthUser(userId, authorizationCode, error);
|
var res = await hhService.AuthUser(userId, code, error);
|
||||||
return res switch
|
return res switch
|
||||||
{
|
{
|
||||||
HeadHunterService.Status.Success => Ok("Авторизация завершена успешно. Вернитесь в Telegram для продолжения."),
|
HeadHunterService.Status.Success => Ok("Авторизация завершена успешно. Вернитесь в Telegram для продолжения."),
|
||||||
|
|||||||
@@ -10,5 +10,4 @@ WORKDIR /app
|
|||||||
COPY --from=build /app .
|
COPY --from=build /app .
|
||||||
EXPOSE 5001
|
EXPOSE 5001
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
ENV ASPNETCORE_ENVIRONMENT Staging
|
|
||||||
ENTRYPOINT ["dotnet", "JOBot.Backend.dll"]
|
ENTRYPOINT ["dotnet", "JOBot.Backend.dll"]
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Web;
|
||||||
using JOBot.Backend.DAL.Context;
|
using JOBot.Backend.DAL.Context;
|
||||||
using JOBot.Backend.DTOs.HeadHunterHook;
|
using JOBot.Backend.DTOs.HeadHunterHook;
|
||||||
using JOBot.Backend.Infrastructure.Config;
|
using JOBot.Backend.Infrastructure.Config;
|
||||||
@@ -16,17 +17,10 @@ public class HeadHunterService(ILogger<HeadHunterService> logger, IOptions<HeadH
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">Telegram UserId</param>
|
/// <param name="userId">Telegram UserId</param>
|
||||||
/// <returns>Link for auth</returns>
|
/// <returns>Link for auth</returns>
|
||||||
public string GenerateAuthLink(int userId)
|
public string GenerateAuthLink(long userId)
|
||||||
{
|
{
|
||||||
var redirectUri = new UriBuilder(_config.Links.HookDomain)
|
|
||||||
{
|
|
||||||
Port = -1,
|
|
||||||
Scheme = "https",
|
|
||||||
Path = _config.Links.HookRoute,
|
|
||||||
Query = $"?userId={userId}"
|
|
||||||
}.ToString();
|
|
||||||
|
|
||||||
return string.Format(_config.Links.AuthLink, [_config.ClientId, userId, redirectUri]);
|
return string.Format(_config.Links.AuthLink, [_config.ClientId, GetRedirectUrl(userId)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Status> AuthUser(int userId, string authorizationCode, string? error)
|
public async Task<Status> AuthUser(int userId, string authorizationCode, string? error)
|
||||||
@@ -42,10 +36,11 @@ public class HeadHunterService(ILogger<HeadHunterService> logger, IOptions<HeadH
|
|||||||
using var client = new HttpClient();
|
using var client = new HttpClient();
|
||||||
var form = new Dictionary<string, string>
|
var form = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "client-id", _config.ClientId },
|
{ "client_id", _config.ClientId },
|
||||||
{ "client_secret", _config.Secret },
|
{ "client_secret", _config.Secret },
|
||||||
{ "code", authorizationCode },
|
{ "code", authorizationCode },
|
||||||
{ "grant_type", "authorization_code" }
|
{ "grant_type", "authorization_code" },
|
||||||
|
{ "redirect_uri", GetRedirectUrl(userId) }
|
||||||
};
|
};
|
||||||
client.BaseAddress = new UriBuilder(_config.Links.HeadHunterApiDomain)
|
client.BaseAddress = new UriBuilder(_config.Links.HeadHunterApiDomain)
|
||||||
{
|
{
|
||||||
@@ -64,8 +59,9 @@ public class HeadHunterService(ILogger<HeadHunterService> logger, IOptions<HeadH
|
|||||||
|
|
||||||
if (!res.IsSuccessStatusCode)
|
if (!res.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
logger.LogWarning($"Response of HttpRequest ${_config.Links.HeadHunterApiDomain} " +
|
logger.LogWarning($"Response of HttpRequest {_config.Links.HeadHunterApiDomain}" +
|
||||||
$"${_config.Links.HeadHunterTokenRoute} has unsuccessful status code {res.StatusCode}");
|
$"{_config.Links.HeadHunterTokenRoute} has unsuccessful status code {res.StatusCode}");
|
||||||
|
logger.LogWarning($"{res.Content.ReadAsStringAsync().Result}");
|
||||||
return Status.HeadHunterAuthRejectedError;
|
return Status.HeadHunterAuthRejectedError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +91,17 @@ public class HeadHunterService(ILogger<HeadHunterService> logger, IOptions<HeadH
|
|||||||
return Status.Success;
|
return Status.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetRedirectUrl(long userId)
|
||||||
|
{
|
||||||
|
return new UriBuilder(_config.Links.HookDomain)
|
||||||
|
{
|
||||||
|
Port = -1,
|
||||||
|
Scheme = "https",
|
||||||
|
Path = _config.Links.HookRoute,
|
||||||
|
Query = $"?userId={userId}"
|
||||||
|
}.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
public enum Status
|
public enum Status
|
||||||
{
|
{
|
||||||
UserAuthRejectedError,
|
UserAuthRejectedError,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Google.Protobuf.WellKnownTypes;
|
||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using JOBot.Backend.DAL.Context;
|
using JOBot.Backend.DAL.Context;
|
||||||
using JOBot.Backend.DAL.Models;
|
using JOBot.Backend.DAL.Models;
|
||||||
@@ -7,7 +8,7 @@ using User = JOBot.Backend.DAL.Models.User;
|
|||||||
|
|
||||||
namespace JOBot.Backend.Services.gRPC;
|
namespace JOBot.Backend.Services.gRPC;
|
||||||
|
|
||||||
public class UserService(AppDbContext dbContext) : Proto.User.UserBase
|
public class UserService(AppDbContext dbContext, HeadHunterService hhService) : Proto.User.UserBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create user
|
/// Create user
|
||||||
@@ -62,6 +63,16 @@ public class UserService(AppDbContext dbContext) : Proto.User.UserBase
|
|||||||
return new AcceptEulaResponse { Success = true };
|
return new AcceptEulaResponse { Success = true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Task<GetHeadHunterAuthHookResponse> GetHeadHunterAuthHook(
|
||||||
|
GetHeadHunterAuthHookRequest request,
|
||||||
|
ServerCallContext context)
|
||||||
|
{
|
||||||
|
return Task.Run(() => new GetHeadHunterAuthHookResponse
|
||||||
|
{
|
||||||
|
RegistrationUrl = hhService.GenerateAuthLink(request.UserId)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Throw RPCException if user not found
|
/// Throw RPCException if user not found
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AllowedHosts": "*",
|
|
||||||
"ConnectionStrings": {
|
|
||||||
"PostgreSQL": "Host=postgres;Port=5432;Database=jobot_test;Username=postgres;Password=LocalDbPass"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
"HeadHunter": {
|
"HeadHunter": {
|
||||||
"Links": {
|
"Links": {
|
||||||
"AuthLink": "https://hh.ru/oauth/authorize?response_type=code&client_id={client_id}&redirect_uri={redirect_uri}",
|
"AuthLink": "https://hh.ru/oauth/authorize?response_type=code&client_id={0}&redirect_uri={1}",
|
||||||
"HookDomain": "jobot.lisoveliy.su",
|
"HookDomain": "jobot.lisoveliy.su",
|
||||||
"HookRoute": "/auth",
|
"HookRoute": "/auth",
|
||||||
"HeadHunterApiDomain": "api.hh.ru",
|
"HeadHunterApiDomain": "api.hh.ru",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public class EulaAgreementButtonCommand(PrepareUserState prepareUserState) : IAu
|
|||||||
{
|
{
|
||||||
public async Task ExecuteAsync(Update update, GetUserResponse user, CancellationToken ct)
|
public async Task ExecuteAsync(Update update, GetUserResponse user, CancellationToken ct)
|
||||||
{
|
{
|
||||||
await prepareUserState.AcceptEula(update, ct);
|
if (!user.Eula)
|
||||||
|
await prepareUserState.AcceptEula(user, update, ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,4 +57,10 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -6,12 +6,10 @@ namespace JOBot.TClient.Services;
|
|||||||
|
|
||||||
public class MenuService(ITelegramBotClient bot)
|
public class MenuService(ITelegramBotClient bot)
|
||||||
{
|
{
|
||||||
public Task RenderMenu(Update update, CancellationToken ct = default)
|
public async Task RenderMenu(Update update, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
||||||
|
|
||||||
bot.SendMessage(update.Message.From.Id,"PrepareUser stage is done.", cancellationToken: ct);
|
await bot.SendMessage(update.Message.From.Id,"PrepareUser stage is done.", cancellationToken: ct);
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,4 +83,19 @@ public class PrepareUserService(ITelegramBotClient bot, User.UserClient userClie
|
|||||||
if (!result.Success)
|
if (!result.Success)
|
||||||
throw new FallbackException(TextResource.FallbackMessage, update.Message, _bot);
|
throw new FallbackException(TextResource.FallbackMessage, update.Message, _bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task Auth(Update update, CancellationToken ct = default)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
||||||
|
|
||||||
|
var url = await _userClient.GetHeadHunterAuthHookAsync(new GetHeadHunterAuthHookRequest()
|
||||||
|
{
|
||||||
|
UserId = update.Message.From.Id
|
||||||
|
});
|
||||||
|
|
||||||
|
await _bot.SendMessage(
|
||||||
|
update.Message.From.Id,
|
||||||
|
string.Format(TextResource.AskForAuth, [url.RegistrationUrl]),
|
||||||
|
cancellationToken: ct);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using JOBot.Proto;
|
||||||
using JOBot.TClient.Services;
|
using JOBot.TClient.Services;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using User = JOBot.Proto.User;
|
using User = JOBot.Proto.User;
|
||||||
@@ -21,27 +22,34 @@ public class PrepareUserState(PrepareUserService prepareUserService, MenuService
|
|||||||
return; //interrupt while eula isn't accepted
|
return; //interrupt while eula isn't accepted
|
||||||
}
|
}
|
||||||
|
|
||||||
await OnUserEulaValidStage(update, ct);
|
await OnUserEulaValidStage(user, update, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Signal for accepted eula
|
/// Signal for accepted eula
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
/// <param name="update"></param>
|
/// <param name="update"></param>
|
||||||
/// <param name="ct"></param>
|
/// <param name="ct"></param>
|
||||||
public async Task AcceptEula(Update update, CancellationToken ct = default)
|
public async Task AcceptEula(GetUserResponse user, Update update, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
await prepareUserService.AcceptEula(update, ct: ct);
|
await prepareUserService.AcceptEula(update, ct: ct);
|
||||||
await OnUserEulaValidStage(update, ct);
|
await OnUserEulaValidStage(user, update, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Continue prepare stage
|
/// Continue prepare stage
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
/// <param name="update"></param>
|
/// <param name="update"></param>
|
||||||
/// <param name="ct"></param>
|
/// <param name="ct"></param>
|
||||||
private async Task OnUserEulaValidStage(Update update, CancellationToken ct = default)
|
private async Task OnUserEulaValidStage(GetUserResponse user, Update update, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
|
if (!user.IsLogged)
|
||||||
|
{
|
||||||
|
await prepareUserService.Auth(update, ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
await menuService.RenderMenu(update, ct); //boilerplate
|
await menuService.RenderMenu(update, ct); //boilerplate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
9
JOBot.TClient/TextResource.Designer.cs
generated
9
JOBot.TClient/TextResource.Designer.cs
generated
@@ -59,6 +59,15 @@ namespace JOBot.TClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Авторизируйтесь на сайте HeadHunter для получения доступа к резюме и вакансиям {0}.
|
||||||
|
/// </summary>
|
||||||
|
public static string AskForAuth {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("AskForAuth", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Команда не найдена, попробуйте что-то другое.
|
/// Looks up a localized string similar to Команда не найдена, попробуйте что-то другое.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -34,4 +34,7 @@ https://hh.ru/account/agreement?backurl=%2Faccount%2Fsignup%3Fbackurl%3D%252F%26
|
|||||||
<data name="Info" xml:space="preserve">
|
<data name="Info" xml:space="preserve">
|
||||||
<value>Это бот для упрощения поиска работы на HH.ru</value>
|
<value>Это бот для упрощения поиска работы на HH.ru</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="AskForAuth" xml:space="preserve">
|
||||||
|
<value>Авторизируйтесь на сайте HeadHunter для получения доступа к резюме и вакансиям {0}</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
option csharp_namespace = "JOBot.Proto";
|
option csharp_namespace = "JOBot.Proto";
|
||||||
|
|
||||||
|
import "google/protobuf/wrappers.proto";
|
||||||
|
import "google/protobuf/empty.proto";
|
||||||
|
|
||||||
service User {
|
service User {
|
||||||
rpc Register (RegisterRequest) returns (RegisterResponse);
|
rpc Register (RegisterRequest) returns (RegisterResponse);
|
||||||
rpc GetUser (GetUserRequest) returns (GetUserResponse);
|
rpc GetUser (GetUserRequest) returns (GetUserResponse);
|
||||||
rpc AcceptEula (AcceptEulaRequest) returns (AcceptEulaResponse);
|
rpc AcceptEula (AcceptEulaRequest) returns (AcceptEulaResponse);
|
||||||
|
rpc GetHeadHunterAuthHook(GetHeadHunterAuthHookRequest) returns (GetHeadHunterAuthHookResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
import "google/protobuf/wrappers.proto";
|
|
||||||
|
|
||||||
message RegisterRequest{
|
message RegisterRequest{
|
||||||
int64 user_id = 1;
|
int64 user_id = 1;
|
||||||
google.protobuf.StringValue username = 2;
|
google.protobuf.StringValue username = 2;
|
||||||
@@ -37,4 +39,12 @@ message AcceptEulaRequest {
|
|||||||
|
|
||||||
message AcceptEulaResponse{
|
message AcceptEulaResponse{
|
||||||
bool success = 1;
|
bool success = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetHeadHunterAuthHookRequest{
|
||||||
|
int64 user_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetHeadHunterAuthHookResponse{
|
||||||
|
string registration_url = 1;
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "5432:5432"
|
- "5432:5432"
|
||||||
volumes:
|
volumes:
|
||||||
- ./.docker/postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
networks:
|
networks:
|
||||||
- jobot
|
- jobot
|
||||||
|
|
||||||
@@ -20,6 +20,7 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- postgres
|
- postgres
|
||||||
ports:
|
ports:
|
||||||
|
- "5000:5000"
|
||||||
- "5001:5001"
|
- "5001:5001"
|
||||||
networks:
|
networks:
|
||||||
- jobot
|
- jobot
|
||||||
@@ -34,4 +35,7 @@ services:
|
|||||||
- jobot
|
- jobot
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
jobot:
|
jobot:
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
12
compose.yml
12
compose.yml
@@ -5,9 +5,9 @@ services:
|
|||||||
image: postgres:15
|
image: postgres:15
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_PASSWORD: LocalDbPass
|
POSTGRES_PASSWORD: LocalDbPass
|
||||||
POSTGRES_DB: jobot
|
POSTGRES_DB: jobot
|
||||||
volumes:
|
volumes:
|
||||||
- ./.docker/postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
networks:
|
networks:
|
||||||
- jobot
|
- jobot
|
||||||
|
|
||||||
@@ -17,6 +17,8 @@ services:
|
|||||||
dockerfile: JOBot.Backend/Dockerfile
|
dockerfile: JOBot.Backend/Dockerfile
|
||||||
depends_on:
|
depends_on:
|
||||||
- postgres
|
- postgres
|
||||||
|
ports:
|
||||||
|
- "5000:5000"
|
||||||
networks:
|
networks:
|
||||||
- jobot
|
- jobot
|
||||||
|
|
||||||
@@ -30,4 +32,8 @@ services:
|
|||||||
- jobot
|
- jobot
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
jobot:
|
jobot:
|
||||||
|
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
Reference in New Issue
Block a user