public ISafe CreateSafeForNonExistingUser(string userName, string masterpassword, string password)
        {
            var masterPassBytes             = GetEncryptedBytes(masterpassword, password);
            var verifyingWord               = "SafeBySimplify";
            var veriyfingWordEncryptedBytes = GetEncryptedBytes(verifyingWord, password);

            var account = new Account()
            {
                MasterEncryptedPassBytes     = masterPassBytes,
                VerifyingWord                = verifyingWord,
                VeryifyingWordEncryptedBytes = veriyfingWordEncryptedBytes,
            };

            AccountGateway.WriteUserRecord(WorkingDirectory, userName, account);

            var safeForNonExistingUser = new Safe(masterpassword);

            safeForNonExistingUser.UserName         = userName;
            safeForNonExistingUser.WorkingDirectory = WorkingDirectory;
            return(safeForNonExistingUser);
        }
 public AccountManager()
 {
     accountGateway = new AccountGateway();
 }
        /**
         * Facilitate testing of data layer
         */
        public static void Main(string[] args)
        {
            var accGateway      = AccountGateway.GetInstance(DbObj.GetInstance());
            var metadataGateway = MetadataGateway.GetInstance(DbObj.GetInstance());

            string       email = "*****@*****.**";
            ObjectId     objId;
            AccountModel acc;

            while (true)
            {
                Console.WriteLine("\nSelect an operation:");
                Console.WriteLine("0.  Exit.");
                Console.WriteLine("1.  Create 4 new users.");
                Console.WriteLine("2.  View all users.");
                Console.WriteLine("3.  Update a user's name.");
                Console.WriteLine("4.  Delete a user's account.");
                Console.WriteLine("5.  View name & password of a user.");
                Console.WriteLine("6.  Create sample file and folders.");
                Console.WriteLine("7.  View content of user's root folder.");
                string cmd = Console.ReadLine();

                switch (cmd)
                {
                case "0":
                    Console.WriteLine("\nExit ok.");
                    return;

                case "1":
                    // CREATE
                    objId = ObjectId.GenerateNewId();
                    accGateway.Insert(new AccountModel(objId, "Ng Cai Feng", "Mr",
                                                       "*****@*****.**", "password1", DateTime.Now, true, "", "Bio"));
                    objId = ObjectId.GenerateNewId();
                    accGateway.Insert(new AccountModel(objId, "Chua Xiang Wei, Jerahmeel", "Mr",
                                                       "*****@*****.**", "password2", DateTime.Now, true, "", "Bio"));
                    objId = ObjectId.GenerateNewId();
                    accGateway.Insert(new AccountModel(objId, "Ryan Chia Dong Yi", "Mr",
                                                       "*****@*****.**", "password3", DateTime.Now, true, "", "Bio"));
                    objId = ObjectId.GenerateNewId();
                    accGateway.Insert(new AccountModel(objId, "Lim Jing Pei", "Ms",
                                                       "*****@*****.**", "password4", DateTime.Now, true, "", "Bio"));
                    accGateway.Save();

                    break;

                case "2":
                    // READ all accounts
                    var readResults = accGateway.SelectAll().GetEnumerator();

                    while (readResults.MoveNext())
                    {
                        Console.WriteLine(readResults.Current?.Email + " " + readResults.Current?.Name);
                    }

                    break;

                case "3":
                    // UPDATE account by email
                    Console.WriteLine("Enter the email of the user whose name you want to update:");
                    email = Console.ReadLine();
                    Console.WriteLine("Enter the new name:");
                    String name = Console.ReadLine();

                    acc = accGateway.SelectByEmail(email);
                    if (acc != null)
                    {
                        acc.Name = name;

                        accGateway.Update(acc);
                        accGateway.Save();
                    }
                    else
                    {
                        Console.WriteLine("Email not found.");
                    }

                    break;

                case "4":
                    // DELETE account by email
                    Console.WriteLine("Enter the email of the user to delete:");
                    email = Console.ReadLine();

                    acc = accGateway.SelectByEmail(email);
                    if (acc != null)
                    {
                        accGateway.Delete(acc);
                        accGateway.Save();
                    }
                    else
                    {
                        Console.WriteLine("Email not found.");
                    }

                    break;

                case "5":
                    // SELECT ACCOUNT MODEL BY EMAIL
                    Console.WriteLine("Enter the email of the user you want to view:");
                    email = Console.ReadLine();

                    acc = accGateway.SelectByEmail(email);
                    if (acc != null)
                    {
                        Console.WriteLine("Name of " + email + ": " + acc.Name);
                        Console.WriteLine("Password of " + email + ": " + acc.Password);
                    }
                    else
                    {
                        Console.WriteLine("Email not found.");
                    }

                    break;

                case "6":
                    // CREATE FILES AND FOLDERS

                    AccessControlsModel        acModel1 = new AccessControlsModel("*****@*****.**", true, true);
                    AccessControlsModel        acModel2 = new AccessControlsModel("*****@*****.**", true, true);
                    List <AccessControlsModel> acList   = new List <AccessControlsModel>();
                    acList.Add(acModel1); acList.Add(acModel2);

                    ObjectId userRootId = ObjectId.GenerateNewId();
                    ObjectId folderAId  = ObjectId.GenerateNewId();
                    ObjectId folderBId  = ObjectId.GenerateNewId();
                    ObjectId folderCId  = ObjectId.GenerateNewId();

                    // userRoot
                    metadataGateway.Insert(new MetadataModel(userRootId, email, email, 0, DateTime.Now, "", "", acList));
                    // folderA in root
                    metadataGateway.Insert(new MetadataModel(folderAId, email, "FolderA", 0, DateTime.Now, "", userRootId.ToString(), acList));
                    // fileA in folderA
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileA", 1, DateTime.Now, "", folderAId.ToString(), acList));
                    // fileB in folderA
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileB", 1, DateTime.Now, "", folderAId.ToString(), acList));
                    // fileC in folderA
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileC", 1, DateTime.Now, "", folderAId.ToString(), acList));
                    // folderB in folderA
                    metadataGateway.Insert(new MetadataModel(folderBId, email, "FolderB", 0, DateTime.Now, "", folderAId.ToString(), acList));
                    // fileD in folderB
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileD", 1, DateTime.Now, "", folderBId.ToString(), acList));
                    // folderC in root
                    metadataGateway.Insert(new MetadataModel(folderCId, email, "FolderC", 0, DateTime.Now, "", userRootId.ToString(), acList));
                    // fileE in folderC
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileE", 1, DateTime.Now, "", folderCId.ToString(), acList));
                    // fileF in root
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileF", 1, DateTime.Now, "", userRootId.ToString(), acList));
                    // fileG in root
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileG", 1, DateTime.Now, "", userRootId.ToString(), acList));

                    metadataGateway.Save();

                    break;

                case "7":
                    // View content of user's root folder

                    Console.WriteLine("Enter the email of the user:"******"\nTop level files and folders:\n");
                        var contentEnumerator = content.GetEnumerator();
                        while (contentEnumerator.MoveNext())
                        {
                            Console.WriteLine(contentEnumerator.Current?.name);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Email not found.");
                    }

                    break;

                default:
                    Console.WriteLine("Invalid command.");
                    break;
                }
            }
        }
 public CreateAccountInteractor(ICreateAccountValidator validator, AccountGateway accountGateway, IPlayerGateway playerGateway)
 {
     Validator      = validator;
     AccountGateway = accountGateway;
     PlayerGateway  = playerGateway;
 }
