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
public class UserRegisterModel | |
{ | |
public string Username { get; set; } | |
public string Password { get; set; } | |
} |
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
public class AuthController : Controller | |
{ | |
private ApplicationDbContext _db; | |
private SignInManager<IdentityUser> _signInManager; | |
private UserManager<IdentityUser> _userManager; | |
public AuthController(ApplicationDbContext db, SignInManager<IdentityUser> signin, UserManager<IdentityUser> usermanager) | |
{ | |
_db = db; | |
_signInManager = signin; |
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
[HttpGet] | |
public string GeneratePassword() | |
{ | |
var options = _userManager.Options.Password; | |
int length = options.RequiredLength; | |
bool nonAlphanumeric = options.RequireNonAlphanumeric; | |
bool digit = options.RequireDigit; | |
bool lowercase = options.RequireLowercase; |
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
[HttpGet] | |
public IActionResult Register() | |
{ | |
return View(); | |
} | |
[HttpPost] | |
public async Task<IActionResult> Register(UserRegisterModel model) | |
{ | |
var exists = _db.Users.SingleOrDefault(u => u.Email.Equals(model.Username)); |
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
@model RandomPassword.Models.UserRegisterModel | |
@{ | |
ViewData["Title"] = "Register"; | |
} | |
<h2>Register</h2> | |
<h4>UserRegisterModel</h4> | |
<hr /> |
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
[HttpGet] | |
public IActionResult Login() | |
{ | |
return View(); | |
} | |
[HttpPost] | |
public async Task<IActionResult> Login(UserRegisterModel model) | |
{ | |
var exists = _db.Users.SingleOrDefault(u => u.Email.Equals(model.Username)); |
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
[HttpGet] | |
public IActionResult Login() | |
{ | |
return View(); | |
} | |
[HttpPost] | |
public async Task<IActionResult> Login(UserRegisterModel model) | |
{ | |
var exists = _db.Users.SingleOrDefault(u => u.Email.Equals(model.Username)); |
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
public class TestController : Controller | |
{ | |
private HttpClient _client; | |
public TestController() | |
{ | |
_client = new HttpClient(); | |
_client.BaseAddress = new Uri("http://example.com/api"); | |
} | |
} |
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
public class RequestSender | |
{ | |
private static HttpClient _CLIENT; | |
public RequestSender() | |
{ | |
if (_CLIENT == null) | |
{ | |
_CLIENT = new HttpClient(); | |
_CLIENT.BaseAddress = new Uri("http://example.com/api/"); |
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
public class RequestSender | |
{ | |
private static Dictionary<string, HttpClient> _CLIENTS = new Dictionary<string, HttpClient>(); | |
private HttpClient _client; | |
public RequestSender(string baseURI) | |
{ | |
var value = _CLIENTS.GetValueOrDefault(baseURI); | |
if (value == null) |