Exemplo n.º 1
0
        /// <summary>
        /// </summary>
        private void SignOut()
        {
            MessageBoxResult response = MessageBox.Show(
                StringResources.MessageBox_ResetSettings_Message,
                StringResources.MessageBox_ResetSettings_Title,
                MessageBoxButton.OKCancel);

            if (response == MessageBoxResult.Cancel)
            {
                return;
            }
            try
            {
                PlayState playState = BackgroundAudioPlayer.Instance.PlayerState;
                switch (playState)
                {
                case PlayState.Paused:
                case PlayState.Playing:
                case PlayState.BufferingStarted:
                case PlayState.BufferingStopped:
                case PlayState.TrackReady:
                case PlayState.TrackEnded:
                case PlayState.Rewinding:
                case PlayState.FastForwarding:
                    BackgroundAudioPlayer.Instance.Stop();
                    break;

                default:
                    break;
                }
            }
            catch (InvalidOperationException)
            {
                // Background audio resources no longer available
            }

            this.ShowProgress(StringResources.Progress_Loading);
            this.AddToLifetime(
                this.profileService.ResetAsync().ObserveOnDispatcher().Subscribe(
                    _ => { },
                    () =>
            {
                this.UserName      = null;
                this.Password      = null;
                this.loginResponse = null;
                this.currentUserIdChanges.OnNext(null);

                this.CanLogin   = true;
                this.IsLoggedIn = false;
                this.HideProgress();
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// </summary>
        /// <param name="user">
        /// </param>
        private void LoadLoginResponse(UserLoginResponseContract user)
        {
            this.loginResponse = user;
            if (this.loginResponse == null || this.loginResponse.CurrentUser == null)
            {
                this.IsLoggedIn = false;
                this.CanLogin   = true;
                return;
            }

            this.IsLoggedIn = true;
            this.CanLogin   = false;
            this.currentUserIdChanges.OnNext(this.loginResponse.CurrentUser.Id);
        }
        public async Task <ActionResult <UserLoginResponseContract> > Authenticate([FromBody] UserForAuthenticationContract userForAuthContract)
        {
            User user = await this.userManager.FindByNameAsync(userForAuthContract.UserName);

            // no username in our base
            if (user is null)
            {
                return(Unauthorized(new ErrorDetails()
                {
                    StatusCode = StatusCodes.Status401Unauthorized,
                    Message = "Wrong password or login."
                }));
            }

            var passCheck = await this.signInManager.CheckPasswordSignInAsync(user, userForAuthContract.Password, true);

            // Check password correct.
            if (!passCheck.Succeeded)
            {
                int leftAttempts = userManager.Options.Lockout.MaxFailedAccessAttempts - user.AccessFailedCount;
                return(Unauthorized(new ErrorDetails()
                {
                    StatusCode = StatusCodes.Status401Unauthorized,
                    Message = passCheck.IsLockedOut ? $"The account is blocked to {user.LockoutEnd}" : $"Wrong password or login. {leftAttempts} login attempts remaining."
                }));
            }

            var roles = await this.userManager.GetRolesAsync(user);

            UserLoginResponseContract res = new UserLoginResponseContract()
            {
                UserName     = user.UserName,
                UserId       = user.Id.ToString(),
                UserFullName = $"{user.FirstName} {user.LastName}",
                Token        = await this.authManager.CreateToken(user),
                Roles        = roles.ToArray()
            };

            return(Ok(res));
        }
Exemplo n.º 4
0
 /// <summary>
 /// </summary>
 /// <param name="login">
 /// </param>
 /// <returns>
 /// </returns>
 private IObservable <PortableUnit> SaveUserTokenAsync(UserLoginResponseContract login)
 {
     return(this.storage.SaveJsonAsync(UserLoginFilePath, login));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Loads the login response
 /// </summary>
 /// <param name="u"></param>
 /// <returns></returns>
 private string LoadCurrentUser(UserLoginResponseContract u)
 {
     return(this.UserId = u != null && u.CurrentUser != null ? u.CurrentUser.Id : null);
 }