Skip to content
This repository was archived by the owner on Jul 2, 2022. It is now read-only.

Commit f26ca7f

Browse files
committed
LoginService -> LoginFactory
1 parent e3c71e4 commit f26ca7f

File tree

7 files changed

+28
-25
lines changed

7 files changed

+28
-25
lines changed

CodeHub.Core/CodeHub.Core.iOS.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
<Compile Include="Services\ApplicationService.cs" />
4646
<Compile Include="Services\GitHubAccountsService.cs" />
4747
<Compile Include="Services\IApplicationService.cs" />
48-
<Compile Include="Services\ILoginService.cs" />
49-
<Compile Include="Services\LoginService.cs" />
5048
<Compile Include="ViewModels\Accounts\AccountsViewModel.cs" />
5149
<Compile Include="ViewModels\Accounts\AddAccountViewModel.cs" />
5250
<Compile Include="ViewModels\App\SettingsViewModel.cs" />
@@ -133,6 +131,8 @@
133131
<Compile Include="Utils\MarkdownHtmlGenerator.cs" />
134132
<Compile Include="ViewModels\App\SidebarOrderViewModel.cs" />
135133
<Compile Include="Factories\IFeatureFactory.cs" />
134+
<Compile Include="Factories\ILoginFactory.cs" />
135+
<Compile Include="Factories\LoginFactory.cs" />
136136
</ItemGroup>
137137
<ItemGroup />
138138
<ItemGroup>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using CodeHub.Core.Data;
22
using System.Threading.Tasks;
33

