mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Added invitre code creation to main admin page.
This commit is contained in:
parent
416387c764
commit
0073e99c6d
@ -158,19 +158,23 @@ namespace Teknik.Areas.Admin.Controllers
|
||||
[ValidateAntiForgeryToken]
|
||||
public IActionResult CreateInviteCode(string username)
|
||||
{
|
||||
if (UserHelper.UserExists(_dbContext, username))
|
||||
{
|
||||
User user = UserHelper.GetUser(_dbContext, username);
|
||||
InviteCode inviteCode = new InviteCode();
|
||||
inviteCode.Active = true;
|
||||
inviteCode.Code = Guid.NewGuid().ToString();
|
||||
inviteCode.Owner = user;
|
||||
_dbContext.InviteCodes.Add(inviteCode);
|
||||
_dbContext.SaveChanges();
|
||||
InviteCode inviteCode = new InviteCode();
|
||||
inviteCode.Active = true;
|
||||
inviteCode.Code = Guid.NewGuid().ToString();
|
||||
|
||||
return Json(new { result = new { code = inviteCode.Code } });
|
||||
if (!string.IsNullOrEmpty(username))
|
||||
{
|
||||
if (!UserHelper.UserExists(_dbContext, username))
|
||||
{
|
||||
return new StatusCodeResult(StatusCodes.Status404NotFound);
|
||||
}
|
||||
User user = UserHelper.GetUser(_dbContext, username);
|
||||
inviteCode.Owner = user;
|
||||
}
|
||||
return new StatusCodeResult(StatusCodes.Status404NotFound);
|
||||
_dbContext.InviteCodes.Add(inviteCode);
|
||||
_dbContext.SaveChanges();
|
||||
|
||||
return Json(new { result = new { code = inviteCode.Code } });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
|
@ -1,5 +1,9 @@
|
||||
@model Teknik.Areas.Admin.ViewModels.DashboardViewModel
|
||||
|
||||
<script>
|
||||
var createInviteCode = '@Url.SubRouteUrl("admin", "Admin.Action", new { action = "CreateInviteCode" })';
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-sm-10 col-sm-offset-1">
|
||||
@ -11,4 +15,11 @@
|
||||
<a href="@Url.SubRouteUrl("admin", "Admin.UploadSearch")">Upload Search</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-10 col-sm-offset-1">
|
||||
<button type="button" class="btn btn-info" id="createInviteCode">Create Invite Code</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<bundle src="js/admin.min.js" append-version="true"></bundle>
|
20
Teknik/Scripts/Admin/Admin.js
Normal file
20
Teknik/Scripts/Admin/Admin.js
Normal file
@ -0,0 +1,20 @@
|
||||
$(function () {
|
||||
$('#createInviteCode').click(function () {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: createInviteCode,
|
||||
data: AddAntiForgeryToken(),
|
||||
success: function (html) {
|
||||
if (html.result) {
|
||||
$("#top_msg").css('display', 'none');
|
||||
$("#top_msg").html('');
|
||||
alert('Successfully created invite code for \'' + username + '\': ' + html.result.code);
|
||||
}
|
||||
else {
|
||||
$("#top_msg").css('display', 'inline', 'important');
|
||||
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' + parseErrorMessage(html) + '</div>');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
@ -1,4 +1,11 @@
|
||||
[
|
||||
{
|
||||
"outputFileName": "./wwwroot/js/admin.min.js",
|
||||
"inputFiles": [
|
||||
"./wwwroot/lib/bootbox/js/bootbox.js",
|
||||
"./wwwroot/js/app/Admin/Admin.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"outputFileName": "./wwwroot/js/uploadSearch.min.js",
|
||||
"inputFiles": [
|
||||
|
Loading…
Reference in New Issue
Block a user