public UserAccount User_Validate(string username, string password)
        {
            try
            {
                IUserRepository userrep = new EntityUserRepository();
                User            user    = userrep.ValidateUser(username, password);
                if (user == null)
                {
                    return(null);
                }

                IAccountRepository acctrep = new EntityAccountRepository();
                Account            acct    = acctrep.GetAccount(user.AccountID);
                if (acct == null || !acct.IsActive)
                {
                    return(null);
                }

                UserAccount useracct = new UserAccount();
                useracct.UserID             = user.UserID;
                useracct.Username           = user.Username;
                useracct.FirstName          = user.FirstName;
                useracct.LastName           = user.LastName;
                useracct.EmailAddress       = user.EmailAddress;
                useracct.IsAdmin            = user.IsAdmin;
                useracct.UserIsActive       = user.IsActive;
                useracct.AccountID          = acct.AccountID;
                useracct.AccountName        = acct.AccountName;
                useracct.AccountDescription = acct.AccountDescription;
                useracct.FTPServer          = acct.FTPServer;
                useracct.FTPUsername        = acct.FTPUsername;
                useracct.FTPPassword        = acct.FTPPassword;
                useracct.AccountIsActive    = acct.IsActive;

                return(useracct);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #2
0
        //
        // GET: /User/

        public ActionResult Index()
        {
            try
            {
                if (Session["UserAccountID"] == null)
                {
                    return(RedirectToAction("Validate", "Login"));
                }
                User currentuser = (User)Session["User"];
                ViewData["LoginInfo"] = "<b>User:</b> " + currentuser.Username + "&nbsp; &nbsp; &nbsp;<b>Account:</b> " + Session["UserAccountName"];
                if (currentuser.IsAdmin)
                {
                    ViewData["txtIsAdmin"] = "true";
                }
                else
                {
                    throw new Exception("You are not authorized to access this page.");
                }

                // Initialize or get the page state using session
                UserPageState pagestate = GetPageState();

                // Set and save the page state to the submitted form values if any values are passed
                if (Request.Form["lstAscDesc"] != null)
                {
                    pagestate.AccountID = Convert.ToInt32(Request.Form["lstAccount"]);
                    pagestate.Username  = Request.Form["txtUsername"].ToString().Trim();
                    if (Request.Form["chkIncludeInactive"].ToLower().StartsWith("true"))
                    {
                        pagestate.IncludeInactive = true;
                    }
                    else
                    {
                        pagestate.IncludeInactive = false;
                    }
                    pagestate.SortBy     = Request.Form["lstSortBy"].ToString().Trim();
                    pagestate.AscDesc    = Request.Form["lstAscDesc"].ToString().Trim();
                    pagestate.PageNumber = Convert.ToInt32(Request.Form["txtPageNumber"].ToString().Trim());
                    SavePageState(pagestate);
                }

                // Add the session values to the view data so they can be populated in the form
                ViewData["AccountID"]       = pagestate.AccountID;
                ViewData["Username"]        = pagestate.Username;
                ViewData["IncludeInactive"] = pagestate.IncludeInactive;
                ViewData["SortBy"]          = pagestate.SortBy;
                ViewData["SortByList"]      = new SelectList(BuildSortByList(), "Value", "Text", pagestate.SortBy);
                ViewData["AscDescList"]     = new SelectList(BuildAscDescList(), "Value", "Text", pagestate.AscDesc);
                ViewData["AccountList"]     = new SelectList(BuildAccountList(true), "Value", "Text", pagestate.AccountID);

                // Determine asc/desc
                bool isdescending = false;
                if (pagestate.AscDesc.ToLower().StartsWith("d"))
                {
                    isdescending = true;
                }

                // Get a Count of all filtered records
                int recordcount = repository.GetUserRecordCount(pagestate.AccountID, pagestate.Username, pagestate.IncludeInactive);

                // Determine the page count
                int pagecount = 1;
                if (recordcount > 0)
                {
                    pagecount = recordcount / Constants.PageSize;
                    if (recordcount % Constants.PageSize != 0) // Add a page if there are more records
                    {
                        pagecount = pagecount + 1;
                    }
                }

                // Make sure the current page is not greater than the page count
                if (pagestate.PageNumber > pagecount)
                {
                    pagestate.PageNumber = pagecount;
                    SavePageState(pagestate);
                }

                // Set the page number and account in viewdata
                ViewData["PageNumber"]  = Convert.ToString(pagestate.PageNumber);
                ViewData["PageCount"]   = Convert.ToString(pagecount);
                ViewData["RecordCount"] = Convert.ToString(recordcount);

                // We need to add the account name
                IEnumerable <User> users     = repository.GetUserPage(pagestate.AccountID, pagestate.Username, pagestate.IncludeInactive, pagestate.SortBy, isdescending, pagestate.PageNumber, pagecount);
                List <UserView>    userviews = new List <UserView>();
                IAccountRepository acctrep   = new EntityAccountRepository();
                foreach (User user in users)
                {
                    UserView userview = new UserView();
                    userview.UserID    = user.UserID;
                    userview.AccountID = user.AccountID;
                    Account acct = acctrep.GetAccount(user.AccountID);
                    userview.AccountName  = acct.AccountName;
                    userview.Username     = user.Username;
                    userview.FirstName    = user.FirstName;
                    userview.LastName     = user.LastName;
                    userview.EmailAddress = user.EmailAddress;
                    userview.IsAdmin      = user.IsAdmin;
                    userview.IsActive     = user.IsActive;

                    userviews.Add(userview);
                }

                ViewResult result = View(userviews);
                result.ViewName = "Index";
                return(result);
            }
            catch (Exception ex)
            {
                Helpers.SetupApplicationError("User", "Index", ex.Message);
                return(RedirectToAction("Index", "ApplicationError"));
            }
        }
Beispiel #3
0
        public ActionResult Validate(FormCollection collection)
        {
            try
            {
                // Validate the login
                User user = repository.ValidateLogin(Request.Form["txtUsername"].ToString(), Request.Form["txtPassword"].ToString());

                ViewData["FreeLinks"] = "";
                if (ConfigurationManager.AppSettings["ShowFreeLinks"] == "true")
                {
                    ViewData["FreeLinks"] = BuildFreeLinks();
                }

                // Display the system messages, if any
                ViewData["SystemMessages"] = BuildSystemMessages();

                if (user == null)
                {
                    ViewData["Username"]          = Request.Form["txtUsername"].ToString();
                    ViewData["Password"]          = String.Empty;
                    ViewData["ValidationMessage"] = "Invalid Login. Please try again.";
                    ViewData["LoginInfo"]         = "Please log in.";

                    return(View());
                }
                else
                {
                    Session["User"]          = user;
                    Session["UserAccountID"] = user.AccountID;

                    IAccountRepository acctrep = new EntityAccountRepository();
                    Account            account = acctrep.GetAccount(user.AccountID);
                    Session["UserAccountName"] = account.AccountName;

                    // Make sure the Account Folders exist
                    string serverpath = Server.MapPath("~/UploadedFiles");
                    if (!serverpath.EndsWith(@"\"))
                    {
                        serverpath += @"\";
                    }
                    System.IO.Directory.CreateDirectory(serverpath + user.AccountID.ToString() + @"\Images");
                    System.IO.Directory.CreateDirectory(serverpath + user.AccountID.ToString() + @"\Videos");
                    System.IO.Directory.CreateDirectory(serverpath + user.AccountID.ToString() + @"\Music");

                    serverpath = Server.MapPath("~/Media");
                    if (!serverpath.EndsWith(@"\"))
                    {
                        serverpath += @"\";
                    }
                    System.IO.Directory.CreateDirectory(serverpath + user.AccountID.ToString() + @"\Images");
                    System.IO.Directory.CreateDirectory(serverpath + user.AccountID.ToString() + @"\Videos");
                    System.IO.Directory.CreateDirectory(serverpath + user.AccountID.ToString() + @"\Music");

                    // Create example data for the account (if appropriate)
                    IPlayerGroupRepository    pgrep  = new EntityPlayerGroupRepository();
                    IEnumerable <PlayerGroup> groups = pgrep.GetAllPlayerGroups(account.AccountID);
                    if (groups == null || groups.Count() == 0)
                    {
                        acctrep.CreateExampleData(account.AccountID);
                    }

                    // Log the login
                    ILoginLogRepository llrep    = new EntityLoginLogRepository();
                    LoginLog            loginlog = new LoginLog();
                    loginlog.AccountID     = user.AccountID;
                    loginlog.UserID        = user.UserID;
                    loginlog.Username      = user.Username;
                    loginlog.LoginDateTime = DateTime.Now.ToUniversalTime();
                    llrep.CreateLoginLog(loginlog);

                    return(RedirectToAction("Index", "PlayerGroup"));
                }
            }
            catch (Exception ex)
            {
                Helpers.SetupApplicationError("Login", "Validate POST", ex.Message);
                return(RedirectToAction("Index", "ApplicationError"));
            }
        }