示例#5
0
 public void Arrange()
 {
     AccountApiClient = new Mock <IAccountApiClient>();
     AccountGateway   = new AccountGateway(AccountApiClient.Object);
 }
示例#6
0
        public void RefreshTest()
        {
            IList <Cookie> cookies = new List <Cookie>();

            #region Test email host domain

            //IList<IAccount> accounts = AccountGateway.GetAll();

            //foreach (IAccount account in accounts)
            //{
            //    account.IsDefault = account.Host == "legacymail.taylorcorp.com";
            //}

            //accounts= AccountGateway.Update(accounts);

            #endregion

            #region Test wrong email host domain

            IAccount a = AccountGateway.GetDefault();
            a.Host = "test.test.com";
            a      = AccountGateway.Update(a);

            #endregion

            Process.Start(AccountGateway.AccountSettingPath);

            try
            {
                Authentication.AuthenticationManager.Refresh();
                cookies = Authentication.AuthenticationManager.Current.CookieCache;
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(AuthenticationException));
                Console.WriteLine(e.Message);
            }

            Assert.IsTrue(cookies.Count < 2);

            #region Test email host domain

            //foreach (IAccount account in accounts)
            //{
            //    account.IsDefault = account.Host == "webmail.taylorcorp.com";
            //}
            //AccountGateway.Update(accounts);

            #endregion

            #region Test wrong email host domain

            a.Host = "webmail.taylorcorp.com";
            a      = AccountGateway.Update(a);

            #endregion

            Process.Start(AccountGateway.AccountSettingPath);

            Authentication.AuthenticationManager.Refresh();

            cookies = Authentication.AuthenticationManager.Current.CookieCache;

            Console.WriteLine("Count:{0}", cookies.Count);

            Assert.IsTrue(cookies.Count >= 2);
        }
        protected AuthenticationManager()
        {
            Log.Debug("Authentication Manager initialized.");
            _cookieCache    = new List <Cookie>();
            _currentAccount = AccountGateway.GetDefault();
            if (_currentAccount == null)
            {
                throw new AuthenticationException("Message: No default account found in Account Setting.");
            }

            try
            {
                _cookieCache = Authenticate(_currentAccount);
            }
            catch (AuthenticationException e)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Authentication Exception, are you using a valid login?");
                sb.AppendLine("   Msg: " + e.Message);
                sb.AppendLine("   Note: You must use a valid login / password for authentication.");
                string message = sb.ToString();
                Log.Error(message);
                throw new AuthenticationException(message);
            }
            catch (SecurityException e)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Security Exception");
                sb.AppendLine("   Msg: " + e.Message);
                sb.AppendLine("   Note: The application may not be trusted if run from a network share.");
                string message = sb.ToString();
                Log.Error(message);
                throw new AuthenticationException(message);
            }
            catch (WebException e)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Web Exception");
                sb.AppendLine("   Status: " + e.Status);
                sb.AppendLine("   Reponse: " + e.Response);
                sb.AppendLine("   Msg: " + e.Message);
                string message = sb.ToString();
                Log.Error(message);
                throw new AuthenticationException(message);
            }
            catch (Exception ex)
            {
                if (ex is AuthenticationException)
                {
                    throw;
                }

                Log.ErrorFormat("Message: Authentication failed to email host ({0}). {1}", _currentAccount.Host, ex.Message);
                throw new AuthenticationException(string.Format("Authentication failed to email host ({0})",
                                                                _currentAccount.Host));
            }

            if (_cookieCache.Count < 2)
            {
                string message = "Login failed. Is the login / password correct?";
                Log.Error(message);
                throw new AuthenticationException(message);
            }
        }
 public DepositManager()
 {
     depositGateway = new DepositGateway();
     accountGateway = new AccountGateway();
 }
