You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.3 KiB
77 lines
2.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using APP.Models;
|
|
using APP.Utils;
|
|
using BWPMModels;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace APP.Controllers
|
|
{
|
|
public class AccountController : Controller
|
|
{
|
|
private readonly UserManager<AppUser> _userManager;
|
|
private readonly SignInManager<AppUser> _signInManager;
|
|
public AccountController(UserManager<AppUser> userManager, SignInManager<AppUser> signInManager)
|
|
{
|
|
this._userManager = userManager;
|
|
this._signInManager = signInManager;
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Login()
|
|
{
|
|
|
|
return View();
|
|
}
|
|
|
|
[HttpGet]
|
|
//[Authorize]
|
|
public IActionResult Welcome()
|
|
{
|
|
ViewBag.sessionvariable = HttpContext.Session.GetString("SessionVariable1");
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> Login(LoginViewModel model)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return View(model);
|
|
}
|
|
|
|
model.Email = model.Email.Trim();
|
|
|
|
var appUser = await _userManager.FindByEmailAsync(model.Email).ConfigureAwait(false);
|
|
if (appUser == null)
|
|
{
|
|
ModelState.AddModelError("FileNameValidation", "Account does not exist.");
|
|
return View(model);
|
|
}
|
|
|
|
var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, true, lockoutOnFailure: false).ConfigureAwait(false);
|
|
if (result.Succeeded)
|
|
{
|
|
HttpContext.Session.SetString("LoggendIn", "True");
|
|
return RedirectToAction("Welcome", "Account");
|
|
}
|
|
|
|
ModelState.AddModelError("FileNameValidation", "Password does not match.");
|
|
ViewBag.message = "Ungültige Eingabe von User/Passwort";
|
|
|
|
return View(model);
|
|
}
|
|
|
|
public async Task<IActionResult> Logout()
|
|
{
|
|
await _signInManager.SignOutAsync().ConfigureAwait(false);
|
|
HttpContext.Session.SetString("LoggendIn", "false");
|
|
return Redirect("/");
|
|
}
|
|
}
|
|
} |