From cc9985eb1def29e336b25a3877c010710d64c2a9 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Tue, 1 Nov 2022 23:38:54 -0400 Subject: [PATCH] creating migration pages --- src/BirdsiteLive.Domain/UserService.cs | 6 ++ .../Controllers/MigrationController.cs | 86 +++++++++++++++++++ src/BirdsiteLive/Views/Migration/Index.cshtml | 45 ++++++++++ src/BirdsiteLive/Views/Users/Index.cshtml | 4 + src/BirdsiteLive/wwwroot/css/birdsite.css | 15 ++++ 5 files changed, 156 insertions(+) create mode 100644 src/BirdsiteLive/Controllers/MigrationController.cs create mode 100644 src/BirdsiteLive/Views/Migration/Index.cshtml diff --git a/src/BirdsiteLive.Domain/UserService.cs b/src/BirdsiteLive.Domain/UserService.cs index a080180..42cf6d3 100644 --- a/src/BirdsiteLive.Domain/UserService.cs +++ b/src/BirdsiteLive.Domain/UserService.cs @@ -113,6 +113,12 @@ namespace BirdsiteLive.Domain type = "PropertyValue", name = "Official", value = $"https://twitter.com/{acct}" + }, + 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 diff --git a/src/BirdsiteLive/Controllers/MigrationController.cs b/src/BirdsiteLive/Controllers/MigrationController.cs new file mode 100644 index 0000000..a0b84aa --- /dev/null +++ b/src/BirdsiteLive/Controllers/MigrationController.cs @@ -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; } + + } +} diff --git a/src/BirdsiteLive/Views/Migration/Index.cshtml b/src/BirdsiteLive/Views/Migration/Index.cshtml new file mode 100644 index 0000000..dfdf14d --- /dev/null +++ b/src/BirdsiteLive/Views/Migration/Index.cshtml @@ -0,0 +1,45 @@ +@model BirdsiteLive.Controllers.MigrationData +@{ + ViewData["Title"] = "Migration"; +} + +
+

Migrate @@@ViewData.Model.Acct

+ + @if (!ViewData.Model.IsAcctProvided && !ViewData.Model.IsAcctProvided) + { +

What is needed?

+ +

You'll need a Fediverse account and access to the Twitter account to provide proof of ownership.

+ +

What will migration do?

+ +

Migration will transfer the followers to the provided account.
+ After a week, the account will be deleted. It will also be blacklisted so that it can't be recreated.

+ } + +

Start the migration!

+ +

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):

+ + +
+ +

Provide migration information:

+
+ @*
+ + + We'll never share your email with anyone else. +
*@ +
+ + +
+
+ + +
+ +
+
\ No newline at end of file diff --git a/src/BirdsiteLive/Views/Users/Index.cshtml b/src/BirdsiteLive/Views/Users/Index.cshtml index 945964a..8177d6c 100644 --- a/src/BirdsiteLive/Views/Users/Index.cshtml +++ b/src/BirdsiteLive/Views/Users/Index.cshtml @@ -45,4 +45,8 @@ } + +
+ I'm the owner of this account and I'm now on the Fediverse +
\ No newline at end of file diff --git a/src/BirdsiteLive/wwwroot/css/birdsite.css b/src/BirdsiteLive/wwwroot/css/birdsite.css index 5b6023c..159a50a 100644 --- a/src/BirdsiteLive/wwwroot/css/birdsite.css +++ b/src/BirdsiteLive/wwwroot/css/birdsite.css @@ -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; +} \ No newline at end of file