mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
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.
This commit is contained in:
parent
be5d5a49aa
commit
b2abba1825
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
@ -46,7 +48,7 @@ namespace Teknik.GitService
|
|||||||
return false;
|
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
|
// Add gogs user
|
||||||
using (var client = new WebClient())
|
using (var client = new WebClient())
|
||||||
@ -57,6 +59,13 @@ namespace Teknik.GitService
|
|||||||
Uri baseUri = new Uri(_host);
|
Uri baseUri = new Uri(_host);
|
||||||
Uri finalUri = new Uri(baseUri, "api/v1/admin/users?token=" + _accessToken);
|
Uri finalUri = new Uri(baseUri, "api/v1/admin/users?token=" + _accessToken);
|
||||||
string result = client.UploadString(finalUri, "POST", json);
|
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);
|
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);
|
void EditPassword(string username, string email, string password);
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ using Teknik.IdentityServer.Models;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Teknik.Logging;
|
using Teknik.Logging;
|
||||||
using Teknik.Configuration;
|
using Teknik.Configuration;
|
||||||
|
using Teknik.Utilities;
|
||||||
|
|
||||||
namespace Teknik.IdentityServer.Controllers
|
namespace Teknik.IdentityServer.Controllers
|
||||||
{
|
{
|
||||||
@ -306,12 +307,16 @@ namespace Teknik.IdentityServer.Controllers
|
|||||||
[HttpOptions]
|
[HttpOptions]
|
||||||
public async Task Logout()
|
public async Task Logout()
|
||||||
{
|
{
|
||||||
if (User?.Identity.IsAuthenticated == true)
|
try
|
||||||
{
|
{
|
||||||
await _signInManager.SignOutAsync();
|
if (User?.Identity?.IsAuthenticated == true)
|
||||||
|
{
|
||||||
// raise the logout event
|
await _signInManager.SignOutAsync();
|
||||||
await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
|
}
|
||||||
|
}
|
||||||
|
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);
|
var result = await _userManager.CreateAsync(identityUser, model.Password);
|
||||||
if (result.Succeeded)
|
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 });
|
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)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
string dataDir = Configuration["ConfigDirectory"];
|
string dataDir = Configuration["ConfigDirectory"];
|
||||||
|
if (string.IsNullOrEmpty(dataDir))
|
||||||
|
{
|
||||||
|
string baseDir = Environment.ContentRootPath;
|
||||||
|
dataDir = Path.Combine(baseDir, "App_Data");
|
||||||
|
}
|
||||||
AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
|
AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
|
||||||
|
|
||||||
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
|
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
|
||||||
|
@ -41,6 +41,7 @@ namespace Teknik.Areas.Users.Controllers
|
|||||||
{
|
{
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[Area("User")]
|
[Area("User")]
|
||||||
|
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
public class UserController : DefaultController
|
public class UserController : DefaultController
|
||||||
{
|
{
|
||||||
private static readonly UsedCodesManager usedCodesManager = new UsedCodesManager();
|
private static readonly UsedCodesManager usedCodesManager = new UsedCodesManager();
|
||||||
@ -62,7 +63,6 @@ namespace Teknik.Areas.Users.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[TrackPageView]
|
|
||||||
public IActionResult Login(string returnUrl)
|
public IActionResult Login(string returnUrl)
|
||||||
{
|
{
|
||||||
// Let's double check their email and git accounts to make sure they exist
|
// 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);
|
var result = await IdentityHelper.CreateUser(config, username, password, recoveryEmail);
|
||||||
if (result.Success)
|
if (result.Success)
|
||||||
{
|
{
|
||||||
|
// Get the userId passed back
|
||||||
|
string userId = (string)result.Data;
|
||||||
|
|
||||||
// Create an Email Account
|
// Create an Email Account
|
||||||
CreateUserEmail(config, GetUserEmailAddress(config, username), password);
|
CreateUserEmail(config, GetUserEmailAddress(config, username), password);
|
||||||
|
|
||||||
@ -149,7 +152,7 @@ namespace Teknik.Areas.Users.Utility
|
|||||||
DisableUserEmail(config, GetUserEmailAddress(config, username));
|
DisableUserEmail(config, GetUserEmailAddress(config, username));
|
||||||
|
|
||||||
// Create a Git Account
|
// Create a Git Account
|
||||||
CreateUserGit(config, username, password);
|
CreateUserGit(config, username, password, userId);
|
||||||
|
|
||||||
// Add User
|
// Add User
|
||||||
User newUser = CreateUser(db, config, username, inviteCode);
|
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
|
// Make sure they have a git and email account before resetting their password
|
||||||
string email = GetUserEmailAddress(config, username);
|
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)
|
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;
|
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
|
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);
|
string email = GetUserEmailAddress(config, username);
|
||||||
|
|
||||||
var svc = CreateGitService(config);
|
var svc = CreateGitService(config);
|
||||||
svc.CreateAccount(username, email, password);
|
svc.CreateAccount(username, email, password, authId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
<label for="registerConfirmPassword">Confirm Password <span class="text-danger">*</span></label>
|
<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"/>
|
<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>
|
||||||
<div class="form-group">
|
<div class="form-group@(Html.Raw(Config.UserConfig.InviteCodeRequired ? string.Empty : " hidden"))">
|
||||||
<label for="registerInviteCode">Invite Code@(Html.Raw(Config.UserConfig.InviteCodeRequired ? " <span class=\"text-danger\">*</span>" : string.Empty))</label>
|
<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"/>
|
<input type="text" class="form-control" id="registerInviteCode" value="@Model.InviteCode" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" name="Register.InviteCode"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -9,6 +9,10 @@ body {
|
|||||||
|
|
||||||
body { padding-top: 70px; }
|
body { padding-top: 70px; }
|
||||||
|
|
||||||
|
.nav-up {
|
||||||
|
top: -50px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Wrapper for page content to push down footer */
|
/* Wrapper for page content to push down footer */
|
||||||
#wrap {
|
#wrap {
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
|
@ -75,8 +75,10 @@ namespace Teknik.Controllers
|
|||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public IActionResult Robots([FromServices] IHostingEnvironment env)
|
public IActionResult Robots([FromServices] IHostingEnvironment env)
|
||||||
{
|
{
|
||||||
//string file = FileHelper.MapPath(env, Constants.ROBOTS_PATH);
|
string dataDir = (string)AppDomain.CurrentDomain.GetData("DataDirectory");
|
||||||
return File(Constants.ROBOTS_PATH, "text/plain");
|
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)
|
protected IActionResult GenerateActionResult(object json)
|
||||||
|
@ -6,7 +6,7 @@ namespace Teknik.Utilities
|
|||||||
public const string TRUSTEDDEVICECOOKIE = "TeknikTrustedDevice";
|
public const string TRUSTEDDEVICECOOKIE = "TeknikTrustedDevice";
|
||||||
public const string LOGO_PATH = "images/logo-black.svg";
|
public const string LOGO_PATH = "images/logo-black.svg";
|
||||||
public const string FAVICON_PATH = "images/favicon.ico";
|
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_NAME_PREFIX = "Teknik";
|
||||||
public const string LOG_FILE_EXT = ".log";
|
public const string LOG_FILE_EXT = ".log";
|
||||||
|
Loading…
Reference in New Issue
Block a user