|
1 | 1 | using System.Collections.Generic; |
2 | 2 | using App.AL.Validation.String; |
3 | | -using App.DL.Model.User; |
4 | | -using App.DL.Model.User.Registration; |
5 | 3 | using App.DL.Module.Email; |
6 | 4 | using App.DL.Repository.User; |
7 | 5 | using App.DL.Repository.User.Registration; |
|
12 | 10 | using Micron.DL.Module.Controller; |
13 | 11 | using Micron.DL.Module.Crypto; |
14 | 12 | using Micron.DL.Module.Http; |
| 13 | +using Micron.DL.Module.Misc; |
15 | 14 | using Micron.DL.Module.Validator; |
16 | 15 | using Nancy; |
17 | 16 | using Newtonsoft.Json.Linq; |
@@ -95,6 +94,45 @@ public JwtAuthController() { |
95 | 94 | }); |
96 | 95 | }); |
97 | 96 |
|
| 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 | + |
98 | 136 | Post("/api/v1/register/confirm_email", _ => { |
99 | 137 | var errors = ValidationProcessor.Process(Request, new IValidatorRule[] { |
100 | 138 | new ShouldHaveParameters(new[] {"confirmation_key"}), |
|
0 commit comments