-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
169 additions
and
136 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
Core.Signalr.Template.Client/Controllers/AccountController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Core.Signalr.Template.Client.Models; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Authentication.Cookies; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.IdentityModel.Tokens; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IdentityModel.Tokens.Jwt; | ||
using System.Security.Claims; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Core.Signalr.Template.Client.Controllers | ||
{ | ||
public class AccountController : Controller | ||
{ | ||
[HttpGet] | ||
[AllowAnonymous] | ||
public IActionResult Login() | ||
{ | ||
if (User.Identity.IsAuthenticated) | ||
{ | ||
return RedirectToAction("Index", "Home"); | ||
} | ||
return View(); | ||
} | ||
|
||
[HttpPost] | ||
[AllowAnonymous] | ||
public async Task<IActionResult> Login(string userName) | ||
{ | ||
if (string.IsNullOrWhiteSpace(userName)) | ||
{ | ||
throw new Exception("用户名不能为空"); | ||
} | ||
|
||
var claims = new List<Claim>() { | ||
new Claim(ClaimTypes.Name,userName), | ||
}; | ||
var claimIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); | ||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimIdentity)); | ||
|
||
return RedirectToAction("Index","Home"); | ||
} | ||
|
||
public async Task<IActionResult> LoginOut() | ||
{ | ||
await HttpContext.SignOutAsync(); | ||
return RedirectToAction(nameof(AccountController.Login), "Account"); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Core.Signalr.Template.Client/Controllers/HomeController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Core.Signalr.Template.Client.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Core.Signalr.Template.Client/Core.Signalr.Template.Client.csproj.user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID> | ||
<Controller_SelectedScaffolderCategoryPath>root/Controller</Controller_SelectedScaffolderCategoryPath> | ||
<WebStackScaffolding_ControllerDialogWidth>600</WebStackScaffolding_ControllerDialogWidth> | ||
<WebStackScaffolding_IsLayoutPageSelected>True</WebStackScaffolding_IsLayoutPageSelected> | ||
<WebStackScaffolding_IsPartialViewSelected>False</WebStackScaffolding_IsPartialViewSelected> | ||
<WebStackScaffolding_IsReferencingScriptLibrariesSelected>True</WebStackScaffolding_IsReferencingScriptLibrariesSelected> | ||
<WebStackScaffolding_LayoutPageFile /> | ||
<WebStackScaffolding_IsAsyncSelected>False</WebStackScaffolding_IsAsyncSelected> | ||
</PropertyGroup> | ||
</Project> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@{ | ||
ViewData["Title"] = "Signalr 登录"; | ||
} | ||
|
||
<div id="pageContent"> | ||
<div class="card"> | ||
<div class="card-header"> | ||
<div class="card-title">登录</div> | ||
</div> | ||
<div class="card-body"> | ||
<form method="post" action="/Account/Login"> | ||
<div class="form-group"> | ||
<label for="userName">用户名</label> | ||
<input autocomplete="off" type="text" class="form-control" name="userName" placeholder="用户名"> | ||
</div> | ||
<button type="submit" class="btn btn-primary">假装登录</button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
@section Scripts{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.