public int AnonymousUserInterface(ref IWorkgroupService workgroupProxy, IRegistrationService registrationProxy, ConnectionHandler connectionHandler, ClientAccount clientAccount) { User user = new User(); bool operationSuccess; int choice = 0; bool ok = false; Console.WriteLine("---AUTHENTICATION SERVICE---\n"); Console.WriteLine("1. Login"); Console.WriteLine("2. Register"); do { Console.Write("Choice: "); if (!Int32.TryParse(Console.ReadLine(), out choice)) { Console.WriteLine("Choice is a number!"); } ok = true; } while (ok != true); switch (choice) { case 1: { string answerOne = null; string answerTwo = null; LoginDTO loginInformation = new LoginDTO(); InputCredentials(clientAccount); if (clientAccount.RequireSafeLogin) { Console.WriteLine("Server demands safe login. Input answers to security questions in order to log in"); Console.WriteLine(clientAccount.SecurityQuestionOne); answerOne = Console.ReadLine(); Console.WriteLine(clientAccount.SecurityQuestionTwo); answerTwo = Console.ReadLine(); } if (connectionHandler.workgroupChannel.Credentials.UserName.UserName != null) //Reopen channel for new credentials { if (connectionHandler.CloseWorkgroupChannel()) { connectionHandler.OpenWorkgroupChannel(); connectionHandler.workgroupChannel.Credentials.UserName.UserName = clientAccount.Username; connectionHandler.workgroupChannel.Credentials.UserName.Password = clientAccount.Password; workgroupProxy = connectionHandler.workgroupChannel.CreateChannel(); } } else { connectionHandler.workgroupChannel.Credentials.UserName.UserName = clientAccount.Username; connectionHandler.workgroupChannel.Credentials.UserName.Password = clientAccount.Password; workgroupProxy = connectionHandler.workgroupChannel.CreateChannel(); } try { loginInformation = workgroupProxy.Login(clientAccount.Username, clientAccount.Password, answerOne, answerTwo); } /*catch(ArgumentException e) * { * Console.WriteLine(e.Message); * } * catch(FaultException fe) * { * Console.WriteLine(fe.Message, fe.Reason); * }*/ catch (Exception e) { if (e is FaultException) { Console.WriteLine(e.Message); } if (e is ArgumentException) { Console.WriteLine(e.Message); } } if (loginInformation.Authenticated) { clientAccount.Authenticated = true; clientAccount.ClientGroup = loginInformation.UserGroup; } else { if (loginInformation.SecurityQuestionOne != null) { clientAccount.RequireSafeLogin = true; clientAccount.SecurityQuestionOne = loginInformation.SecurityQuestionOne; clientAccount.SecurityQuestionTwo = loginInformation.SecurityQuestionTwo; } Console.WriteLine("Failed to log in"); } break; } case 2: { User newUserAccount = InputUserInfo(); try { operationSuccess = registrationProxy.Register(newUserAccount); if (operationSuccess) { Console.WriteLine("Successfully registered a new account!"); } } catch (FaultException fe) { Console.WriteLine(fe.Message); Console.WriteLine(fe.InnerException); } break; } case 0: break; } return(choice); }
public Client() { InitializeComponent(); this.connectionHandler = new ConnectionHandler(this); Encoder = new ASCIIEncoding(); }
public void WorkerWindow(ClientAccount ca, IWorkgroupService workgroupProxy, ConnectionHandler connectionHandler) { User u = workgroupProxy.FindUser(ca.Username); int choice = 0; bool ok = false; do { Console.WriteLine("**********************************************"); Console.WriteLine("Hello " + u.Username); Console.WriteLine("1. Request to get in the team"); Console.WriteLine("2. Request for vacation"); Console.WriteLine("3. Change password"); Console.WriteLine("4. Logout"); if (ca.ClientGroup == "Boss") { Console.WriteLine("5. See list of requests"); } do { Console.Write("Choice: "); if (!Int32.TryParse(Console.ReadLine(), out choice)) { Console.WriteLine("Choice is a number!"); } ok = true; } while (ok != true); switch (choice) { case 1: { try { workgroupProxy.Ask(u.Username); Console.WriteLine("Your request for joining group is sent"); } catch (FaultException fe) { Console.WriteLine(fe.Message, fe.Reason); } break; } case 2: { DateTime timeNow = DateTime.Now; int result = 0; int result2 = 0; string start, end; do { Console.WriteLine("Starting date[mm/dd/yyyy]: "); start = Console.ReadLine(); try { DateTime dt = Convert.ToDateTime(start); result = DateTime.Compare(Convert.ToDateTime(start), timeNow); //ako je start pre trenutka onda je result = -1 } catch { Console.WriteLine("Not a good date format."); } } while (result <= 0); do { Console.WriteLine("Ending date[mm/dd/yyyy]: "); end = Console.ReadLine(); try { DateTime dt = Convert.ToDateTime(end); result = DateTime.Compare(Convert.ToDateTime(end), timeNow); result2 = DateTime.Compare(Convert.ToDateTime(end), Convert.ToDateTime(start)); } catch { Console.WriteLine("Not a good date format."); } } while (result <= 0 || result2 <= 0); try { workgroupProxy.RequestVacation(u.Username, start, end); } catch (FaultException fe) { Console.WriteLine(fe.Reason); } break; } case 3: { bool correctpass = false; do { Console.WriteLine("Input old password"); string oldpass = Console.ReadLine(); if (u.Password != oldpass) { Console.WriteLine("You entered wrong password."); } Console.WriteLine("Input new password"); string newpass = Console.ReadLine(); try { correctpass = workgroupProxy.ChangePassword(u.Username, oldpass, newpass); } catch (FaultException fe) { Console.WriteLine(fe.Reason); } } while (correctpass == false); break; } case 4: { bool loggedout = false; loggedout = workgroupProxy.Logout(u.Username); Environment.Exit(0); break; } case 5: { List <Request> list = workgroupProxy.AllRequests(u.Username); int no = list.Count; if (no != 0) { Console.WriteLine("**********REQUESTS********"); foreach (Request r in list) { Console.WriteLine("User that asked for vacation: " + r.UserId); Console.WriteLine("Id: " + r.Id); Console.WriteLine("Starting date: " + r.StartDate); Console.WriteLine("Ending date: " + r.EndDate); } Console.WriteLine("**********************"); Console.WriteLine("1. Approve request"); Console.WriteLine("2. Deny request"); Console.WriteLine("Choice: "); int choice2 = Int32.Parse(Console.ReadLine()); if (choice2 == 1) { Console.WriteLine("Input ID of request you want to approve"); int id; if (!Int32.TryParse(Console.ReadLine(), out id)) { Console.WriteLine("ID is number!"); break; } try { workgroupProxy.ApproveRequest(id, ca.Username); } catch (FaultException fe) { Console.WriteLine(fe.Reason); } } else if (choice2 == 2) { Console.WriteLine("Input ID of request you want to deny"); int id; if (!Int32.TryParse(Console.ReadLine(), out id)) { Console.WriteLine("ID is number!"); break; } try { workgroupProxy.DenyRequest(id, ca.Username); } catch (FaultException fe) { Console.WriteLine(fe.Reason); } } } else { Console.WriteLine("There are no requests for vacation."); } break; } } } while (choice != 4); }