Browse Source

Multiple Items:

- Added auto adding external source to git on reg.
- Fixed caching of account pages.
- Removed invite code in registration if it isn't required.
- Fixed robots.txt not loading.
Teknikode 2 months ago
parent
commit
b2abba1825

+ 11
- 2
GitService/GiteaService.cs View File

@@ -1,4 +1,6 @@
1
-using System;
1
+using Newtonsoft.Json;
2
+using Newtonsoft.Json.Linq;
3
+using System;
2 4
 using System.Collections.Generic;
3 5
 using System.Linq;
4 6
 using System.Net;
@@ -46,7 +48,7 @@ namespace Teknik.GitService
46 48
             return false;
47 49
         }
48 50
 
49
-        public void CreateAccount(string username, string email, string password)
51
+        public void CreateAccount(string username, string email, string password, string authId)
50 52
         {
51 53
             // Add gogs user
52 54
             using (var client = new WebClient())
@@ -57,6 +59,13 @@ namespace Teknik.GitService
57 59
                 Uri baseUri = new Uri(_host);
58 60
                 Uri finalUri = new Uri(baseUri, "api/v1/admin/users?token=" + _accessToken);
59 61
                 string result = client.UploadString(finalUri, "POST", json);
62
+
63
+                JObject resultJson = JObject.Parse(result);
64
+
65
+                // Add an external auth for them
66
+                MysqlDatabase mySQL = new MysqlDatabase(_server, _database, _username, _password, _port);
67
+                string sql = @"INSERT INTO gogs.external_login_user (external_id, user_id, login_source_id) VALUES ({0}, {1}, {2})";
68
+                var results = mySQL.Query(sql, new object[] { authId, resultJson["id"], _sourceId });
60 69
             }
61 70
         }
62 71
 

+ 1
- 1
GitService/IGitService.cs View File

@@ -10,7 +10,7 @@ namespace Teknik.GitService
10 10
 
11 11
         DateTime LastActive(string username);
12 12
 
13
-        void CreateAccount(string username, string email, string password);
13
+        void CreateAccount(string username, string email, string password, string authId);
14 14
 
15 15
         void EditPassword(string username, string email, string password);
16 16
 

+ 10
- 5
IdentityServer/Controllers/AccountController.cs View File

@@ -23,6 +23,7 @@ using Teknik.IdentityServer.Models;
23 23
 using Microsoft.Extensions.Logging;
24 24
 using Teknik.Logging;
25 25
 using Teknik.Configuration;
26
+using Teknik.Utilities;
26 27
 
27 28
 namespace Teknik.IdentityServer.Controllers