4-
namespace CodeHub.Core.Services
4+
namespace CodeHub.Core.Factories
55
{
6-
public interface ILoginService
6+
public interface ILoginFactory
77
{
88
Task<LoginData> LoginWithToken(string clientId, string clientSecret, string code, string redirect, string requestDomain, string apiDomain, GitHubAccount existingAccount);
99

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
using GitHubSharp;
55
using System.Threading.Tasks;
66

7-
namespace CodeHub.Core.Services
7+
namespace CodeHub.Core.Factories
88
{
9-
public class LoginService : ILoginService
9+
public class LoginFactory : ILoginFactory
1010
{
1111
private static readonly string[] Scopes = { "user", "public_repo", "repo", "notifications", "gist" };
1212
private readonly IAccountsService _accounts;
1313

14-
public LoginService(IAccountsService accounts)
14+
public LoginFactory(IAccountsService accounts)
1515
{
1616
_accounts = accounts;
1717
}

CodeHub.Core/ViewModels/Accounts/AccountsViewModel.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
using CodeHub.Core.Data;
55
using CodeHub.Core.Services;
66
using System;
7+
using CodeHub.Core.Factories;
78

89
namespace CodeHub.Core.ViewModels.Accounts
910
{
1011
public class AccountsViewModel : BaseAccountsViewModel
1112
{
12-
private readonly ILoginService _loginService;
13+
private readonly ILoginFactory _loginFactory;
1314
private readonly IApplicationService _applicationService;
1415

15-
public AccountsViewModel(IAccountsService accountsService, ILoginService loginService, IApplicationService applicationService)
16+
public AccountsViewModel(IAccountsService accountsService, ILoginFactory loginFactory, IApplicationService applicationService)
1617
: base(accountsService)
1718
{
18-
_loginService = loginService;
19+
_loginFactory = loginFactory;
1920
_applicationService = applicationService;
2021
}
2122

@@ -47,7 +48,7 @@ protected async override void SelectAccount(IAccount account)
4748
try
4849
{
4950
IsLoggingIn = true;
50-
var client = await _loginService.LoginAccount(githubAccount);
51+
var client = await _loginFactory.LoginAccount(githubAccount);
5152
_applicationService.ActivateUser(githubAccount, client);
5253
}
5354
catch (GitHubSharp.UnauthorizedException e)

CodeHub.Core/ViewModels/Accounts/AddAccountViewModel.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
using CodeHub.Core.Data;
66
using CodeHub.Core.Services;
77
using CodeFramework.Core.ViewModels;
8+
using CodeHub.Core.Factories;
89

910
namespace CodeHub.Core.ViewModels.Accounts
1011
{
1112
public class AddAccountViewModel : BaseViewModel
1213
{
1314
private GitHubAccount _attemptedAccount;
1415
private readonly IApplicationService _application;
15-
private readonly ILoginService _loginService;
16+
private readonly ILoginFactory _loginFactory;
1617
private string _username;
1718
private string _password;
1819
private string _domain;
@@ -51,10 +52,10 @@ public ICommand LoginCommand
5152
get { return new MvxCommand(() => Login(), CanLogin);}
5253
}
5354

54-
public AddAccountViewModel(IApplicationService application, ILoginService loginService)
55+
public AddAccountViewModel(IApplicationService application, ILoginFactory loginFactory)
5556
{
5657
_application = application;
57-
_loginService = loginService;
58+
_loginFactory = loginFactory;
5859
}
5960

6061
public void Init(NavObject navObject)
@@ -99,16 +100,16 @@ private async Task Login()
99100
{
100101
IsLoggingIn = true;
101102
Console.WriteLine(apiUrl);
102-
var loginData = await Task.Run(() => _loginService.Authenticate(apiUrl, Username, Password, TwoFactor, IsEnterprise, _attemptedAccount));
103-
var client = await Task.Run(() => _loginService.LoginAccount(loginData.Account));
103+
var loginData = await Task.Run(() => _loginFactory.Authenticate(apiUrl, Username, Password, TwoFactor, IsEnterprise, _attemptedAccount));
104+
var client = await Task.Run(() => _loginFactory.LoginAccount(loginData.Account));
104105
_application.ActivateUser(loginData.Account, client);
105106
}
106107
catch (Exception e)
107108
{
108109
TwoFactor = null;
109110

110111
// Don't log an error for a two factor warning
111-
if (!(e is LoginService.TwoFactorRequiredException))
112+
if (!(e is LoginFactory.TwoFactorRequiredException))
112113
{
113114
Password = null;
114115
DisplayAlert(e.Message);

CodeHub.Core/ViewModels/Accounts/LoginViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class LoginViewModel : BaseViewModel
1515
public const string ClientId = "72f4fb74bdba774b759d";
1616
public const string ClientSecret = "9253ab615f8c00738fff5d1c665ca81e581875cb";
1717
public static readonly string RedirectUri = "http://dillonbuchanan.com/";
18-
private readonly ILoginService _loginService;
18+
private readonly ILoginFactory _loginFactory;
1919

2020
private bool _isLoggingIn;
2121
public bool IsLoggingIn
@@ -57,9 +57,9 @@ public ICommand GoBackCommand
5757
get { return new MvxCommand(() => ChangePresentation(new MvxClosePresentationHint(this))); }
5858
}
5959

60-
public LoginViewModel(ILoginService loginService)
60+
public LoginViewModel(ILoginFactory loginFactory)
6161
{
62-
_loginService = loginService;
62+
_loginFactory = loginFactory;
6363
}
6464

6565
public void Init(NavObject navObject)
@@ -115,7 +115,7 @@ public async Task Login(string code)
115115
{
116116
IsLoggingIn = true;
117117
var account = AttemptedAccount;
118-
var data = await _loginService.LoginWithToken(ClientId, ClientSecret, code, RedirectUri, WebDomain, apiUrl, account);
118+
var data = await _loginFactory.LoginWithToken(ClientId, ClientSecret, code, RedirectUri, WebDomain, apiUrl, account);
119119

120120
try
121121
{

CodeHub.Core/ViewModels/App/StartupViewModel.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
using CodeHub.Core.Data;
44
using CodeHub.Core.Services;
55
using System.Linq;
6+
using CodeHub.Core.Factories;
67

78
namespace CodeHub.Core.ViewModels.App
89
{
910
public class StartupViewModel : BaseStartupViewModel
1011
{
11-
private readonly ILoginService _loginService;
12+
private readonly ILoginFactory _loginFactory;
1213
private readonly IApplicationService _applicationService;
1314

14-
public StartupViewModel(ILoginService loginService, IApplicationService applicationService)
15+
public StartupViewModel(ILoginFactory loginFactory, IApplicationService applicationService)
1516
{
16-
_loginService = loginService;
17+
_loginFactory = loginFactory;
1718
_applicationService = applicationService;
1819
}
1920

@@ -55,7 +56,7 @@ protected async override void Startup()
5556
try
5657
{
5758
IsLoggingIn = true;
58-
var client = await _loginService.LoginAccount(account);
59+
var client = await _loginFactory.LoginAccount(account);
5960
_applicationService.ActivateUser(account, client);
6061
}
6162
catch (GitHubSharp.UnauthorizedException e)

0 commit comments

Comments
 (0)