示例#9
0
    public string LoadUserInformation()
    {
        DataTable     dt       = null;
        StringBuilder tableRow = new StringBuilder();

        try
        {
            using (AccountGateway accountGateway = new AccountGateway())
            {
                int count = 0;
                dt = accountGateway.LoadUserInformation();
                if (dt.Rows.Count > 0)
                {
                    tableRow.Append("<table class='table table-bordered'><thead><tr class='success'>" +
                                    "<th>Serial No</th>" +
                                    "<th>User Name</th>" +
                                    "<th>User Password</th>" +
                                    "<th>Full Name</th>" +
                                    "<th>IsActive</th>" +
                                    "<th>Admin Type</th>" +
                                    "<th>Zone Name</th>" +
                                    "<th>Inserted On</th>" +
                                    "<th>Inserted By</th>" +
                                    "<th>Updated On</th>" +
                                    "<th>Updated By</th>" +
                                    "<th>Action</th>" +
                                    "</tr></thead >");
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        count++;

                        tableRow.Append("<tbody><tr>");

                        tableRow.Append("<td>" + count + "</td>");
                        tableRow.Append("<td>" + dt.Rows[i]["UserName"] + "</td>");
                        tableRow.Append("<td>" + dt.Rows[i]["UserPassword"] + "</td>");
                        tableRow.Append("<td>" + dt.Rows[i]["FullName"] + "</td>");
                        tableRow.Append("<td>" + dt.Rows[i]["IsActive"] + "</td>");

                        //tableRow.Append("<td>" + dt.Rows[i]["AdminType"] + "</td>");
                        string admin = dt.Rows[i]["AdminType"].ToString();

                        if (admin == "1")
                        {
                            tableRow.Append("<td>" + "Admin" + "</td>");
                        }
                        if (admin == "2")
                        {
                            tableRow.Append("<td>" + "Manager" + "</td>");
                        }
                        if (admin == "3")
                        {
                            tableRow.Append("<td>" + "User" + "</td>");
                        }

                        tableRow.Append("<td>" + dt.Rows[i]["ZoneName"] + "</td>");

                        tableRow.Append("<td>" + dt.Rows[i]["InsertedOn"] + "</td>");
                        tableRow.Append("<td>" + dt.Rows[i]["InsertedBy"] + "</td>");
                        tableRow.Append("<td>" + dt.Rows[i]["UpdatedOn"] + "</td>");
                        tableRow.Append("<td>" + dt.Rows[i]["UpdatedBy"] + "</td>");
                        tableRow.Append("<td><a href='NewAccount.aspx?Id=" + dt.Rows[i]["UserId"] + "'>Edit</a></td>");
                        tableRow.Append("</tr></tbody>");
                    }
                    tableRow.Append("</table>");
                }
                else
                {
                    tableRow.Append("No Data Found");
                }
            }
        }
        catch (Exception ex)
        {
        }
        return(tableRow.ToString());
    }
示例#10
0
 public WithdrawManager()
 {
     withdrawGateway = new WithdrawGateway();
     accountGateway  = new AccountGateway();
 }
示例#11
0
 public List <string> GetUserNames()
 {
     return(AccountGateway.GetUserNames(WorkingDirectory));
 }