/// <summary> /// Anmelden /// </summary> /// <param name="httpContext"></param> /// <param name="username"></param> /// <param name="password"></param> /// <param name="isPersistent"></param> /// <returns></returns> public async Task <bool> SignInUser(HttpContext httpContext, string username, string password, bool isPersistent = false) { try { RestAccess ra = new RestAccess(Constants.ServiceClientEndPointWithApiPrefix); var user = await ra.UserCheck(username); if (user.Ok && user.Result != null && !user.Result.UserIsLocked && user.Result.UserId > 0) { var hash = PasswordHelper.CumputeHash(password); var userAccountData = await ra.UserAccountData(new ExPostUserPasswortData { UserId = user.Result.UserId, PasswordHash = hash }); if (userAccountData.Ok && userAccountData.Result != null && userAccountData.Result.UserAccountData != null) { ClaimsIdentity identity = new ClaimsIdentity(GetUserClaims(userAccountData.Result.UserAccountData), CookieAuthenticationDefaults.AuthenticationScheme); ClaimsPrincipal principal = new ClaimsPrincipal(identity); await httpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); return(true); } } } catch (Exception) { return(false); } return(false); }
/// <summary> /// Anmelden /// </summary> /// <param name="httpContext"></param> /// <param name="username"></param> /// <param name="password"></param> /// <param name="isPersistent"></param> /// <returns></returns> public async Task <bool> SignInAdmin(HttpContext httpContext, string username, string password, bool isPersistent = false) { try { RestAccess ra = new RestAccess(Constants.ServiceClientEndPointWithApiPrefix); var user = await ra.UserCheck(username); //if (user.Ok && user.Result != null && !user.Result.UserIsLocked && user.Result.UserId > 0) if (username.ToLower() == "admin" && password == "[PASSWORT]") { //var hash = PasswordHelper.CumputeHash(password); //var userAccountData = await ra.UserAccountData(new ExPostUserPasswortData {UserId = user.Result.UserId, PasswordHash = hash}); //if (userAccountData.Ok && userAccountData.Result != null && userAccountData.Result.UserAccountData != null) var tmp = new ExUserAccountData { IsAdmin = true, FirstName = "Admin", LastName = "Admin", UserId = 1, PhoneNumber = "+43" }; { ClaimsIdentity identity = new ClaimsIdentity(GetUserClaims(tmp), CookieAuthenticationDefaults.AuthenticationScheme); ClaimsPrincipal principal = new ClaimsPrincipal(identity); await httpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); return(true); } } } catch (Exception) { return(false); } return(false); }
public async Task <IActionResult> RegisterUser(RegisterUserViewModel form) { if (!ModelState.IsValid) { return(View(form)); } try { var success = ValidationHelper.ProoveValidPhoneNumber(form.PhoneNumber, out string telNumber); if (!success) { ModelState.AddModelError("PhoneNumber", "Die Telefonnummer hat ein ungültiges Format"); return(View(form)); } var user = await _context.TblUsers.FirstOrDefaultAsync(a => a.PhoneNumber == telNumber); if (user != null) { //ModelState.AddModelError("PhoneNumber", "Diese Telefonnumer existiert bereits im System."); //return View(form); TempData["message"] = "Du bist bereits registriert. Bitte logge dich ein!"; return(RedirectToAction("LoginUser")); } RestAccess ra = new RestAccess(Constants.ServiceClientEndPointWithApiPrefix); var res = await ra.UserCheck(telNumber); if (res.Ok) { if (!res.Result.IsNewUser) { TempData["message"] = "Du bist bereits registriert. Bitte logge dich ein!"; return(RedirectToAction("LoginUser")); } TempData["message"] = "Danke! Um die Registrierung abzuschließen überprüfe bitte deine SMS Nachrichten!"; return(RedirectToAction("LoginUser")); } ViewData["message"] = "Registrierung war nicht erfolgreich. Bitte Eingabe überprüfen!"; return(View(form)); } catch (Exception ex) { ModelState.AddModelError("PhoneNumber", ex.Message); return(View(form)); } }