Skip to content

Commit

Permalink
resumes page and set-get accesstoken realized
Browse files Browse the repository at this point in the history
  • Loading branch information
mediaexplorer74 committed May 27, 2023
1 parent 52741a5 commit a2cdcce
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 77 deletions.
30 changes: 13 additions & 17 deletions HHExplorer/HHExplorer/Api/HHConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,21 @@ namespace HHWebAuthenticator.HH
public class HHConfiguration
{
// Credentials
public const string ClientId = ""; //client_id
public const string ClientSecret = ""; //client_secret

public const string ClientId
= ""; //client_id
public const string ClientSecret
= ""; //client_secret

// Callback
public const string Callback =
// "https://" +
//"app-settings.hhdevelopercontent.com/simple-redirect.html";
"com.vipxam.webauthenticator-12345://callback";
public const string CallbackEscaped =
// "app-settings.hhdevelopercontent.com%3Fsimple-redirect.html";
//"https%3A%2F%2Fapp-settings.hhdevelopercontent.com%3Fsimple-redirect.html";
"com.vipxam.webauthenticator-12345%3A%2F%2Fcallback";

public const string CallbackScheme =
//"app-settings.hhdevelopercontent.com";
"com.vipxam.webauthenticator-12345";

public const string Auth2Url = "https://hh.ru/oauth/authorize?";//"https://www.hh.com/oauth2/authorize?";
public const string Callback
= "com.vipxam.webauthenticator-12345://callback";
public const string CallbackEscaped
= "com.vipxam.webauthenticator-12345%3A%2F%2Fcallback";

public const string CallbackScheme
= "com.vipxam.webauthenticator-12345";

public const string Auth2Url = "https://hh.ru/oauth/authorize?";

public const string ScopesEscaped = "readwrite%20profile";
public const string ExpireIn = "604800";
Expand Down
9 changes: 9 additions & 0 deletions HHExplorer/HHExplorer/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Xamarin.Essentials;

namespace News
{
Expand All @@ -12,6 +13,14 @@ public partial class App : Application

public App()
{
// try to get (restore) "accesstoken" settings
string accesstoken = Preferences.Get("accesstoken", "");
if (accesstoken != "")
{
AccessToken = accesstoken;
UserLogined = true;
}

InitializeComponent();

MainPage = new NavigationPage(new Views.MainPage());
Expand Down
8 changes: 7 additions & 1 deletion HHExplorer/HHExplorer/HHExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
<Compile Update="Views\AuthPage.xaml.cs">
<DependentUpon>AuthPage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\VacanciesPage.xaml.cs">
<DependentUpon>VacanciesPage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\ResumesPage.xaml.cs">
<DependentUpon>ResumesPage.xaml</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
Expand All @@ -65,7 +71,7 @@
<EmbeddedResource Update="Views\AuthPage.xaml">
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\UserDetailsPage.xaml">
<EmbeddedResource Update="Views\ResumesPage.xaml">
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion HHExplorer/HHExplorer/Views/AuthPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
<Label Text="Link HH Account" HorizontalTextAlignment="Center"
TextColor="White"/>
</Frame>
<Button HeightRequest="40" Margin="20,150,20,0"
<Button x:Name="LoginBtn"
HeightRequest="40"
Margin="20,150,20,0"
BackgroundColor="White" TextColor="#2196F3"
FontSize="Medium" FontAttributes="Bold"
Text="Login"
Expand Down
60 changes: 42 additions & 18 deletions HHExplorer/HHExplorer/Views/AuthPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using HHLibrary.Models;
using HHWebAuthenticator;
using HHWebAuthenticator.HH;
using HHWebAuthenticator.Views;
using Xamarin.Forms;
using Xamarin.Essentials;

namespace News.Views
{
Expand All @@ -14,22 +14,52 @@ public partial class AuthPage : ContentPage
public AuthPage()
{
InitializeComponent();
this.Title = "Login";
if (!App.UserLogined)
{
LoginBtn.Text = "Login";
}
else
{
LoginBtn.Text = "Log out";
}
}

public async Task Login_Button_Clicked(Object sender, EventArgs e)
{
Debug.WriteLine("[i] Checkpoint 1");
await StartHHAuthenticationAsync();
if (!App.UserLogined)
{
Debug.WriteLine("[i] Checkpoint 1");

await StartHHAuthenticationAsync();

Debug.WriteLine("[i] Checkpoint 2");

if (App.UserLogined)
{
//this.Title = "AT=" + App.AccessToken;
Debug.WriteLine("[i] User logined!");
LoginBtn.Text = "Log out";

Debug.WriteLine("[i] Checkpoint 2");
//RnD
if (App.UserLogined)
//await this.Navigation.PushAsync(new UserDetailsPage(),true);

//store "accesstoken" settings
Preferences.Set("accesstoken", App.AccessToken);
}
}
else
{
this.Title = "AT=" + App.AccessToken;
Debug.WriteLine("[i] User logined!");
//await this.Navigation.PushAsync(new UserDetailsPage(),true);
await this.Navigation.PushAsync(new UserDetailsPage(),true);
//Always logined. Log out...
try
{
Preferences.Remove("accesstoken");
}
catch (Exception ex)
{
Debug.WriteLine("[ex] Remove accesstoken problem: "
+ ex.Message);
}

LoginBtn.Text = "Login";
}
return;
}
Expand Down Expand Up @@ -66,13 +96,7 @@ async Task StartHHAuthenticationAsync()
}
else
{
Debug.WriteLine("[i] Login (scheme A) failed , try plan B");

//_tokenResponse.access_token
// = "P22U04L64BJF7M071R0DRON4A5Q5BIKE8LOUIEDD52R9R74H117L1S9SHUELEDNC";
//_tokenResponse.expires_in = 10000;
//_tokenResponse.refresh_token = "";
//this.Navigation.PushAsync(new UserDetailsPage());
Debug.WriteLine("[e] Error fetching token!!");
}

// RnD: await
Expand Down
6 changes: 3 additions & 3 deletions HHExplorer/HHExplorer/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<!--Pages can be added as references or inline-->
<TabbedPage.Children>
<views:AuthPage Title="Auth"> </views:AuthPage>
<views:NewsPage Title="Vacancies"></views:NewsPage>
<!--views:NewsPage Title="Entertainment"></views:NewsPage>
<views:NewsPage Title="General"></views:NewsPage>
<views:VacanciesPage Title="Vacancies"></views:VacanciesPage>
<views:ResumesPage Title="Resumes"></views:ResumesPage>
<!--views:NewsPage Title="General"></views:NewsPage>
<views:NewsPage Title="Health"></views:NewsPage>
<views:NewsPage Title="Science"></views:NewsPage>
<views:NewsPage Title="Sports"></views:NewsPage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="HHWebAuthenticator.Views.UserDetailsPage"
x:Class="News.Views.ResumesPage"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
BackgroundColor="#2196F3"
ios:Page.UseSafeArea="true" >
Expand All @@ -15,21 +15,13 @@
TextColor="White"/>
</Frame>

<Button x:Name="Btn1"
<Button x:Name="Btn1"
Text="Refresh all your resumes"
Clicked="ResumeUpdateButtonClick"/>

<Entry x:Name="TBox1" Text=""
HorizontalTextAlignment="Center"
Height="300"
/>

<Button HeightRequest="40" Margin="20,150,20,0"
BackgroundColor="White" TextColor="#2196F3" FontSize="Medium"
FontAttributes="Bold"
Text="Log Out"
HorizontalOptions="FillAndExpand" VerticalOptions="End"
Clicked="Logout_Button_Clicked" ></Button>
<Entry x:Name="TBox1" Text=""
HorizontalTextAlignment="Center"
/>

</StackLayout>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,29 @@
using Xamarin.Forms;
using HHLibrary.Models;

namespace HHWebAuthenticator.Views
namespace News.Views
{
public partial class UserDetailsPage : ContentPage
public partial class ResumesPage : ContentPage
{
//Models.HHResponseModel HHAccessToken;

public UserDetailsPage()
public ResumesPage()
{
this.InitializeComponent();

this.Title = "User Details";
this.Title = "Resume group tasks";

//HHAccessToken = HHConfiguration.TokenResponse;
Debug.WriteLine("HH Access token: " + HHConfiguration.TokenResponse);
TBox1.Text = "HH Access token: " + HHConfiguration.TokenResponse;
Debug.WriteLine("HH Access token: " + App.AccessToken); //HHConfiguration.TokenResponse.access_token);
TBox1.Text = "HH Access token: " + App.AccessToken; //HHConfiguration.TokenResponse.access_token;

//FetchUserActivity();
//FetchUserProfile();
TBox1.Text = TBox1.Text + " "
+ $"Welcome! Press the Resume refresh button to refresh all resume.";
+ $"Press the RESUME REFRESH button to refresh all your resumes";

}

void Logout_Button_Clicked(Object sender, EventArgs e)
{
//TODO: Pending to implement this
// Basically what you will need to revoke tokens
}

void FetchUserProfile()
{
Expand Down Expand Up @@ -69,7 +64,7 @@ private async void ResumeUpdateButtonClick(object sender, EventArgs e)
client.BaseAddress = new Uri("https://api.hh.ru");
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer",
HHConfiguration.TokenResponse.access_token);
App.AccessToken/*HHConfiguration.TokenResponse.access_token*/);
client.DefaultRequestHeaders.UserAgent.ParseAdd
(
$"HHExplorer/1 (me@nm.ru)"
Expand Down Expand Up @@ -113,7 +108,7 @@ private async void ResumeUpdateButtonClick(object sender, EventArgs e)
}//ResumeUpdateButtonClick end



// 1 resume date-time update
async void ResumeRefreshAsync(string ResumeId)
{
// - A -
Expand All @@ -122,7 +117,7 @@ async void ResumeRefreshAsync(string ResumeId)
client.BaseAddress = new Uri("https://api.hh.ru");
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer",
HHConfiguration.TokenResponse.access_token);
App.AccessToken/*HHConfiguration.TokenResponse.access_token*/);
client.DefaultRequestHeaders.UserAgent.ParseAdd
(
$"HHExplorer/1 (me@nm.ru)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:system = "clr-namespace:System;assembly=netstandard"
Title="Safe Area"
ios:Page.UseSafeArea="true"
x:Class = "News.Views.NewsPage">
x:Class = "News.Views.VacanciesPage">
<StackLayout>
<!--Button Text="Refresh" Clicked="Button_OnClicked"></Button-->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace News.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]

public partial class NewsPage : ContentPage
public partial class VacanciesPage : ContentPage
{
HHRestService _restService;

Expand All @@ -31,7 +31,7 @@ public interface IMegaClient
void RunUri(string s_uri);
}

public NewsPage()
public VacanciesPage()
{
InitializeComponent();

Expand Down Expand Up @@ -114,11 +114,11 @@ private async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
}//class end

/*
public partial class NewsPage : ContentPage
public partial class VacanciesPage : ContentPage
{
private readonly NewsService _newsService;
private NewsCategory _category;
public NewsPage()
private readonly VacanciesService _vacanciesService;
private VacanciesCategory _category;
public VacanciesPage()
{
InitializeComponent();
_newsService = new();
Expand Down
Binary file modified Images/shot3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ RU only. Только для России.
## Current Status
- Damaged / transformed to "HH concept" (idea only; horizontal menu added). Функционал разрушен, счас это всё лишь "концепт" нового HH...
- Min. Win. os. build = 15063 (No Astoria compatibility). Минимальная версия сборки Windows изменена на 15063 (совместимость с Astoria нарушена)
- Auth (Login) page added. No settings store at now.
- Auth (Login) page added. The access token stored when the user logined (and acc. token removed when the user "log-outed").
- Resumes page added. Just Click Resume refresh to refresh date-time "marker" for all your resumes :)
- Android/iOS targets are only "dummies" (stubs) at now.

## How to get your HH credentials?
Expand All @@ -23,6 +24,7 @@ RU only. Только для России.
## TODO
- Add Map. Добавить Карту.
- Add Geo-location. Реализовать некую геолокацию (привязку вакансий к опр. станции метро и т.п.).
- Add normal LixBox/TextBlock for Resumes page and etc.

## .

Expand Down

0 comments on commit a2cdcce

Please sign in to comment.