Esempio n. 1
0
        /** Logs the user into their Microsoft Live account using Microsoft Graphs API.
         *  To increase the number of permissions add to scopes array. Right now our graphs
         *  client has user email access and read/write permission to users onedrive.
         */
        public static async void Login()
        {
            var clientId = "1912fef8-e092-4702-8012-cb3e535138a8";        // microsoft graphs api ID.
            var app      = PublicClientApplicationBuilder.Create(clientId)
                           .WithRedirectUri("http://localhost")
                           .Build();

            string[] scopes = new string[]
            {
                // add more scopes here if you want more access to users data using graphs api.
                "https://graph.microsoft.com/user.read",
                "https://graph.microsoft.com/email",
                "https://graph.microsoft.com/Files.ReadWrite.AppFolder"
            };
            var result = await app.AcquireTokenInteractive(scopes)
                         .ExecuteAsync();

            InteractiveAuthenticationProvider authProvider = new InteractiveAuthenticationProvider(app, scopes);

            graphClient = new GraphServiceClient(authProvider);
            var user = await graphClient.Me.Request().GetAsync();

            email = user.Mail;
            DatabaseCommunicator.email = user.Mail;
            if (Program.connected_to_database)
            {
                if (!DatabaseCommunicator.CheckRegistration(email))
                {
                    // show registration box here.
                    RegisterForm register = new RegisterForm(email);
                    register.StartPosition = FormStartPosition.CenterScreen;
                    register.Show();
                }
                else
                {
                    // User is already registered so we don't show registration.
                    // get all the ticked whitelist categories. If it is first time user then we show messagebox asking to select categories.
                    LoadCSESettings();
                    LoadPrivacySettings();
                    Program.LoadWhitelist();
                    LoadCategories();
                }
            }
            else
            {
                // App isn't connected to database so we don't need to check if user is registered or not.
                LoadCSESettings();
                LoadPrivacySettings();
                Program.LoadWhitelist();
                LoadCategories();
            }
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            RegisterForm registerForm = new RegisterForm();

            registerForm.ShowDialog();
        }