Beispiel #1
0
        public async Task <IActionResult> LoginClassic(InputModels.LoginInput input)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await AccountRepository.Login(input);

                return(await this.RedirectFromService(serviceResponse, FailureCallback));
            }

            return(await FailureCallback());

            async Task <IActionResult> FailureCallback()
            {
                if (UserContext.IsAuthenticated)
                {
                    return(Redirect("/"));
                }

                await AccountRepository.SignOut();

                var viewModel = new ViewModels.Account.LoginPage {
                    Email      = input.Email,
                    RememberMe = input.RememberMe
                };

                return(View(viewModel));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Login(InputModels.LoginInput input)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await AccountRepository.Login(input);

                return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback));
            }

            return(await FailureCallback());

            async Task <IActionResult> FailureCallback()
            {
                if (AccountRepository.IsAuthenticated)
                {
                    return(RedirectToAction(nameof(Home.FrontPage), nameof(Home)));
                }

                await AccountRepository.SignOut();

                var viewModel = new ViewModels.Account.LoginPage {
                    Email      = input.Email,
                    RememberMe = input.RememberMe
                };

                return(ForumViewResult.ViewResult(this, viewModel));
            }
        }
Beispiel #3
0
        public async Task <IActionResult> Login(InputModels.LoginInput input)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await AccountRepository.Login(input);

                return(await this.RedirectFromService(serviceResponse, failSync : FailureCallback));
            }

            return(FailureCallback());

            IActionResult FailureCallback()
            {
                return(RedirectToAction(nameof(LoginClassic)));
            }
        }
Beispiel #4
0
        public async Task <IActionResult> Login(InputModels.LoginInput input)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await AccountRepository.Login(input);

                return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback));
            }

            return(await FailureCallback());

            async Task <IActionResult> FailureCallback()
            {
                return(await Task.Run(() => {
                    var classicLogin = Url.Action(nameof(LoginClassic));
                    return ForumViewResult.RedirectToLocal(this, classicLogin);
                }));
            }
        }
Beispiel #5
0
        public async Task <ServiceModels.ServiceResponse> Login(InputModels.LoginInput input)
        {
            var serviceResponse = new ServiceModels.ServiceResponse();

            var result = await SignInManager.PasswordSignInAsync(input.Email, input.Password, input.RememberMe, lockoutOnFailure : false);

            if (result.IsLockedOut)
            {
                Log.LogWarning($"User account locked out '{input.Email}'.");
                serviceResponse.RedirectPath = UrlHelper.Action(nameof(Account.Lockout), nameof(Account));
            }
            else if (!result.Succeeded)
            {
                Log.LogWarning($"Invalid login attempt for account '{input.Email}'.");
                serviceResponse.Error("Invalid login attempt.");
            }
            else
            {
                Log.LogInformation($"User logged in '{input.Email}'.");
            }

            return(serviceResponse);
        }
Beispiel #6
0
        public async Task <ServiceModels.ServiceResponse> Register(InputModels.RegisterInput input)
        {
            var serviceResponse = new ServiceModels.ServiceResponse();

            if (!input.ConfirmThirteen)
            {
                var message = $"You must be 13 or older to register.";
                serviceResponse.Error(nameof(input.ConfirmThirteen), message);
                Log.LogWarning(message);
            }

            if ((await Records()).Any(r => r.DisplayName == input.DisplayName))
            {
                var message = $"The display name '{input.DisplayName}' is already taken.";
                serviceResponse.Error(nameof(input.DisplayName), message);
                Log.LogWarning(message);
            }

            if (serviceResponse.Success)
            {
                var user = new DataModels.ApplicationUser {
                    DisplayName = input.DisplayName,
                    Registered  = DateTime.Now,
                    Birthday    = DateTime.Now,
                    LastOnline  = DateTime.Now,
                    UserName    = input.Email,
                    Email       = input.Email
                };

                var identityResult = await UserManager.CreateAsync(user, input.Password);

                if (identityResult.Succeeded)
                {
                    var code = await UserManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = EmailConfirmationLink(user.Id, code);

                    if (EmailSender.Ready)
                    {
                        await EmailSender.SendEmailConfirmationAsync(input.Email, callbackUrl);
                    }

                    var loginInput = new InputModels.LoginInput {
                        Email    = input.Email,
                        Password = input.Password
                    };

                    return(await Login(loginInput));
                }
                else
                {
                    foreach (var error in identityResult.Errors)
                    {
                        Log.LogError($"Error registering '{input.Email}'. Message: {error.Description}");
                        serviceResponse.Error(error.Description);
                    }
                }
            }

            return(serviceResponse);
        }