async void Login(PasswordBox password) { if (!Regex.IsMatch(Server, @"[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)")) { await ShowMessageDialog("Server URL is invalid", false); return; } DialogHost.Show(new ProgressDialog(), "RootDialog"); APIResponse result = await MattermostAPI.Login(Server, Team, Username, password.SecurePassword); if (!result.Success) { await ShowMessageDialog(result.Error); return; } LocalStorage.Store("configs", new LocalConfig { Server = Server, Team = Team, Username = Username, UserID = MattermostAPI.MyID, Token = MattermostAPI.Token, TeamID = MattermostAPI.Team.ID, }); LocalStorage.Store("teams", MattermostAPI.Team); APIResponse <List <User> > users = await MattermostAPI.GetUsers(); if (!users.Success) { await ShowMessageDialog(users.Error); return; } Task <APIResponse <Preferences> > preferencesTask = MattermostAPI.GetPreferences(); APIResponse <List <Channel> > channels = await MattermostAPI.GetChannels(); if (!channels.Success) { await ShowMessageDialog(channels.Error); return; } await preferencesTask; mainVM.CurrentView = new MessageViewModel(mainVM, users.Value, channels.Value); DialogHost.CloseDialogCommand.Execute(true, null); }
async void CheckConfig(LocalConfig config) { APIResponse response = await MattermostAPI.CheckSession(config); APIResponse <List <User> > users = await MattermostAPI.GetUsers(); APIResponse <List <Channel> > channels = await MattermostAPI.GetChannels(); APIResponse <Preferences> preferences = await MattermostAPI.GetPreferences(); CurrentView = new MessageViewModel(this, users.Value, channels.Value); }
async void CheckConfig(LocalConfig config) { APIResponse response = await MattermostAPI.CheckSession(config); if (!response.Success) { CurrentView = new LoginViewModel(this, config, response.Error); } else { APIResponse <List <User> > users = await MattermostAPI.GetUsers(config.TeamID); APIResponse <List <Channel> > channels = await MattermostAPI.GetChannels(config.TeamID); APIResponse <Preferences> preferences = await MattermostAPI.GetPreferences(); CurrentView = new MessageViewModel(this, users.Value, channels.Value); } }