示例#1
0
        public async Task <IHttpActionResult> PasswordSignIn([FromBody] SignInCredentials credentials)
        {
            var userName = credentials?.Username;
            var password = credentials?.Password;

            using (var signInManager = _signInManagerFactory())
            {
                var status = await signInManager.PasswordSignInAsync(userName, password, false, shouldLockout : true);

                var result = new SignInResult {
                    Status = status
                };

                if (result.Status == Microsoft.AspNet.Identity.Owin.SignInStatus.Success)
                {
                    var user = await _securityService.FindByNameAsync(userName, UserDetails.Full);

                    //Do not allow to login rejected users
                    if (user != null && user.UserState == AccountState.Rejected)
                    {
                        result.Status = Microsoft.AspNet.Identity.Owin.SignInStatus.LockedOut;
                    }
                }

                return(Ok(result));
            }
        }
        public async Task <IActionResult> Login(SignInCredentials credentials)
        {
            if (!ModelState.IsValid)
            {
                return(View(credentials));
            }

            var user = await userManager.FindByNameAsync(credentials.UserName);

            if (user is null)
            {
                ModelState.AddModelError(String.Empty, "Invalid credentials.");
                return(View());
            }

            var result = await signInManager.PasswordSignInAsync(user, credentials.Password, credentials.RememberMe, false);

            if (!result.Succeeded)
            {
                ModelState.AddModelError(String.Empty, "Invalid credentials.");
                return(View());
            }

            return(RedirectToActionPermanent(nameof(FilmsController.Index), "Films"));
        }
示例#3
0
        private void AttemptSignIn()
        {
            var credentials = new SignInCredentials
            {
                Username = _usernameInputField.text,
                Password = _passwordInputField.text
            };

            var result = _user.AttemptSignIn(credentials);

            if (result == SignInError.None)
            {
                ShowCanvas = false;
                _messager.Publish(new MainMenuSelectedMessage());
            }
            else
            {
                ShowCanvas = false;
                _messager.Publish(new ShowPopUpDialogueMessage
                {
                    AllowCancel  = false,
                    MainDialogue = result.ToString().ToFormalString(),
                    OnConfirmed  = () => ShowCanvas = true
                });
            }
        }
        public IActionResult Authenticate([FromBody] SignInCredentials credentials)
        {
            Business.Domain.Model.User user = _userService.Authenticate(credentials.UserName, credentials.Password);

            if (user == null)
            {
                return(Unauthorized());
            }

            return(Ok(user.Token));
        }
示例#5
0
        public User Authenticate(SignInCredentials signInCredentials)
        {
            signInCredentials.Password = this.Hash(signInCredentials.Password);
            var userModel = UserService.Get(signInCredentials.Username, signInCredentials.Password);

            if (userModel == null)
            {
                return(null);
            }
            AssignToken(userModel);
            return(userModel);
        }
示例#6
0
        public IActionResult Login([FromBody] SignInCredentials signInCredentials)
        {
            var user = _authService.Authenticate(signInCredentials);

            if (user == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            user.Password = null;
            return(Ok(user));
        }
        public SignInError AttemptSignIn(SignInCredentials login)
        {
            // TODO: talk to server

            // for now we'll just build data and assume all is dandy
            _userAccountData = new UserAccountData
            {
                Username = login.Username,
                Password = login.Password
            };

            return(SignInError.None);
        }
        public void RegisterAccount()
        {
            // make sure passwords are the same
            if (_passwordInputField.text != _passwordConfirmationInputField.text)
            {
                ShowCanvas = false;
                _messager.Publish(new ShowPopUpDialogueMessage
                {
                    MainDialogue = LanguageStrings.PasswordMismatchError,
                    AllowCancel  = false,
                    OnConfirmed  = () => ShowCanvas = true
                });

                return;
            }

            // make sure the password meets the min character requirements
            if (_passwordInputField.text.Length < GameConstants.MinPasswordCharacterCount)
            {
                ShowCanvas = false;
                _messager.Publish(new ShowPopUpDialogueMessage
                {
                    MainDialogue = string.Format(LanguageStrings.InsufficientPasswordLength, GameConstants.MinPasswordCharacterCount),
                    AllowCancel  = false,
                    OnConfirmed  = () => ShowCanvas = true
                });

                return;
            }

            // send out our username and password over to serverland
            var login = new SignInCredentials
            {
                Username = _usernameInputField.text,
                Password = _passwordInputField.text
            };

            // TODO: send the sign in details to the server and get result
            var error = RegistrationAttemptError.None;

            // TODO: for now we just user no error

            if (error == RegistrationAttemptError.None)
            {
                ShowCanvas = false;
                _messager.Publish(new ShowPopUpDialogueMessage
                {
                    MainDialogue = LanguageStrings.AccountCreationSuccess,
                    AllowCancel  = false,
                    OnConfirmed  = () => _currentAccountCreationSession.OnConfirmed(login)
                });
            }
            else
            {
                ShowCanvas = false;
                _messager.Publish(new ShowPopUpDialogueMessage
                {
                    MainDialogue = error.ToString().ToFormalString(),
                    AllowCancel  = false,
                    OnConfirmed  = () => ShowCanvas = true
                });
            }
        }