Skip to content
This repository has been archived by the owner on Apr 19, 2021. It is now read-only.

Commit

Permalink
add file
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinZonda committed Feb 27, 2021
0 parents commit 201f206
Show file tree
Hide file tree
Showing 66 changed files with 40,479 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.vs/
.vscode/
.idea/
**/bin
**/obj
**/config.json
12 changes: 12 additions & 0 deletions Auto-Invitation.Web/Auto-Invitation.Web.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>Auto_Invitation.Web</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Auto-Invitation\Auto-Invitation.csproj" />
</ItemGroup>

</Project>
51 changes: 51 additions & 0 deletions Auto-Invitation.Web/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Net;
using System.Net.Mail;
using Microsoft.AspNetCore.Mvc;

namespace Auto_Invitation.Web.Controllers
{
public class ApiController : Controller
{
[HttpPost]
[Route("/invite")]
public IActionResult Invite(string email = "", string apikey = "")
{
if (email == "" && apikey == "")
{
ViewData["H1"] = "Welcome";
ViewData["Msg"] = "You should add something. :D";
return View();
}

if (!string.IsNullOrWhiteSpace(Shared.Config.Auth) && apikey != Shared.Config.Auth)
{
ViewData["H1"] = "Unauthorized";
ViewData["Msg"] = "You don't have permision to do this! :(";
return View();
}

if (!MailAddress.TryCreate(email, out MailAddress ma))
{
ViewData["H1"] = "Bad Request";
ViewData["Msg"] = "Oops! Maybe your mail address is invalid? :(";
return View();
}

var m = GitHub.InviteToOrg(Shared.Config.Org, ma).Result;

if (m.Status == HttpStatusCode.Created)
{
ViewData["H1"] = "OK";
ViewData["Msg"] = "Thank you for support!\r\nAn mail with invitation will send to your mail soon! :D";
}
else
{
ViewData["H1"] = "Error";
ViewData["Msg"] = "Oops! Something happened! :(";
}

return View();
}
}
}
33 changes: 33 additions & 0 deletions Auto-Invitation.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Auto_Invitation.Web.Models;

namespace Auto_Invitation.Web.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}

public IActionResult Index()
{
return View();
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel {RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier});
}
}
}
9 changes: 9 additions & 0 deletions Auto-Invitation.Web/Models/ConfigModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Auto_Invitation.Web.Models
{
public class ConfigModel
{
public string Api { get; set; }
public string Org { get; set; }
public string Auth { get; set; }
}
}
11 changes: 11 additions & 0 deletions Auto-Invitation.Web/Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Auto_Invitation.Web.Models
{
public class ErrorViewModel
{
public string RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}
35 changes: 35 additions & 0 deletions Auto-Invitation.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Auto_Invitation.Web
{
public class Program
{
public static void Main(string[] args)
{
Shared.Config = JsonSerializer.Deserialize<Models.ConfigModel>(File.ReadAllText("config.json"),
new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
});
if (Shared.Config == null)
throw new ArgumentNullException("Shared.Config is NULL!");

Initialize.Do(Shared.Config.Api);

CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}
}
28 changes: 28 additions & 0 deletions Auto-Invitation.Web/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:31069",
"sslPort": 44346
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Auto_Invitation.Web": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
7 changes: 7 additions & 0 deletions Auto-Invitation.Web/Shared.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Auto_Invitation.Web
{
public class Shared
{
public static Models.ConfigModel Config;
}
}
58 changes: 58 additions & 0 deletions Auto-Invitation.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Auto_Invitation.Web
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
6 changes: 6 additions & 0 deletions Auto-Invitation.Web/Views/Api/Invite.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@{
ViewData["Title"] = "Invite Status";
}
<h1>@ViewData["H1"]</h1>

<p>@ViewData["Msg"]</p>
19 changes: 19 additions & 0 deletions Auto-Invitation.Web/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@{
ViewData["Title"] = "Home Page";
}

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<form action="~/invite" method="post">

<div class="content">
<p>Email: </p>
<input type="email" name="email"/>
<p>Key: </p>
<input type="text" name="apikey"/>
<br>
<br>
<input type="submit" value="Submit"/>
</div>
</form>
</div>
6 changes: 6 additions & 0 deletions Auto-Invitation.Web/Views/Home/Privacy.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>
25 changes: 25 additions & 0 deletions Auto-Invitation.Web/Views/Shared/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@model ErrorViewModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
48 changes: 48 additions & 0 deletions Auto-Invitation.Web/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - LGBT-CN.ORG</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">AUTO LGBT-CN.ORG SYSTEM</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2021 - Auto_Invitation.Web - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
3 changes: 3 additions & 0 deletions Auto-Invitation.Web/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@using Auto_Invitation.Web
@using Auto_Invitation.Web.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
3 changes: 3 additions & 0 deletions Auto-Invitation.Web/Views/_ViewStart.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}
Loading

0 comments on commit 201f206

Please sign in to comment.