Пример #1
0
        public createAccountWindow()
        {
            InitializeComponent();

            //Create DB connection if email is valid
            db = new ServerCommunicationController();
        }
Пример #2
0
        private Boolean registerUserCloud(string token, int cloudID, string refreshToken)
        {
            ServerCommunicationController db = new ServerCommunicationController();

            db.InsertNewUserCloud(user.User_id, token, cloudId, refreshToken);
            return(true); //TODO: refine it
        }
Пример #3
0
        public async static Task oneDriveLogin(User user)
        {
            var _oneDriveClient = InitializeAPI.oneDriveClient;
            int cloudId         = 1;

            //Models.WindowsDownloadManager wdm = new WindowsDownloadManager();

            //these are also login params, should move to login class

            //checks to see if the client is authenticated
            if (!_oneDriveClient.IsAuthenticated)
            {
                //checks for active session
                if (accountSession != null)
                {
                    var      refreshToken = accountSession.RefreshToken;
                    string[] secret       = { onedrive_client_secret };
                    await _oneDriveClient.AuthenticateAsync();

                    //trys this sneak silent authenticator

                    /*
                     * await OneDriveClient.GetSilentlyAuthenticatedMicrosoftAccountClient(
                     *  onedrive_client_id,
                     *  onedrive_redirect_uri,
                     *  secret,
                     *  refreshToken);
                     */
                }
                else
                {
                    try {
                        await _oneDriveClient.AuthenticateAsync();

                        accountSession = _oneDriveClient.AuthenticationProvider.CurrentAccountSession;
                        if (_oneDriveClient.IsAuthenticated)
                        {
                            Console.WriteLine("One Drive login succedded for user " + user.User_id);
                        }

                        //Console.WriteLine("1D refresh: " + oneDriveClient.AuthenticationProvider.CurrentAccountSession.RefreshToken);
                        //Console.WriteLine("1D token: " + oneDriveClient.AuthenticationProvider.CurrentAccountSession.AccessToken);
                        string refreshToken = _oneDriveClient.AuthenticationProvider.CurrentAccountSession.RefreshToken;
                        string accessToken  = _oneDriveClient.AuthenticationProvider.CurrentAccountSession.AccessToken;
                        ServerCommunicationController db = new ServerCommunicationController();
                        db.InsertNewUserCloud(user.User_id, accessToken, cloudId, refreshToken);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("One Drive login FAILED: " + e.Message);
                    }
                }
            }

            InitializeAPI.oneDriveClient = _oneDriveClient;
        }
Пример #4
0
 public void ServerCommunicationControllerTest()
 {
     try
     {
         ServerCommunicationController db = new ServerCommunicationController();
     }
     catch (ArgumentException e)
     {
         Assert.Fail();
     }
 }
Пример #5
0
        public void UpdateLastLoginTest()
        {
            ServerCommunicationController db = new ServerCommunicationController();

            try
            {
                db.UpdateLastLogin("*****@*****.**");
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }
Пример #6
0
        public void SelectUserTest()
        {
            ServerCommunicationController db = new ServerCommunicationController();

            try
            {
                User testUser = db.SelectUser("*****@*****.**"); //user with email = '*****@*****.**' already added in DB for testing purpose
                Assert.AreEqual(testUser.Email, "*****@*****.**");
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }
Пример #7
0
        public void doesUserCloudExistTest()
        {
            ServerCommunicationController db = new ServerCommunicationController();

            try
            {
                bool testBool = db.doesUserCloudExist(778); //userCloud with user_cloud_id = 778 already added in DB for testing purpose
                Assert.AreEqual(testBool, true);
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }
Пример #8
0
        public void InsertDeleteNewUserCloudTest()
        {
            ServerCommunicationController db = new ServerCommunicationController();

            try
            {
                db.InsertNewUserCloud(777, "token", 2, "token");
                db.DeleteUserCloud(777);
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }
Пример #9
0
        public void InsertDeleteTest()
        {
            ServerCommunicationController db = new ServerCommunicationController();

            try
            {
                db.Insert("users", "*****@*****.**", "hash", "salt");
                db.Delete("*****@*****.**");
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }
Пример #10
0
        public void emailExistsTest()
        {
            ServerCommunicationController db = new ServerCommunicationController();

            try
            {
                bool testBool = db.emailExists("*****@*****.**");
                Assert.AreEqual(testBool, true);
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }
Пример #11
0
        public void SelectUserCloudsTest()
        {
            ServerCommunicationController db = new ServerCommunicationController();

            try
            {
                List <UserCloud> testUserCloudList = new List <UserCloud>();
                testUserCloudList = db.SelectUserClouds(778); //userCloud with user_cloud_id = 778 already added in DB for testing purpose
                Assert.AreEqual(testUserCloudList.Count > 0, true);
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }
Пример #12
0
        private void loginClick(object sender, RoutedEventArgs e)
        {
            string email = textBox.Text.ToString();
            string pass  = passwordBox.Password.ToString();

            if (email == "")
            {
                errorMessage.Text = "Please enter Email.";
            }
            else if (pass == "")
            {
                errorMessage.Text = "Please enter Password.";
            }
            else
            {
                //Query DB users table for username entered
                ServerCommunicationController db = new ServerCommunicationController();

                if (db.emailExists(email))
                {
                    User user = db.SelectUser(email);
                    db.UpdateLastLogin(email);
                    //List<String> list = db.SelectUser(email);
                    byte[] salt, key;
                    // load salt and key from database
                    salt = Convert.FromBase64String(user.Pass_salt);
                    key  = Convert.FromBase64String(user.Pass_hash);

                    using (var deriveBytes = new Rfc2898DeriveBytes(pass, salt))
                    {
                        byte[] newKey = (deriveBytes.GetBytes(20));  // derive a 20-byte key
                        //Checks to see if keys are NOT the same
                        if (!newKey.SequenceEqual(key))
                        {
                            errorMessage.Text = "Incorrect Password.";
                        }
                        //If keys are the same
                        else
                        {
                            List <UserCloud> userClouds;
                            //Ensure user has user clouds
                            if (db.doesUserCloudExist(user.User_id))
                            {
                                //Gather and display user clouds
                                userClouds = db.SelectUserClouds(user.User_id);
                                foreach (UserCloud cloud in userClouds)
                                {
                                    string type = "";
                                    if (cloud.Cloud_id == 1)
                                    {
                                        type = "One Drive";
                                    }
                                    else if (cloud.Cloud_id == 2)
                                    {
                                        type = "Google Drive";
                                    }
                                    Console.WriteLine("Cloud token (" + type + ") printed from logInWindow: " + cloud.Cloud_token);
                                    Console.WriteLine("Refresh token (" + type + ") printed from logInWindow: " + cloud.Refresh_token);
                                }
                            }
                            MainWindow mainWin = new MainWindow(user);
                            mainWin.Show();
                            this.Close();
                        }
                    }
                }
                else
                {
                    errorMessage.Text = "Username does not exist.";
                }
            }
        }