Skip to content

Commit 15d0622

Browse files
authored
Merge pull request #45 from gitcomteam/dev
v0.17.1
2 parents d98e255 + 719be74 commit 15d0622

File tree

6 files changed

+68
-11
lines changed

6 files changed

+68
-11
lines changed

App/AL/CLI/Creation/CreateProject.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ public CreateProject() {
1717
}
1818

1919
public CliResult Execute() {
20-
Output("Manually creating project");
21-
2220
Output("Type creator login:");
2321
var userLogin = Console.ReadLine();
2422

App/AL/CLI/Creation/CreateUser.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using App.DL.Repository.User;
4+
using App.PL.Transformer.User;
5+
using Micron.AL.Config.CLI;
6+
using Micron.DL.Module.CLI;
7+
using Micron.DL.Module.Misc;
8+
9+
namespace App.AL.CLI.Creation {
10+
public class CreateUser : BaseCommand, ICliCommand {
11+
public override string Signature { get; } = "create-user";
12+
13+
public CreateUser() {
14+
StrOutput = new List<string>();
15+
}
16+
17+
public CliResult Execute() {
18+
Output("Type email:");
19+
var email = Console.ReadLine();
20+
var user = UserRepository.FindByEmail(email);
21+
if (user != null) {
22+
Output("User with this email already exists");
23+
return new CliResult(CliExitCode.UnknownError, StrOutput);
24+
}
25+
26+
Output("Type login:");
27+
var login = Console.ReadLine();
28+
user = UserRepository.FindByLogin(login);
29+
if (user != null) {
30+
Output("User with this login already exists");
31+
return new CliResult(CliExitCode.UnknownError, StrOutput);
32+
}
33+
34+
Output("Type password:");
35+
var password = Console.ReadLine();
36+
password = string.IsNullOrEmpty(password) ? Rand.RandomString() : password;
37+
Console.WriteLine($"New password: {password}");
38+
39+
user = UserRepository.FindOrCreateByEmailAndLogin(email, login, password);
40+
41+
Output("Created user:");
42+
Output(new UserTransformer().Transform(user).ToString());
43+
44+
return new CliResult(CliExitCode.Ok, StrOutput);
45+
}
46+
}
47+
}

App/AL/Config/CLI/CommandsList.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static ICliCommand[] Get()
1212
new ApproveInvoice(),
1313
new DbTablesCount(),
1414
new CreateProject(),
15+
new CreateUser(),
1516
};
1617
}
1718
}

App/AL/Controller/Auth/External/GitHub/GithubAuthController.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using System.Collections.Generic;
22
using System.Net.Http;
33
using App.DL.Enum;
4-
using App.DL.Model.Auth;
54
using App.DL.Repository.Auth;
65
using App.DL.Repository.User;
76
using Micron.DL.Middleware;
87
using Micron.DL.Module.Auth;
98
using Micron.DL.Module.Config;
109
using Micron.DL.Module.Controller;
1110
using Micron.DL.Module.Http;
11+
using Micron.DL.Module.Misc;
1212
using Nancy;
1313
using Newtonsoft.Json.Linq;
1414
using Octokit;
@@ -18,18 +18,18 @@ public sealed class GithubAuthController : BaseController {
1818
protected override IMiddleware[] Middleware() => new IMiddleware[] {};
1919

2020
private const string Scopes = "user:email,read:user";
21-
21+
2222
public GithubAuthController() {
2323
var clientId = AppConfig.GetConfiguration("auth:external:github:client_id");
2424
var clientSecret = AppConfig.GetConfiguration("auth:external:github:client_secret");
25-
25+
2626
Get("/api/v1/auth/github/login_link/get", _ => {
2727
var loginLink = $"https://github.com/login/oauth/authorize?scope={Scopes}&client_id={clientId}";
2828
return HttpResponse.Data(new JObject() {
2929
["login_link"] = loginLink
3030
});
3131
});
32-
32+
3333
Get("/api/v1/auth/github/get_auth_token", _ => {
3434
var responseBody = "";
3535
var code = GetRequestStr("code");
@@ -65,9 +65,11 @@ public GithubAuthController() {
6565

6666
var githubUser = githubClient.User.Current().Result;
6767

68-
var user = UserRepository.FindByEmail(githubUser.Email) ??
68+
var userEmail = githubUser.Email ?? $"{Rand.RandomString()}[email protected]";
69+
70+
var user = UserRepository.FindByEmail(userEmail) ??
6971
UserRepository.FindOrCreateByEmailAndLogin(
70-
githubUser.Email, githubUser.Login, null,
72+
userEmail, githubUser.Login, null,
7173
UserRepository.FindByGuid(GetRequestStr("referral_key"))
7274
);
7375

App/App.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TargetFramework>netcoreapp2.2</TargetFramework>
66
<LangVersion>8</LangVersion>
77
<Nullable>enable</Nullable>
8-
<AssemblyVersion>0.17.0</AssemblyVersion>
8+
<AssemblyVersion>0.17.1</AssemblyVersion>
99
<FileVersion></FileVersion>
1010
</PropertyGroup>
1111

App/DL/Model/User/User.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using System.Net.Mail;
34
using App.DL.Enum;
45
using App.DL.Model.Auth;
56
using App.DL.Repository.Auth;
@@ -48,12 +49,20 @@ public static User FindByGuid(string guid)
4849
new {guid}
4950
).FirstOrDefault();
5051

51-
public static int Create(string email, string login, string password)
52-
=> ExecuteScalarInt(
52+
public static int Create(string email, string login, string password) {
53+
try {
54+
new MailAddress(email);
55+
}
56+
catch (Exception e) {
57+
Console.WriteLine(e.StackTrace);
58+
throw new Exception($"Invalid user email: {email}");
59+
}
60+
return ExecuteScalarInt(
5361
@"INSERT INTO public.users(guid, email, login, password) VALUES (@guid, @email, @login, @password);
5462
SELECT currval('users_id_seq');"
5563
, new {guid = Guid.NewGuid().ToString(), email, login, password = Encryptor.Encrypt(password)}
5664
);
65+
}
5766

5867
public ServiceAccessToken ServiceAccessToken(ServiceType serviceType) =>
5968
ServiceAccessTokenRepository.Find(this, serviceType);

0 commit comments

Comments
 (0)