protected async Task InternalLogin(string username, byte[] hash, bool rememberLogin) { var systemInfo = await _apiClient.GetSystemInfoAsync(CancellationToken.None); if (Version.Parse(systemInfo.Version) < RequiredServerVersion) { throw new ApplicationException(string.Format("Media Browser Server is out of date. Please upgrade to {0} or greater.", RequiredServerVersion)); } try { var result = await _apiClient.AuthenticateUserAsync(username, hash); CurrentUser = result.User; _apiClient.SetAuthenticationInfo(result.AccessToken, result.User.Id); UpdateSavedLogin(result.AccessToken, result.User.Id, result.ServerId, rememberLogin); } catch (HttpException ex) { throw new UnauthorizedAccessException("Invalid username or password. Please try again."); } await AfterLogin(); }
public async Task Login(string username, string password) { using (var provider = SHA1.Create()) { var hash = provider.ComputeHash(Encoding.UTF8.GetBytes(password ?? string.Empty)); var result = await _apiClient.AuthenticateUserAsync(username, hash); CurrentUser = result.User; _apiClient.CurrentUserId = CurrentUser.Id; } EventHelper.FireEventIfNotNull(UserLoggedIn, this, EventArgs.Empty, _logger); var userConfig = await _config.GetUserTheaterConfiguration(CurrentUser.Id); var theme = _themeManager.Themes.FirstOrDefault(i => string.Equals(i.Name, userConfig.Theme)) ?? _themeManager.DefaultTheme; await _themeManager.LoadTheme(theme); await _navService.NavigateToHomePage(); _navService.ClearHistory(); }
public async Task LoginToServer(IApiClient apiClient, string username, string password, bool rememberCredentials) { //Check just in case if (password == null) { password = string.Empty; } _connectionManager.SaveLocalCredentials = rememberCredentials; try { var result = await apiClient.AuthenticateUserAsync(username, password); CurrentUser = result.User; _config.Configuration.RememberLogin = rememberCredentials; _config.SaveConfiguration(); } catch (HttpException ex) { throw new UnauthorizedAccessException("Invalid username or password. Please try again."); } await AfterLogin(); }