private async Task LoginAsync() { CheckAuthentication auth = new CheckAuthentication(); auth.authentication = new Authentication(); auth.authentication.password = Password; auth.authentication.userName = UserName; bool result = await IsValidAuthentication(auth); if (result) { if (PasswordShouldBeSaved) { CService.SaveCredentials(UserName, Password); } MvvmNanoIoC.RegisterAsSingleton <Authentication>(auth.authentication); NavigateTo <MasterDetailViewModel>(); } else { Info = true; InfoText = "Passwort ist nicht korrekt"; Debug.WriteLine("Not authenticated"); NotifyPropertyChanged("Info"); NotifyPropertyChanged("InfoText"); } }
/// <summary> /// Checks auth /// </summary> /// <param name="auth">Authentication RequestObject</param> /// <returns>success/failure</returns> public async Task <bool> CanAuthenticate(CheckAuthentication auth) { _restUrl = "http://tutorscout24.vogel.codes:3000/tutorscout24/api/v1/user/checkAuthentication"; var uri = new Uri(string.Format(_restUrl, string.Empty)); var json = JsonConvert.SerializeObject(auth); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; response = await _client.PostAsync(uri, content); return(response.IsSuccessStatusCode); }
private async void TryToPerformAutoLogin() { CredentialService CService = MvvmNanoIoC.Resolve <CredentialService>(); try { if (CService.DoCredentialsExist()) { CheckAuthentication auth = new CheckAuthentication(); auth.authentication = new Authentication(); auth.authentication.password = CService.Password; auth.authentication.userName = CService.UserName; bool result = await IsValidAuthentication(auth); if (result) { MvvmNanoIoC.RegisterAsSingleton <Authentication>(auth.authentication); SetUpMainPage <MasterDetailViewModel>(); } else { SetUpMainPage <LoginViewModel>(); } } else { SetUpMainPage <LoginViewModel>(); } } catch (Exception) { SetUpMainPage <LoginViewModel>(); } }
private static bool TryHandleAsStaticContent(IContext context) { var absolutePath = context.Request.Url.AbsolutePath; string file; CacheOptions cacheOptions; IList <IAccessControlEntry> accessControl; if (SimpleWeb.Configuration.PublicFileMappings.ContainsKey(absolutePath)) { var publicFile = SimpleWeb.Configuration.PublicFileMappings[absolutePath]; file = SimpleWeb.Environment.PathUtility.MapPath(publicFile.Path); cacheOptions = publicFile.CacheOptions; accessControl = publicFile.AccessControl; } else if (SimpleWeb.Configuration.AuthenticatedFileMappings.ContainsKey(absolutePath)) { var user = SimpleWeb.Configuration.AuthenticationProvider.GetLoggedInUser(context); if (user == null || !user.IsAuthenticated) { CheckAuthentication.Redirect(context); return(true); } var publicFile = SimpleWeb.Configuration.AuthenticatedFileMappings[absolutePath]; file = SimpleWeb.Environment.PathUtility.MapPath(publicFile.Path); cacheOptions = publicFile.CacheOptions; accessControl = publicFile.AccessControl; } else { var folder = SimpleWeb.Configuration.PublicFolders.FirstOrDefault( f => absolutePath.StartsWith(f.Alias + "/", StringComparison.OrdinalIgnoreCase)); if (folder != null) { file = SimpleWeb.Environment.PathUtility.MapPath(folder.RewriteAliasToPath(absolutePath)); cacheOptions = folder.CacheOptions; accessControl = folder.AccessControl; } else { return(false); } } if (string.IsNullOrWhiteSpace(file) || !File.Exists(file)) { return(false); } context.Response.Status = Status.OK; context.Response.SetContentType(GetContentType(file, context.Request.GetAccept())); var fileInfo = new FileInfo(file); context.Response.SetContentLength(fileInfo.Length); context.Response.SetLastModified(fileInfo.LastWriteTimeUtc); if (cacheOptions != null) { context.Response.SetCacheOptions(cacheOptions); } if (accessControl != null) { context.SetAccessControlHeaders(accessControl); } context.Response.WriteFunction = (stream) => { using (var fileStream = File.OpenRead(file)) { fileStream.CopyTo(stream); return(TaskHelper.Completed()); } }; return(true); }
/// <summary> /// Base Controller /// </summary> public BaseController() { this.authentication = new CheckAuthentication(); }
private async Task <bool> IsValidAuthentication(CheckAuthentication auth) { return(await MvvmNanoIoC.Resolve <TutorScoutRestService>().CanAuthenticate(auth)); }