Skip to content

Commit d98e255

Browse files
authored
Merge pull request #39 from gitcomteam/dev
0.17.0
2 parents 7b6eb51 + 84e5d84 commit d98e255

File tree

7 files changed

+111
-6
lines changed

7 files changed

+111
-6
lines changed

App/AL/Controller/Auth/JwtAuthController.cs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System.Collections.Generic;
22
using App.AL.Validation.String;
3-
using App.DL.Model.User;
4-
using App.DL.Model.User.Registration;
53
using App.DL.Module.Email;
64
using App.DL.Repository.User;
75
using App.DL.Repository.User.Registration;
@@ -12,6 +10,7 @@
1210
using Micron.DL.Module.Controller;
1311
using Micron.DL.Module.Crypto;
1412
using Micron.DL.Module.Http;
13+
using Micron.DL.Module.Misc;
1514
using Micron.DL.Module.Validator;
1615
using Nancy;
1716
using Newtonsoft.Json.Linq;
@@ -95,6 +94,45 @@ public JwtAuthController() {
9594
});
9695
});
9796

97+
Post("/api/v1/lazy_register", _ => {
98+
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
99+
new ShouldHaveParameters(new[] {"email"}),
100+
new ShouldBeValidEmail(),
101+
}, true);
102+
if (errors.Count > 0) return HttpResponse.Errors(errors);
103+
104+
var email = GetRequestStr("email").Replace(" ", "").ToLower();
105+
106+
var existingUser = UserRepository.FindByEmail(email);
107+
108+
if (existingUser != null) {
109+
return HttpResponse.Error(
110+
HttpStatusCode.Forbidden,
111+
"User with this email already exist, you need to log in"
112+
);
113+
}
114+
115+
var login = email.Split("@")[0];
116+
117+
var registeredUser = UserRepository.FindOrCreateByEmailAndLogin(
118+
email, login, Rand.RandomString()
119+
);
120+
121+
var registerQueueItem = RegistrationQueueItemRepository.Create(registeredUser);
122+
123+
MailGunSender.QueueTemplate(
124+
"confirm-your-email", registeredUser.email, "GitCom - you almost there!",
125+
new[] {
126+
new KeyValuePair<string, string>("confirmation_key", registerQueueItem.confirmation_key),
127+
}
128+
);
129+
130+
131+
return HttpResponse.Data(new JObject() {
132+
["token"] = Jwt.FromUserId(registeredUser.id)
133+
});
134+
});
135+
98136
Post("/api/v1/register/confirm_email", _ => {
99137
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
100138
new ShouldHaveParameters(new[] {"confirmation_key"}),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using App.DL.Repository.User;
2+
using App.PL.Transformer.Project;
3+
using Micron.AL.Validation.Db;
4+
using Micron.DL.Middleware;
5+
using Micron.DL.Module.Controller;
6+
using Micron.DL.Module.Http;
7+
using Micron.DL.Module.Validator;
8+
9+
namespace App.AL.Controller.Project {
10+
public class UserProjectsController : BaseController {
11+
protected override IMiddleware[] Middleware() => new IMiddleware[] {};
12+
13+
public UserProjectsController() {
14+
Get("/api/v1/user/projects/get", _ => {
15+
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
16+
new ExistsInTable("user_guid", "users", "guid")
17+
});
18+
if (errors.Count > 0) return HttpResponse.Errors(errors);
19+
20+
var user = UserRepository.FindByGuid(GetRequestStr("user_guid"));
21+
22+
return HttpResponse.Item("projects", new ProjectTransformer().Many(user.Projects()));
23+
});
24+
}
25+
}
26+
}

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.16.0</AssemblyVersion>
8+
<AssemblyVersion>0.17.0</AssemblyVersion>
99
<FileVersion></FileVersion>
1010
</PropertyGroup>
1111

App/DL/Model/Project/Project.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ public static Project FindBy(string col, int val)
5252
$"SELECT * FROM projects WHERE {col} = @val LIMIT 1", new {val}
5353
).FirstOrDefault();
5454

55+
public static Project[] GetBy(string col, string val)
56+
=> Connection().Query<Project>(
57+
$"SELECT * FROM projects WHERE {col} = @val LIMIT 1", new {val}
58+
).ToArray();
59+
60+
public static Project[] GetBy(string col, int val)
61+
=> Connection().Query<Project>(
62+
$"SELECT * FROM projects WHERE {col} = @val LIMIT 1", new {val}
63+
).ToArray();
64+
5565
public static Project FindRandom()
5666
=> Connection().Query<Project>(
5767
"SELECT * FROM projects WHERE id = @id ORDER BY random() LIMIT 1"

App/DL/Model/User/User.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using App.DL.Enum;
44
using App.DL.Model.Auth;
55
using App.DL.Repository.Auth;
6+
using App.DL.Repository.Project;
67
using Micron.DL.Module.Crypto;
78
using Dapper;
89

@@ -56,5 +57,7 @@ public static int Create(string email, string login, string password)
5657

5758
public ServiceAccessToken ServiceAccessToken(ServiceType serviceType) =>
5859
ServiceAccessTokenRepository.Find(this, serviceType);
60+
61+
public Project.Project[] Projects() => ProjectRepository.GetBy("creator_id", id);
5962
}
6063
}

App/DL/Repository/Project/ProjectRepository.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ public static ProjectModel Find(int id) {
1010
return ProjectModel.Find(id);
1111
}
1212

13-
public static ProjectModel FindByGuid(string guid) {
14-
return ProjectModel.FindByGuid(guid);
15-
}
13+
public static ProjectModel FindByGuid(string guid) => ProjectModel.FindByGuid(guid);
14+
15+
public static ProjectModel FindBy(string col, string val) => ProjectModel.FindBy(col, val);
16+
17+
public static ProjectModel FindBy(string col, int val) => ProjectModel.FindBy(col, val);
1618

19+
public static ProjectModel[] GetBy(string col, string val) => ProjectModel.GetBy(col, val);
20+
21+
public static ProjectModel[] GetBy(string col, int val) => ProjectModel.GetBy(col, val);
22+
1723
public static ProjectModel FindRandom() => ProjectModel.FindRandom();
1824

1925
public static ProjectModel[] GetRandom() => ProjectModel.GetRandom();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
4+
use Phinx\Migration\AbstractMigration;
5+
6+
class CreateUserBadgesTable extends AbstractMigration
7+
{
8+
public function change()
9+
{
10+
$table = $this->table('user_badges');
11+
$table
12+
->addColumn('guid', 'string')
13+
->addColumn('user_id', 'integer', ['signed' => false, 'null' => false])
14+
->addColumn('badge', 'string')
15+
16+
->addForeignKey('user_id', 'users', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
17+
18+
->addIndex(['guid'], ['unique' => true])
19+
20+
->create();
21+
}
22+
}

0 commit comments

Comments
 (0)