Exemplo n.º 1
0
        // Method to handle user login validation, obtain user
        // information, and redirect client following login attempt.
        protected void EquipCheckLoginCtrl_Authenticate(object sender, AuthenticateEventArgs e)
        {
            EquipCheckAppUser user = new EquipCheckAppUser();

            user.Username = EquipCheckLoginCtrl.UserName;
            user.Password = EquipCheckLoginCtrl.Password;

            UserManager       userMgr      = new UserManager();
            EquipCheckAppUser userAtServer = userMgr.RetrieveUser(user);

            if (userAtServer != null)
            {
                e.Authenticated = true;

                EquipCheckAppUser userLocal = userMgr.RetrieveLocalUser(userAtServer);

                if (userLocal == null)
                {
                    userLocal = userMgr.CreateUser(userAtServer);
                    userLocal = ListCreation.CreateLists(userLocal);
                }

                // Get user's checklists
                CheckListManager checkListManager = new CheckListManager();
                List <CheckList> checkLists       = checkListManager.RetrieveCheckLists(userLocal);
                List <String>    checkListNames   = checkListManager.getCheckListNames(checkLists);

                userLocal.AllCheckList      = checkLists;
                userLocal.AllCheckListNames = checkListNames;

                // Get user's equipment lists
                EquipListManager     equipListManager = new EquipListManager();
                List <EquipmentList> equipLists       = equipListManager.RetrieveEquipLists(userLocal);

                if (equipLists == null || equipLists.Count == 0)
                {
                    userLocal = ListCreation.CreateLists(userLocal);
                }
                else
                {
                    List <String> equipListNames = equipListManager.getEquipmentListNames(equipLists);
                    userLocal.AllEquipLists     = equipLists;
                    userLocal.AllEquipListNames = equipListNames;
                }

                Session["user"] = userLocal;

                Response.Redirect("/Restricted/Welcome.aspx");
            }
            else
            {
                e.Authenticated = false;

                Session["user"]         = null;
                Session["message_type"] = "login_error";
                Session["message"]      = "Login Error.";
                Session["details"]      = "User Credentials Invalid.";
                Response.Redirect("/Restricted/Message.aspx");
            }
        }
Exemplo n.º 2
0
        // Method to initialize a new user account
        protected void CreateUserWizard_CreatedUser(object sender, EventArgs e)
        {
            EquipCheckAppUser userAtServer = (EquipCheckAppUser)Session["user"];
            UserManager       userManager  = new UserManager();

            userAtServer = userManager.RetrieveUser(userAtServer);

            Roles.AddUserToRole(userAtServer.Username, "Members");

            EquipCheckAppUser userLocal = null;

            if (userAtServer != null)
            {
                userLocal = userManager.CreateUser(userAtServer);
            }

            if (userLocal != null)
            {
                userLocal = ListCreation.CreateLists(userLocal);
            }
        }