Skip to content

0.17.0 #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions App/AL/Controller/Auth/JwtAuthController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Collections.Generic;
using App.AL.Validation.String;
using App.DL.Model.User;
using App.DL.Model.User.Registration;
using App.DL.Module.Email;
using App.DL.Repository.User;
using App.DL.Repository.User.Registration;
Expand All @@ -12,6 +10,7 @@
using Micron.DL.Module.Controller;
using Micron.DL.Module.Crypto;
using Micron.DL.Module.Http;
using Micron.DL.Module.Misc;
using Micron.DL.Module.Validator;
using Nancy;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -95,6 +94,45 @@ public JwtAuthController() {
});
});

Post("/api/v1/lazy_register", _ => {
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
new ShouldHaveParameters(new[] {"email"}),
new ShouldBeValidEmail(),
}, true);
if (errors.Count > 0) return HttpResponse.Errors(errors);

var email = GetRequestStr("email").Replace(" ", "").ToLower();

var existingUser = UserRepository.FindByEmail(email);

if (existingUser != null) {
return HttpResponse.Error(
HttpStatusCode.Forbidden,
"User with this email already exist, you need to log in"
);
}

var login = email.Split("@")[0];

var registeredUser = UserRepository.FindOrCreateByEmailAndLogin(
email, login, Rand.RandomString()
);

var registerQueueItem = RegistrationQueueItemRepository.Create(registeredUser);

MailGunSender.QueueTemplate(
"confirm-your-email", registeredUser.email, "GitCom - you almost there!",
new[] {
new KeyValuePair<string, string>("confirmation_key", registerQueueItem.confirmation_key),
}
);


return HttpResponse.Data(new JObject() {
["token"] = Jwt.FromUserId(registeredUser.id)
});
});

Post("/api/v1/register/confirm_email", _ => {
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
new ShouldHaveParameters(new[] {"confirmation_key"}),
Expand Down
26 changes: 26 additions & 0 deletions App/AL/Controller/Project/UserProjectsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using App.DL.Repository.User;
using App.PL.Transformer.Project;
using Micron.AL.Validation.Db;
using Micron.DL.Middleware;
using Micron.DL.Module.Controller;
using Micron.DL.Module.Http;
using Micron.DL.Module.Validator;

namespace App.AL.Controller.Project {
public class UserProjectsController : BaseController {
protected override IMiddleware[] Middleware() => new IMiddleware[] {};

public UserProjectsController() {
Get("/api/v1/user/projects/get", _ => {
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
new ExistsInTable("user_guid", "users", "guid")
});
if (errors.Count > 0) return HttpResponse.Errors(errors);

var user = UserRepository.FindByGuid(GetRequestStr("user_guid"));

return HttpResponse.Item("projects", new ProjectTransformer().Many(user.Projects()));
});
}
}
}
2 changes: 1 addition & 1 deletion App/App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
<AssemblyVersion>0.16.0</AssemblyVersion>
<AssemblyVersion>0.17.0</AssemblyVersion>
<FileVersion></FileVersion>
</PropertyGroup>

Expand Down
10 changes: 10 additions & 0 deletions App/DL/Model/Project/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public static Project FindBy(string col, int val)
$"SELECT * FROM projects WHERE {col} = @val LIMIT 1", new {val}
).FirstOrDefault();

public static Project[] GetBy(string col, string val)
=> Connection().Query<Project>(
$"SELECT * FROM projects WHERE {col} = @val LIMIT 1", new {val}
).ToArray();

public static Project[] GetBy(string col, int val)
=> Connection().Query<Project>(
$"SELECT * FROM projects WHERE {col} = @val LIMIT 1", new {val}
).ToArray();

public static Project FindRandom()
=> Connection().Query<Project>(
"SELECT * FROM projects WHERE id = @id ORDER BY random() LIMIT 1"
Expand Down
3 changes: 3 additions & 0 deletions App/DL/Model/User/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using App.DL.Enum;
using App.DL.Model.Auth;
using App.DL.Repository.Auth;
using App.DL.Repository.Project;
using Micron.DL.Module.Crypto;
using Dapper;

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

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

public Project.Project[] Projects() => ProjectRepository.GetBy("creator_id", id);
}
}
12 changes: 9 additions & 3 deletions App/DL/Repository/Project/ProjectRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ public static ProjectModel Find(int id) {
return ProjectModel.Find(id);
}

public static ProjectModel FindByGuid(string guid) {
return ProjectModel.FindByGuid(guid);
}
public static ProjectModel FindByGuid(string guid) => ProjectModel.FindByGuid(guid);

public static ProjectModel FindBy(string col, string val) => ProjectModel.FindBy(col, val);

public static ProjectModel FindBy(string col, int val) => ProjectModel.FindBy(col, val);

public static ProjectModel[] GetBy(string col, string val) => ProjectModel.GetBy(col, val);

public static ProjectModel[] GetBy(string col, int val) => ProjectModel.GetBy(col, val);

public static ProjectModel FindRandom() => ProjectModel.FindRandom();

public static ProjectModel[] GetRandom() => ProjectModel.GetRandom();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php


use Phinx\Migration\AbstractMigration;

class CreateUserBadgesTable extends AbstractMigration
{
public function change()
{
$table = $this->table('user_badges');
$table
->addColumn('guid', 'string')
->addColumn('user_id', 'integer', ['signed' => false, 'null' => false])
->addColumn('badge', 'string')

->addForeignKey('user_id', 'users', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])

->addIndex(['guid'], ['unique' => true])

->create();
}
}