creating migration pages
This commit is contained in:
parent
4c4fc95da3
commit
cc9985eb1d
5 changed files with 156 additions and 0 deletions
|
@ -113,6 +113,12 @@ namespace BirdsiteLive.Domain
|
|||
type = "PropertyValue",
|
||||
name = "Official",
|
||||
value = $"<a href=\"https://twitter.com/{acct}\" rel=\"me nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">twitter.com/{acct}</span></a>"
|
||||
},
|
||||
new UserAttachment
|
||||
{
|
||||
type = "PropertyValue",
|
||||
name = "Disclaimer",
|
||||
value = "This is an automatically created and managed mirror profile from Twitter. While it reflects exactly the content of the original account, it doesn't provide support for interactions and replies. It is an equivalent view from other 3rd party Twitter client apps and uses the same technical means to provide it."
|
||||
}
|
||||
},
|
||||
endpoints = new EndPoints
|
||||
|
|
86
src/BirdsiteLive/Controllers/MigrationController.cs
Normal file
86
src/BirdsiteLive/Controllers/MigrationController.cs
Normal file
|
@ -0,0 +1,86 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Npgsql.TypeHandlers;
|
||||
|
||||
namespace BirdsiteLive.Controllers
|
||||
{
|
||||
public class MigrationController : Controller
|
||||
{
|
||||
[HttpGet]
|
||||
[Route("/migration/{id}")]
|
||||
public IActionResult Index(string id)
|
||||
{
|
||||
var migrationCode = GetMigrationCode(id);
|
||||
var data = new MigrationData()
|
||||
{
|
||||
Acct = id,
|
||||
MigrationCode = migrationCode
|
||||
};
|
||||
|
||||
return View(data);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("/migration/{id}")]
|
||||
public IActionResult Migrate(string id, string tweetid, string handle)
|
||||
{
|
||||
var migrationCode = GetMigrationCode(id);
|
||||
var data = new MigrationData()
|
||||
{
|
||||
Acct = id,
|
||||
MigrationCode = migrationCode,
|
||||
|
||||
IsAcctProvided = !string.IsNullOrWhiteSpace(handle),
|
||||
IsTweetProvided = !string.IsNullOrWhiteSpace(tweetid),
|
||||
|
||||
TweetId = tweetid,
|
||||
FediverseAccount = handle
|
||||
};
|
||||
|
||||
return View("Index", data);
|
||||
}
|
||||
|
||||
public byte[] GetHash(string inputString)
|
||||
{
|
||||
using (HashAlgorithm algorithm = SHA256.Create())
|
||||
return algorithm.ComputeHash(Encoding.UTF8.GetBytes(inputString));
|
||||
}
|
||||
|
||||
public string GetHashString(string inputString)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (byte b in GetHash(inputString))
|
||||
sb.Append(b.ToString("X2"));
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public string GetMigrationCode(string acct)
|
||||
{
|
||||
var hash = GetHashString(acct);
|
||||
return $"[[BirdsiteLIVE-MigrationCode|{hash.Substring(0, 10)}]]";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class MigrationData
|
||||
{
|
||||
public string Acct { get; set; }
|
||||
|
||||
public string FediverseAccount { get; set; }
|
||||
public string TweetId { get; set; }
|
||||
|
||||
public string MigrationCode { get; set; }
|
||||
|
||||
public bool IsTweetProvided { get; set; }
|
||||
public bool IsAcctProvided { get; set; }
|
||||
|
||||
public bool IsTweetValid { get; set; }
|
||||
public bool IsAcctValid { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
}
|
||||
}
|
45
src/BirdsiteLive/Views/Migration/Index.cshtml
Normal file
45
src/BirdsiteLive/Views/Migration/Index.cshtml
Normal file
|
@ -0,0 +1,45 @@
|
|||
@model BirdsiteLive.Controllers.MigrationData
|
||||
@{
|
||||
ViewData["Title"] = "Migration";
|
||||
}
|
||||
|
||||
<div class="col-12 col-sm-10 col-md-8 col-lg-6 mx-auto">
|
||||
<h1 class="display-4 migration__title">Migrate @@@ViewData.Model.Acct</h1>
|
||||
|
||||
@if (!ViewData.Model.IsAcctProvided && !ViewData.Model.IsAcctProvided)
|
||||
{
|
||||
<h2 class="display-4 migration__subtitle">What is needed?</h2>
|
||||
|
||||
<p>You'll need a Fediverse account and access to the Twitter account to provide proof of ownership.</p>
|
||||
|
||||
<h2 class="display-4 migration__subtitle">What will migration do?</h2>
|
||||
|
||||
<p>Migration will transfer the followers to the provided account.<br/>
|
||||
After a week, the account will be deleted. It will also be blacklisted so that it can't be recreated.</p>
|
||||
}
|
||||
|
||||
<h2 class="display-4 migration__subtitle">Start the migration!</h2>
|
||||
|
||||
<p>Please copy and post this string in a Tweet (the string must be untampered, but you can write anything you want before or after it):</p>
|
||||
|
||||
<input type="text" name="textbox" value="@ViewData.Model.MigrationCode" onclick="this.select()" class="form-control" readonly />
|
||||
<br/>
|
||||
|
||||
<h2 class="display-4 migration__subtitle">Provide migration information:</h2>
|
||||
<form method="POST">
|
||||
@*<div class="form-group">
|
||||
<label for="exampleInputEmail1">Email address</label>
|
||||
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
|
||||
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
|
||||
</div>*@
|
||||
<div class="form-group">
|
||||
<label for="handle">Fediverse target account</label>
|
||||
<input type="text" class="form-control" id="handle" name="handle" autocomplete="off" placeholder="@Html.Raw("@username@domain.ext")" value="@ViewData.Model.FediverseAccount">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="tweetid">Tweet URL</label>
|
||||
<input type="text" class="form-control" id="tweetid" name="tweetid" autocomplete="off" placeholder="https://twitter.com/<username>/status/<tweet id>" value="@ViewData.Model.TweetId">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Migrate!</button>
|
||||
</form>
|
||||
</div>
|
|
@ -45,4 +45,8 @@
|
|||
<input type="text" name="textbox" value="@ViewData.Model.InstanceHandle" onclick="this.select()" class="form-control" readonly />
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="user-owner">
|
||||
<a href="/migration/@ViewData.Model.Acct">I'm the owner of this account and I'm now on the Fediverse</a>
|
||||
</div>
|
||||
</div>
|
|
@ -71,3 +71,18 @@
|
|||
margin-left: 60px;
|
||||
/*font-weight: bold;*/
|
||||
}
|
||||
|
||||
.user-owner {
|
||||
font-size: .8em;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
/** Migration **/
|
||||
|
||||
.migration__title {
|
||||
font-size: 1.8em;
|
||||
}
|
||||
|
||||
.migration__subtitle {
|
||||
font-size: 1.4em;
|
||||
}
|
Reference in a new issue