/// <summary> /// Logs the user with the given data in /// </summary> /// <param name="username">User provided username</param> /// <param name="password">User's password</param> /// <param name="remember">Remain logged in or not</param> public async void FullLogin(string username, string password, bool remember) { // SSL Crt (should been placed in Solution Dir with Build Option Copy always) // SslCredentials cred = new SslCredentials(File.ReadAllText("server.crt")); // new Channel and then a new client based on that Channel // var connectionChannel = new Channel("beta.emergencyx.de:50051", cred); var emx = EmergencyExplorerService.NewClient(connectionChannel); // For testing only hardcoded login informations // LoginRequest request = new LoginRequest { Username = username, Password = password, RememberMe = remember }; LoginResponse response = await emx.LoginAsync(request); // stop if no success... // if (response.Success != true) { AppConfig.writeToAppConfig("login", "error"); throw new NotSuccessFullLoggedInException(); } //Save the responded date to re-login the user every program session until he logs out // AppConfig.writeToAppConfig("rememberMe", remember.ToString()); AppConfig.writeToAppConfig("userId", response.UserId.ToString()); AppConfig.writeToAppConfig("token", response.Token); AppConfig.writeToAppConfig("username", request.Username); AppConfig.writeToAppConfig("login", "success"); //All done // connectionChannel.ShutdownAsync().Wait(); }
/// <summary> /// Logs the user asyncrouns in. No parmaeter needed because the needed data is stored in app.config /// </summary> public async void TokenLogin() { // SSL Crt (should been placed in Solution Dir with Build Option Copy always) // SslCredentials cred = new SslCredentials(File.ReadAllText("server.crt")); // new Channel and then a new client based on that Channel // var connectionChannel = new Channel("beta.emergencyx.de:50051", cred); var emx = EmergencyExplorerService.NewClient(connectionChannel); LoginWithTokenRequest request = new LoginWithTokenRequest { UserId = Convert.ToUInt32(AppConfig.readFromAppConfig("userId")), Token = AppConfig.readFromAppConfig("token") }; LoginResponse response = await emx.LoginWithTokenAsync(request); connectionChannel.ShutdownAsync().Wait(); if (response.Success != true) { throw new NotSuccessFullLoggedInException(); } }