28 29
 {
@@ -306,12 +307,16 @@ namespace Teknik.IdentityServer.Controllers
306 307
         [HttpOptions]
307 308
         public async Task Logout()
308 309
         {
309
-            if (User?.Identity.IsAuthenticated == true)
310
+            try
310 311
             {
311
-                await _signInManager.SignOutAsync();
312
-
313
-                // raise the logout event
314
-                await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
312
+                if (User?.Identity?.IsAuthenticated == true)
313
+                {
314
+                    await _signInManager.SignOutAsync();
315
+                }
316
+            }
317
+            catch (Exception ex)
318
+            {
319
+                _logger.LogError(ex.GetFullMessage(true, true));
315 320
             }
316 321
         }
317 322
 

+ 1
- 1
IdentityServer/Controllers/ManageController.cs View File

@@ -73,7 +73,7 @@ namespace Teknik.IdentityServer.Controllers
73 73
             var result = await _userManager.CreateAsync(identityUser, model.Password);
74 74
             if (result.Succeeded)
75 75
             {
76
-                return new JsonResult(new { success = true });
76
+                return new JsonResult(new { success = true, data = identityUser.Id });
77 77
             }
78 78
 
79 79
             return new JsonResult(new { success = false, message = "Unable to create user.", identityErrors = result.Errors });

+ 5
- 0
IdentityServer/Startup.cs View File

@@ -41,6 +41,11 @@ namespace Teknik.IdentityServer
41 41
         public void ConfigureServices(IServiceCollection services)
42 42
         {
43 43
             string dataDir = Configuration["ConfigDirectory"];
44
+            if (string.IsNullOrEmpty(dataDir))
45
+            {
46
+                string baseDir = Environment.ContentRootPath;
47
+                dataDir = Path.Combine(baseDir, "App_Data");
48
+            }
44 49
             AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
45 50
 
46 51
             var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

+ 1
- 1
Teknik/Areas/User/Controllers/UserController.cs View File

@@ -41,6 +41,7 @@ namespace Teknik.Areas.Users.Controllers
41 41
 {
42 42
     [Authorize]
43 43
     [Area("User")]
44
+    [ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
44 45
     public class UserController : DefaultController
45 46
     {
46 47
         private static readonly UsedCodesManager usedCodesManager = new UsedCodesManager();
@@ -62,7 +63,6 @@ namespace Teknik.Areas.Users.Controllers
62 63
         }
63 64
 
64 65
         [HttpGet]
65
-        [TrackPageView]
66 66
         public IActionResult Login(string returnUrl)
67 67
         {
68 68
             // Let's double check their email and git accounts to make sure they exist

+ 12
- 13
Teknik/Areas/User/Utility/UserHelper.cs View File

@@ -142,6 +142,9 @@ namespace Teknik.Areas.Users.Utility
142 142
                 var result = await IdentityHelper.CreateUser(config, username, password, recoveryEmail);
143 143
                 if (result.Success)
144 144
                 {
145
+                    // Get the userId passed back
146
+                    string userId = (string)result.Data;
147
+
145 148
                     // Create an Email Account
146 149
                     CreateUserEmail(config, GetUserEmailAddress(config, username), password);
147 150
 
@@ -149,7 +152,7 @@ namespace Teknik.Areas.Users.Utility
149 152
                     DisableUserEmail(config, GetUserEmailAddress(config, username));
150 153
 
151 154
                     // Create a Git Account
152
-                    CreateUserGit(config, username, password);
155
+                    CreateUserGit(config, username, password, userId);
153 156
 
154 157
                     // Add User
155 158
                     User newUser = CreateUser(db, config, username, inviteCode);
@@ -217,21 +220,17 @@ namespace Teknik.Areas.Users.Utility
217 220
             {
218 221
                 // Make sure they have a git and email account before resetting their password
219 222
                 string email = GetUserEmailAddress(config, username);
220
-                if (config.EmailConfig.Enabled && !UserEmailExists(config, email))
223
+                if (config.EmailConfig.Enabled && UserEmailExists(config, email))
221 224
                 {
222
-                    CreateUserEmail(config, email, newPassword);
225
+                    // Change email password
226
+                    EditUserEmailPassword(config, GetUserEmailAddress(config, username), newPassword);
223 227
                 }
224 228
 
225
-                if (config.GitConfig.Enabled && !UserGitExists(config, username))
229
+                if (config.GitConfig.Enabled && UserGitExists(config, username))
226 230
                 {
227
-                    CreateUserGit(config, username, newPassword);
231
+                    // Update Git password
232
+                    EditUserGitPassword(config, username, newPassword);
228 233
                 }
229
-
230
-                // Change email password
231
-                EditUserEmailPassword(config, GetUserEmailAddress(config, username), newPassword);
232
-
233
-                // Update Git password
234
-                EditUserGitPassword(config, username, newPassword);
235 234
             }
236 235
             catch (Exception ex)
237 236
             {
@@ -854,7 +853,7 @@ If you recieved this email and you did not reset your password, you can ignore t
854 853
             return lastActive;
855 854
         }
856 855
 
857
-        public static void CreateUserGit(Config config, string username, string password)
856
+        public static void CreateUserGit(Config config, string username, string password, string authId)
858 857
         {
859 858
             try
860 859
             {
@@ -864,7 +863,7 @@ If you recieved this email and you did not reset your password, you can ignore t
864 863
                     string email = GetUserEmailAddress(config, username);
865 864
 
866 865
                     var svc = CreateGitService(config);
867
-                    svc.CreateAccount(username, email, password);
866
+                    svc.CreateAccount(username, email, password, authId);
868 867
                 }
869 868
             }
870 869
             catch (Exception ex)

+ 2
- 2
Teknik/Areas/User/Views/User/Register.cshtml View File

@@ -26,8 +26,8 @@
26 26
             <label for="registerConfirmPassword">Confirm Password <span class="text-danger">*</span></label>
27 27
             <input type="password" class="form-control" id="registerConfirmPassword" value="" placeholder="********" name="Register.ConfirmPassword" data-val-required="The Confirm Password field is required." data-val="true"/>
28 28
         </div>
29
-        <div class="form-group">
30
-            <label for="registerInviteCode">Invite Code@(Html.Raw(Config.UserConfig.InviteCodeRequired ? " <span class=\"text-danger\">*</span>" : string.Empty))</label>
29
+        <div class="form-group@(Html.Raw(Config.UserConfig.InviteCodeRequired ? string.Empty : " hidden"))">
30
+            <label for="registerInviteCode">Invite Code <span class="text-danger">*</span></label>
31 31
             <input type="text" class="form-control" id="registerInviteCode" value="@Model.InviteCode" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" name="Register.InviteCode"/>
32 32
         </div>
33 33
         <div class="form-group">

+ 4
- 0
Teknik/Content/common.css View File

@@ -9,6 +9,10 @@ body {
9 9
 
10 10
 body { padding-top: 70px; }
11 11
 
12
+.nav-up {
13
+    top: -50px;
14
+}
15
+
12 16
 /* Wrapper for page content to push down footer */
13 17
 #wrap {
14 18
   min-height: 100%;

+ 4
- 2
Teknik/Controllers/DefaultController.cs View File

@@ -75,8 +75,10 @@ namespace Teknik.Controllers
75 75
         [AllowAnonymous]
76 76
         public IActionResult Robots([FromServices] IHostingEnvironment env)
77 77
         {
78
-            //string file = FileHelper.MapPath(env, Constants.ROBOTS_PATH);
79
-            return File(Constants.ROBOTS_PATH, "text/plain");
78
+            string dataDir = (string)AppDomain.CurrentDomain.GetData("DataDirectory");
79
+            string file = Path.Combine(dataDir, Constants.ROBOTS_PATH);
80
+            FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);
81
+            return File(fs, "text/plain");
80 82
         }
81 83
 
82 84
         protected IActionResult GenerateActionResult(object json)

+ 1
- 1
Utilities/Constants.cs View File

@@ -6,7 +6,7 @@ namespace Teknik.Utilities
6 6
         public const string TRUSTEDDEVICECOOKIE = "TeknikTrustedDevice";
7 7
         public const string LOGO_PATH = "images/logo-black.svg";
8 8
         public const string FAVICON_PATH = "images/favicon.ico";
9
-        public const string ROBOTS_PATH = "~/App_Data/robots.txt";
9
+        public const string ROBOTS_PATH = "robots.txt";
10 10
 
11 11
         public const string LOG_FILE_NAME_PREFIX = "Teknik";
12 12
         public const string LOG_FILE_EXT = ".log";

Loading…
Cancel
Save