コード例 #1
0
ファイル: Program.cs プロジェクト: pthambirajah/DAL
        static void Main(string[] args)
        {
            var staffDbManager    = new StaffManager(Configuration);
            var customerDbManager = new CredentialsManager(Configuration);


            /*
             * Console.WriteLine("--GET 1 staff--");
             * Staff staff = staffDbManager.GetStaff(1);
             * Console.WriteLine("Check db");
             * Console.WriteLine(staff.name);
             */



            Console.WriteLine("Username");
            string usernameC = Console.ReadLine();


            Console.WriteLine("Password");
            string passwordC = Console.ReadLine();


            int idCustomerTryingToConnect = customerDbManager.GetIdCredentials(usernameC);

            //En fonction de l'id du customer
            while (passwordC != customerDbManager.GetPassword(idCustomerTryingToConnect, usernameC))
            {
                Console.WriteLine(passwordC);
                Console.WriteLine("Connection denied. Try again");

                Console.WriteLine("Username");
                usernameC = Console.ReadLine();

                Console.WriteLine("Password");
                passwordC = Console.ReadLine();

                idCustomerTryingToConnect = customerDbManager.GetIdCredentials(usernameC);
            }

            Console.WriteLine("Connection successful");

            //Program.Suite(idCustomerTryingToConnect);
        }
コード例 #2
0
        public ActionResult Index(Credentials credModel)
        {
            string usernameC = credModel.username;
            string passwordC = credModel.password;

            var credentialsDbManager  = new CredentialsManager(Configuration);
            int idUserTryingToConnect = credentialsDbManager.GetIdCredentials(usernameC);
            int userStatus            = credentialsDbManager.GetStatus(usernameC);

            //Get password using
            if (passwordC == credentialsDbManager.GetPassword(usernameC))
            {
                HttpContext.Session.SetString("username", usernameC);
                HttpContext.Session.SetInt32("id", idUserTryingToConnect);
                HttpContext.Session.SetInt32("userType", userStatus);
                //status 2 means admin, 1=Delivery employee, 0 = customer
                //The view the user will see depends on his status in our DB
                if (userStatus == 2)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                else if (userStatus == 1)
                {
                    StaffManager sManager = new StaffManager(Configuration);
                    int          idStaff  = sManager.GetStaffId(idUserTryingToConnect);
                    HttpContext.Session.SetInt32("idStaff", idStaff);
                    return(RedirectToAction("Index", "DishesOrder"));
                }
                else if (userStatus == 0)
                {
                    CustomerManager cManager = new CustomerManager(Configuration);
                    HttpContext.Session.SetInt32("idCustomer", cManager.GetCustomerIDByCredentials(idUserTryingToConnect));
                    return(RedirectToAction("Index", "Home"));
                }
                //If we did find a username and password but not a status we through an error.
                return(RedirectToAction("LoginError", "Error", new { message = "Your account is not correctly initialized. Please contact our support : [email protected] or connect with another account." }));
            }
            else
            {   //If the credentials did not match we through an error
                return(RedirectToAction("LoginError", "Error", new { message = "Unfortunately your username or password did not match our records. Please try again." }));
            }
        }
コード例 #3
0
 void OnAddServer(object sender, EventArgs e)
 {
     using (var dialog = new AddServerDialog())
     {
         if (dialog.Run(this) == Command.Ok && dialog.ServerInfo != null)
         {
             if (TFSVersionControlService.Instance.HasServer(dialog.ServerInfo.Name))
             {
                 MessageService.ShowError("Server with same name already exists!");
                 return;
             }
             using (var credentialsDialog = new CredentialsDialog(dialog.ServerType))
             {
                 if (credentialsDialog.Run(this) == Command.Ok && credentialsDialog.Authentication != null)
                 {
                     CredentialsManager.StoreCredential(dialog.ServerInfo.Uri, credentialsDialog.Authentication.Password);
                     var  password             = CredentialsManager.GetPassword(dialog.ServerInfo.Uri); //Try Get Password
                     bool isPasswordSavedInXml = false;
                     if (password == null)
                     {
                         MessageService.ShowWarning("No keyring service found!\nPassword will be saved as plain text.");
                         isPasswordSavedInXml = true;
                     }
                     var server = TeamFoundationServerFactory.Create(dialog.ServerType, dialog.ServerInfo,
                                                                     credentialsDialog.Authentication, isPasswordSavedInXml);
                     using (var projectsDialog = new ChooseProjectsDialog(server))
                     {
                         if (projectsDialog.Run(this) == Command.Ok && projectsDialog.SelectedProjects.Any())
                         {
                             var selectedProjects = projectsDialog.SelectedProjects;
                             server.ProjectCollections = new List <ProjectCollection>(selectedProjects.Select(x => x.Collection).Distinct());
                             server.ProjectCollections.ForEach(pc => pc.Projects = new List <ProjectInfo>(selectedProjects.Where(pi => pi.Collection == pc)));
                             TFSVersionControlService.Instance.AddServer(server);
                             UpdateServersList();
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #4
0
 public void LoadPrefs()
 {
     _registredServers.Clear();
     if (!File.Exists(ConfigFile))
     {
         return;
     }
     try
     {
         using (var file = File.OpenRead(ConfigFile))
         {
             XDocument doc = XDocument.Load(file);
             foreach (var serverElement in doc.Root.Element("Servers").Elements("Server"))
             {
                 var isPasswordSavedInXml = serverElement.Attribute("Password") != null;
                 var password             = isPasswordSavedInXml ? serverElement.Attribute("Password").Value : CredentialsManager.GetPassword(new Uri(serverElement.Attribute("Url").Value));
                 if (password == null)
                 {
                     throw new Exception("TFS Addin: No Password found for TFS server: " + serverElement.Attribute("Name").Value);
                 }
                 var server = TeamFoundationServerFactory.Create(serverElement, password, isPasswordSavedInXml);
                 if (server != null)
                 {
                     _registredServers.Add(server);
                 }
             }
             foreach (var workspace in doc.Root.Element("Workspaces").Elements("Workspace"))
             {
                 _activeWorkspaces.Add(workspace.Attribute("Id").Value, workspace.Attribute("Name").Value);
             }
             var mergeToolElement = doc.Root.Element("MergeTool");
             if (mergeToolElement != null)
             {
                 this.MergeToolInfo = new MergeToolInfo
                 {
                     CommandName = mergeToolElement.Attribute("Command").Value,
                     Arguments   = mergeToolElement.Attribute("Arguments").Value,
                 };
             }
             checkOutLockLevel = doc.Root.Element("CheckOutLockLevel") == null ? CheckOutLockLevel.Unchanged : (CheckOutLockLevel)Convert.ToInt32(doc.Root.Element("CheckOutLockLevel").Value);
             isDebugMode       = doc.Root.Element("DebugMode") != null && Convert.ToBoolean(doc.Root.Element("DebugMode").Value);
             this.Servers.ForEach(s => s.IsDebuMode = isDebugMode);
             file.Close();
         }
     }
     catch (Exception e)
     {
         MessageService.ShowException(e);
         return;
     }
     if (_registredServers.Any())
     {
         RaiseServersChange();
     }
 }