using Bootstrap.Admin.Models; using Bootstrap.DataAccess; using Bootstrap.Security; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Security.Claims; using System.Threading.Tasks; namespace Bootstrap.Admin.Controllers { /// /// Account controller. /// [AllowAnonymous] public class AccountController : Controller { /// /// Login the specified userName, password and remember. /// /// The login. /// User name. /// Password. /// Remember. public async Task Login(string userName, string password, string remember) { if (!string.IsNullOrEmpty(userName) && BootstrapUser.Authenticate(userName, password)) { var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme); identity.AddClaim(new Claim(ClaimTypes.Name, userName)); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity)); return Redirect("~/"); } var mobile = true; //Request.Browser.IsMobileDevice; var model = "IPad"; //Request.Browser.MobileDeviceModel; return mobile && model != "IPad" ? View("Loginm", new ModelBase()) : View("Login", new ModelBase()); } /// /// Logout this instance. /// /// The logout. public async Task Logout() { await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); return Redirect("~" + CookieAuthenticationDefaults.LoginPath); } /// /// Accesses the denied. /// /// The denied. public ActionResult AccessDenied() { return View(); } /// /// /// /// public ActionResult Register(User p) { if (string.IsNullOrEmpty(p.UserName) || string.IsNullOrEmpty(p.Password) || string.IsNullOrEmpty(p.DisplayName) || string.IsNullOrEmpty(p.Description)) return View(); p.UserStatus = 1; return UserHelper.SaveUser(p) ? (ActionResult)Redirect("~/html/RegResult.html") : View(); } /// /// /// /// public ActionResult Mobile() { return View(); } } }