Exemplo n.º 1
0
 public static MockingData GetMockDataService()
 {
     if (_MockingdataService == null)
     {
         _MockingdataService = new MockingData();
         _MockingdataService.InitData();
     }
     return(_MockingdataService);
 }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            DeBank.Library.DAL.MockingData _dataService = DeBank.Library.DAL.MockingData.GetMockDataService();
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    DeBank.Library.Models.User generaluser = new DeBank.Library.Models.User()
                    {
                        Id             = Guid.NewGuid().ToString(),
                        DateOfCreation = DateTime.Now,
                        Name           = Input.Email,
                        Email          = Input.Email,
                        Password       = Input.Password
                    };
                    _dataService.AddUser(generaluser);
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            DeBank.Library.DAL.MockingData _dataService = DeBank.Library.DAL.MockingData.GetMockDataService();
            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    var item = _dataService.ReturnAllUsers().Where(a => a.Name == Input.Email && a.Password == Input.Password).FirstOrDefault();
                    if (item == null)
                    {
                        var generateduser = new DeBank.Library.Models.User()
                        {
                            Id             = Guid.NewGuid().ToString(),
                            DateOfCreation = DateTime.Now,
                            Email          = Input.Email,
                            Name           = Input.Email,
                            Password       = Input.Password
                        };

                        StaticResources.CurrentUser.currentuser = generateduser;
                    }
                    else
                    {
                        StaticResources.CurrentUser.currentuser = item;
                    }
                    TempData["CURRENTUSER"] = item;
                    _logger.LogInformation("User logged in.");
                    return(RedirectToAction("SubAccountsOverview", "RegularUserOverview"));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(Page());
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Exemplo n.º 4
0
        public void AssignStaticresources()
        {
            DeBank.Library.DAL.MockingData _dataService = DeBank.Library.DAL.MockingData.GetMockDataService();

            StaticResources.CurrentUser.currentuser = _dataService.ReturnAllUsers().Where(a => a.Name == Input.Email && a.Password == Input.Password).FirstOrDefault();
        }