- 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.master
@@ -1,4 +1,6 @@ | |||
using System; | |||
using Newtonsoft.Json; | |||
using Newtonsoft.Json.Linq; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Net; | |||
@@ -46,7 +48,7 @@ namespace Teknik.GitService | |||
return false; | |||
} | |||
public void CreateAccount(string username, string email, string password) | |||
public void CreateAccount(string username, string email, string password, string authId) | |||
{ | |||
// Add gogs user | |||
using (var client = new WebClient()) | |||
@@ -57,6 +59,13 @@ namespace Teknik.GitService | |||
Uri baseUri = new Uri(_host); | |||
Uri finalUri = new Uri(baseUri, "api/v1/admin/users?token=" + _accessToken); | |||
string result = client.UploadString(finalUri, "POST", json); | |||
JObject resultJson = JObject.Parse(result); | |||
// Add an external auth for them | |||
MysqlDatabase mySQL = new MysqlDatabase(_server, _database, _username, _password, _port); | |||
string sql = @"INSERT INTO gogs.external_login_user (external_id, user_id, login_source_id) VALUES ({0}, {1}, {2})"; | |||
var results = mySQL.Query(sql, new object[] { authId, resultJson["id"], _sourceId }); | |||
} | |||
} | |||
@@ -10,7 +10,7 @@ namespace Teknik.GitService | |||
DateTime LastActive(string username); | |||
void CreateAccount(string username, string email, string password); | |||
void CreateAccount(string username, string email, string password, string authId); | |||
void EditPassword(string username, string email, string password); | |||
@@ -23,6 +23,7 @@ using Teknik.IdentityServer.Models; | |||
using Microsoft.Extensions.Logging; | |||
using Teknik.Logging; | |||
using Teknik.Configuration; | |||
using Teknik.Utilities; | |||
namespace Teknik.IdentityServer.Controllers | |||
{ | |||
@@ -306,12 +307,16 @@ namespace Teknik.IdentityServer.Controllers | |||
[HttpOptions] | |||
public async Task Logout() | |||
{ | |||
if (User?.Identity.IsAuthenticated == true) | |||
try | |||
{ | |||
await _signInManager.SignOutAsync(); | |||
// raise the logout event | |||
await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName())); | |||
if (User?.Identity?.IsAuthenticated == true) | |||
{ | |||
await _signInManager.SignOutAsync(); | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
_logger.LogError(ex.GetFullMessage(true, true)); | |||
} | |||
} | |||
@@ -73,7 +73,7 @@ namespace Teknik.IdentityServer.Controllers | |||
var result = await _userManager.CreateAsync(identityUser, model.Password); | |||
if (result.Succeeded) | |||
{ | |||
return new JsonResult(new { success = true }); | |||
return new JsonResult(new { success = true, data = identityUser.Id }); | |||
} | |||
return new JsonResult(new { success = false, message = "Unable to create user.", identityErrors = result.Errors }); |
@@ -41,6 +41,11 @@ namespace Teknik.IdentityServer | |||
public void ConfigureServices(IServiceCollection services) | |||
{ | |||
string dataDir = Configuration["ConfigDirectory"]; | |||
if (string.IsNullOrEmpty(dataDir)) | |||
{ | |||
string baseDir = Environment.ContentRootPath; | |||
dataDir = Path.Combine(baseDir, "App_Data"); | |||
} | |||
AppDomain.CurrentDomain.SetData("DataDirectory", dataDir); | |||
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name; |
@@ -41,6 +41,7 @@ namespace Teknik.Areas.Users.Controllers | |||
{ | |||
[Authorize] | |||
[Area("User")] | |||
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)] | |||
public class UserController : DefaultController | |||
{ | |||
private static readonly UsedCodesManager usedCodesManager = new UsedCodesManager(); | |||
@@ -62,7 +63,6 @@ namespace Teknik.Areas.Users.Controllers | |||
} | |||
[HttpGet] | |||
[TrackPageView] | |||
public IActionResult Login(string returnUrl) | |||
{ | |||
// Let's double check their email and git accounts to make sure they exist |
@@ -142,6 +142,9 @@ namespace Teknik.Areas.Users.Utility | |||
var result = await IdentityHelper.CreateUser(config, username, password, recoveryEmail); | |||
if (result.Success) | |||
{ | |||
// Get the userId passed back | |||
string userId = (string)result.Data; | |||
// Create an Email Account | |||
CreateUserEmail(config, GetUserEmailAddress(config, username), password); | |||
@@ -149,7 +152,7 @@ namespace Teknik.Areas.Users.Utility | |||
DisableUserEmail(config, GetUserEmailAddress(config, username)); | |||
// Create a Git Account | |||
CreateUserGit(config, username, password); | |||
CreateUserGit(config, username, password, userId); | |||
// Add User | |||
User newUser = CreateUser(db, config, username, inviteCode); | |||
@@ -217,21 +220,17 @@ namespace Teknik.Areas.Users.Utility | |||
{ | |||
// Make sure they have a git and email account before resetting their password | |||
string email = GetUserEmailAddress(config, username); | |||
if (config.EmailConfig.Enabled && !UserEmailExists(config, email)) | |||
if (config.EmailConfig.Enabled && UserEmailExists(config, email)) | |||
{ | |||
CreateUserEmail(config, email, newPassword); | |||
// Change email password | |||
EditUserEmailPassword(config, GetUserEmailAddress(config, username), newPassword); | |||
} | |||
if (config.GitConfig.Enabled && !UserGitExists(config, username)) | |||
if (config.GitConfig.Enabled && UserGitExists(config, username)) | |||
{ | |||
CreateUserGit(config, username, newPassword); | |||
// Update Git password | |||
EditUserGitPassword(config, username, newPassword); | |||
} | |||
// Change email password | |||
EditUserEmailPassword(config, GetUserEmailAddress(config, username), newPassword); | |||
// Update Git password | |||
EditUserGitPassword(config, username, newPassword); | |||
} | |||
catch (Exception ex) | |||
{ | |||
@@ -854,7 +853,7 @@ If you recieved this email and you did not reset your password, you can ignore t | |||
return lastActive; | |||
} | |||
public static void CreateUserGit(Config config, string username, string password) | |||
public static void CreateUserGit(Config config, string username, string password, string authId) | |||
{ | |||
try | |||
{ | |||
@@ -864,7 +863,7 @@ If you recieved this email and you did not reset your password, you can ignore t | |||
string email = GetUserEmailAddress(config, username); | |||
var svc = CreateGitService(config); | |||
svc.CreateAccount(username, email, password); | |||
svc.CreateAccount(username, email, password, authId); | |||
} | |||
} | |||
catch (Exception ex) |
@@ -26,8 +26,8 @@ | |||
<label for="registerConfirmPassword">Confirm Password <span class="text-danger">*</span></label> | |||
<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"/> | |||
</div> | |||
<div class="form-group"> | |||
<label for="registerInviteCode">Invite Code@(Html.Raw(Config.UserConfig.InviteCodeRequired ? " <span class=\"text-danger\">*</span>" : string.Empty))</label> | |||
<div class="form-group@(Html.Raw(Config.UserConfig.InviteCodeRequired ? string.Empty : " hidden"))"> | |||
<label for="registerInviteCode">Invite Code <span class="text-danger">*</span></label> | |||
<input type="text" class="form-control" id="registerInviteCode" value="@Model.InviteCode" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" name="Register.InviteCode"/> | |||
</div> | |||
<div class="form-group"> |
@@ -9,6 +9,10 @@ body { | |||
body { padding-top: 70px; } | |||
.nav-up { | |||
top: -50px; | |||
} | |||
/* Wrapper for page content to push down footer */ | |||
#wrap { | |||
min-height: 100%; |
@@ -75,8 +75,10 @@ namespace Teknik.Controllers | |||
[AllowAnonymous] | |||
public IActionResult Robots([FromServices] IHostingEnvironment env) | |||
{ | |||
//string file = FileHelper.MapPath(env, Constants.ROBOTS_PATH); | |||
return File(Constants.ROBOTS_PATH, "text/plain"); | |||
string dataDir = (string)AppDomain.CurrentDomain.GetData("DataDirectory"); | |||
string file = Path.Combine(dataDir, Constants.ROBOTS_PATH); | |||
FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); | |||
return File(fs, "text/plain"); | |||
} | |||
protected IActionResult GenerateActionResult(object json) |
@@ -6,7 +6,7 @@ namespace Teknik.Utilities | |||
public const string TRUSTEDDEVICECOOKIE = "TeknikTrustedDevice"; | |||
public const string LOGO_PATH = "images/logo-black.svg"; | |||
public const string FAVICON_PATH = "images/favicon.ico"; | |||
public const string ROBOTS_PATH = "~/App_Data/robots.txt"; | |||
public const string ROBOTS_PATH = "robots.txt"; | |||
public const string LOG_FILE_NAME_PREFIX = "Teknik"; | |||
public const string LOG_FILE_EXT = ".log"; |