Ejemplo n.º 1
0
 public DtlsServer(TlsKeyPairSet serverKeys, KeySet userKeys)
 {
     _serverKeys         = serverKeys;
     _userKeys           = userKeys;
     mPskIdentityManager = new MyIdentityManager(userKeys);
     mPskIdentityManager.TlsEventHandler += OnTlsEvent;
 }
Ejemplo n.º 2
0
        //Get: AdminMainPage/ManageRolesForUser
        //it will manage the roles.
        //presenting the previous roles, user selects new roles, ALL previous roles dropped, and all user selected roles added
        public ActionResult ManageRolesForUser(string id)
        {
            if (id.IsNullOrWhiteSpace())
            {
                return(HttpNotFound("id null or whitespace"));
            }
            MyIdentityManager myIdentityManager = new MyIdentityManager();

            List <SelectListItem> passingRolesList = new List <SelectListItem>();
            var allRoles = myIdentityManager.GetAllRoles();

            if (allRoles.Count == 0)
            {
                return(HttpNotFound("No roles available in the system. Create a New Role First!"));
            }
            foreach (var role in allRoles)
            {
                SelectListItem listItem = new SelectListItem()
                {
                    Text = role.Name, Value = role.Name
                };
                passingRolesList.Add(listItem);
            }
            var dictionary = new Dictionary <string, object>();

            dictionary.Add("selectlist", passingRolesList);
            dictionary.Add("username", myIdentityManager.GetUserByIdentityUserId(id).UserName);

            IEnumerable <SelectListItem> rolesienum = myIdentityManager.AllRolesToIenumSelectListItemsForuser(id);

            dictionary.Add("ienum", rolesienum);
            myIdentityManager.Dispose();
            return(PartialView(dictionary));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> UserEdit(string id)
        {
            if (id.IsNullOrWhiteSpace())
            {
                return(HttpNotFound("id IsNullOrWhiteSpace!"));
            }
            MyIdentityManager myIdentityManager = new MyIdentityManager();
            ApplicationUser   user;

            try {
                user = myIdentityManager.GetUserByIdentityUserId(id);
            }
            catch (Exception e) {
                return(HttpNotFound("user not found!!" + e));
            }

            MyComboItemManager          myComboItemManager = new MyComboItemManager();
            Dictionary <object, object> dictionary         = new Dictionary <object, object>();

            var I2 = myComboItemManager.GetAllRolesForUserIdToIenumSelectListItem(id);

            dictionary.Add("ienum", I2);
            dictionary.Add("applicationUser", user);

            myIdentityManager.Dispose();
            myComboItemManager.DisposeAll();
            return(PartialView("UserEdit", dictionary));
        }
Ejemplo n.º 4
0
        public ActionResult UserDetails(string id)
        {
            if (id == null)
            {
                Debug.WriteLine("id null"); return(HttpNotFound("id null"));
            }
            MyIdentityManager           myIdentityManager      = new MyIdentityManager();
            List <object>               listOfDetailsToDisplay = new List <object>();
            Dictionary <string, object> dictionary             = new Dictionary <string, object>();

            // find what user we are talking about
            Debug.WriteLine("Details called for id: " + id);
            var user = myIdentityManager.GetUserByIdentityUserId(id);

            //ad what we need to the dictionary
            try {
                dictionary.Add("user", user);
                dictionary.Add("UserRolesList", myIdentityManager.GetUserRoles(id));
            }
            catch (Exception e) { Debug.WriteLine(e); }
            if (dictionary.Count == 0)
            {
                Debug.WriteLine("id wrong"); return(HttpNotFound("id wrong"));
            }

            //myIdentityManager.Dispose();
            return(PartialView(dictionary));
        }
Ejemplo n.º 5
0
 internal DtlsServer(KeySet serverKeys, KeySet userKeys)
 {
     _serverKeys         = serverKeys;
     _userKeys           = userKeys;
     mPskIdentityManager = new MyIdentityManager(userKeys);
     mPskIdentityManager.TlsEventHandler += OnTlsEvent;
 }
Ejemplo n.º 6
0
        // GET: ComboItems/Create
        public ActionResult Create()
        {
            //in the get, a list of users to select is presented
            MyIdentityManager myIdentityManager = new MyIdentityManager();
            var allUsers = myIdentityManager.GetAllUsers();


            return(View());
        }
Ejemplo n.º 7
0
        public ActionResult DeleteUser(string id)
        {
            if (id.IsNullOrWhiteSpace())
            {
                return(HttpNotFound("id IsNullOrWhiteSpace!"));
            }

            MyIdentityManager myIdentityManager = new MyIdentityManager();
            var user = myIdentityManager.GetUserByIdentityUserId(id);

            myIdentityManager.Dispose();
            return(PartialView(user));
        }
Ejemplo n.º 8
0
        //called by API()
        public ActionResult UsersToJson()
        {
            MyIdentityManager myIdentityManager = new MyIdentityManager();
            var           allUsers  = myIdentityManager.GetAllUsers();
            List <string> usermanes = new List <string>();

            foreach (var applicationUser in allUsers)
            {
                usermanes.Add(applicationUser.UserName);
            }

            var serialized = JsonConvert.SerializeObject(usermanes);

            myIdentityManager.Dispose();
            return(Content(serialized, typeof(Json).Name));
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> ManageRolesForUser(string id, string[] role, FormCollection collection)
        {
            MyIdentityManager myIdentityManager = new MyIdentityManager();

            var user = myIdentityManager.SearchUserById(id);

            #region safety checks
            if (user == null)
            {
                return(HttpNotFound("User with id " + id + "not found!"));
            }
            if (role == null) //list emptied out
            {                 // all roles must be removed
                myIdentityManager.RemoveUserFromRoles(id);
                return(Json(new { success = true }));
            }
            //delete all roles form user, and add the new roles in the table
            if (!myIdentityManager.RemoveUserFromRoles(id).Succeeded)
            {
                return(HttpNotFound("removeRolesError"));
            }
            var result = false;
            foreach (var r in role)
            {
                if (r.IsNullOrWhiteSpace())
                {
                    return(HttpNotFound("AddNewRoleToUser: a role in the roles table is null or whitespace!"));
                }
                //if role exists and we are not trying to add the user to an non existing role in the db
                if (!myIdentityManager.RoleExist(r))
                {
                    return(HttpNotFound("AddNewRoleToUser: system roles not representing roles table"));
                }
                //if user is already in this role
                result = myIdentityManager.AddUserToRole(id, r);
            }
            #endregion
            //add user to every role
            //var result = myIdentityManager.AddUserToRoles(id, role);
            myIdentityManager.Dispose();
            if (result == true)
            {
                return(Json(new { success = true }));
            }
            return(HttpNotFound("AddNewRoleToUser: Error adding role: " + role + " to user with id " + id));
        }
Ejemplo n.º 10
0
        public ActionResult UsersToXml()
        {
            string            xml = "<?xml version = \"1.0\" encoding= \"utf-8\"?>";
            MyIdentityManager myIdentityManager = new MyIdentityManager();
            var users = myIdentityManager.GetAllUsers();

            xml = xml + "<Users>";
            foreach (var user in users)
            {
                xml = xml + "<Name>";
                xml = xml + user.Id;
                xml = xml + "</Name>";
            }
            xml = xml + "</Users>";

            myIdentityManager.Dispose();
            return(Content(xml, "text/xml"));
        }
Ejemplo n.º 11
0
        public async Task <ActionResult> ManageComboItemsforUser(string id, string[] ComboItems, FormCollection collection)
        {
            MyIdentityManager  myIdentityManager  = new MyIdentityManager();
            MyComboItemManager myComboItemManager = new MyComboItemManager();

            if (ComboItems != null)
            {
                foreach (var comboItem in ComboItems)
                {
                    if (comboItem.IsNullOrWhiteSpace())
                    {
                        return(HttpNotFound("AddNewRoleToUser: a role in the roles table is null or whitespace!"));
                    }
                    //if role exists and we are not trying to add the user to an non existing role in the db
                }
            }// if ComboItems==null is checked by UpdateComboItemsforUser, and there is an action for that

            if (id.IsNullOrWhiteSpace())
            {
                return(HttpNotFound("User Id Is null! 4956"));
            }

            //find user
            var user = myIdentityManager.SearchUserById(id);

            if (user == null)
            {
                return(HttpNotFound("User with id " + id + "not found!"));
            }
            //if (ComboItems == null) { return HttpNotFound("ManageRolesForUser: ComboItems table zero"); }

            //Logic to update with new selection of ComboItems
            bool result = myComboItemManager.UpdateComboItemsforUser(id, ComboItems);

            myComboItemManager.DisposeAll();
            myIdentityManager.Dispose();
            if (result == true)
            {
                return(Json(new { success = true }));
            }
            return(HttpNotFound("AddNewRoleToUser: Error adding role: " + " to user with id " + id));
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> UserEdit([Bind
                                                       (Include = "EnrollmentDate,Email,Id,EmailConfirmed," +
                                                                  "PhoneNumber,PhoneNumberConfirmed," +
                                                                  "TwoFactorEnabled,LockoutEnabled," +
                                                                  "AccessFailedCount,UserName," +
                                                                  "Address," +
                                                                  "LockoutEndDateUtc,ComboItems,")]
                                                  ApplicationUser applicationUser, string[] ComboItems)
        {
            if (ModelState.IsValid)
            {
                MyIdentityManager  myIdentityManager  = new MyIdentityManager();
                MyComboItemManager myComboItemManager = new MyComboItemManager();
                //get the user based on the id
                var userEdited = myIdentityManager.SearchUserById(applicationUser.Id);

                myComboItemManager.UpdateComboItemsforUser(applicationUser.Id, ComboItems);

                userEdited.EnrollmentDate       = applicationUser.EnrollmentDate;
                userEdited.Email                = applicationUser.Email;
                userEdited.Address              = applicationUser.Address;
                userEdited.EmailConfirmed       = applicationUser.EmailConfirmed;
                userEdited.PhoneNumber          = applicationUser.PhoneNumber;
                userEdited.PhoneNumberConfirmed = applicationUser.PhoneNumberConfirmed;
                userEdited.TwoFactorEnabled     = applicationUser.TwoFactorEnabled;
                userEdited.LockoutEnabled       = applicationUser.LockoutEnabled;
                userEdited.LockoutEndDateUtc    = applicationUser.LockoutEndDateUtc;
                userEdited.AccessFailedCount    = applicationUser.AccessFailedCount;
                userEdited.UserName             = applicationUser.UserName;
                var userEditResult = myIdentityManager.UpdateUser(userEdited);

                if (!userEditResult.Succeeded)
                {
                    return(HttpNotFound("not updated"));
                }

                myComboItemManager.DisposeAll();
                return(Json(new { success = true }));
            }
            return(HttpNotFound("Not Valid mod"));
        }
Ejemplo n.º 13
0
        public ActionResult DeleteUser(string id, FormCollection collection)
        {
            if (id.IsNullOrWhiteSpace())
            {
                return(HttpNotFound("id IsNullOrWhiteSpace!"));
            }

            MyIdentityManager myIdentityManager = new MyIdentityManager();
            var user   = myIdentityManager.GetUserByIdentityUserId(id);
            var result = myIdentityManager.DeleteMemberShipUser(user);

            myIdentityManager.Dispose();
            if (result.Succeeded)
            {
                return(Json(new { success = true }));
            }
            else
            {
                return(HttpNotFound("Error deleting user"));
            }
        }
Ejemplo n.º 14
0
 internal DtlsServer(KeySet serverKeys, KeySet userKeys)
 {
     _serverKeys         = serverKeys;
     _userKeys           = userKeys;
     mPskIdentityManager = new MyIdentityManager(userKeys);
 }
Ejemplo n.º 15
0
 internal TlsServer(TlsKeyPairSet serverKeys, KeySet userKeys)
 {
     _serverKeys         = serverKeys;
     _userKeys           = userKeys;
     mPskIdentityManager = new MyIdentityManager(userKeys);
 }
Ejemplo n.º 16
0
        public async Task <ActionResult> AddNewUser(
            [Bind(
                 Include =
                     "Email,Password,UserName,EnrollmentDate,PhoneNumber,PhoneNumberConfirmed" +
                     ",TwoFactorEnabled,Address,LockoutEnabled,LockoutEndDateUtc,AccessFailedCount,EmailConfirmed,ComboItemsStrTable"
                 )] AddNewUserViewModel addNewUserViewModel)
        {
            MyIdentityManager myIdentityManager = new MyIdentityManager();

            if (!ModelState.IsValid)  //if the modelstate is not valid, pass the errors to a string, and display via httpnotfount. Not the best way, but works
            {
                #region error reporting
                var modelStateerrors = ModelState.Where(x => x.Value.Errors.Count > 0)
                                       .Select(x => new { x.Key, x.Value.Errors }).ToArray();
                string errorList = "";


                if (modelStateerrors != null)
                {
                    foreach (var modelerr in modelStateerrors)
                    {
                        foreach (var modelerro in modelerr.Errors)
                        {
                            errorList = errorList + " | " + modelerro.ErrorMessage;
                        }
                    }
                }
                //return PartialView("CustomError", errorList);
                #endregion
            }
            //our user, to ASPNET user. Relying to ASPNET's input error checks etc
            DateTime temp = DateTime.Now;
            var      user = new ApplicationUser {
                Email                = addNewUserViewModel.Email,
                UserName             = addNewUserViewModel.Email,
                Address              = addNewUserViewModel.Address,
                EnrollmentDate       = addNewUserViewModel.EnrollmentDate ?? temp, //if the user leaves that blank, fill it with datetime.now
                PhoneNumber          = addNewUserViewModel.PhoneNumber,
                PhoneNumberConfirmed = addNewUserViewModel.PhoneNumberConfirmed,
                TwoFactorEnabled     = addNewUserViewModel.TwoFactorEnabled,
                LockoutEnabled       = addNewUserViewModel.LockoutEnabled,
                LockoutEndDateUtc    = addNewUserViewModel.LockoutEndDateUtc,
                AccessFailedCount    = addNewUserViewModel.AccessFailedCount ?? 0, //if the user leaves that blank, make it 0
                EmailConfirmed       = addNewUserViewModel.EmailConfirmed
            };
            var  createUserResult         = myIdentityManager.CreateNewUser(user, addNewUserViewModel.Password);
            bool addComboItemToUserResult = false;
            if (createUserResult.Succeeded)
            {
                //foreach (var selectListItem in addNewUserViewModel.ComboItems)
                //{
                //    MyComboItemManager myComboItemManager = new MyComboItemManager();
                //    if (selectListItem.Selected)
                //    {
                //        addComboItemToUserResult = myComboItemManager.AddComboItemToUser(user.Id, selectListItem.Value);
                //    }
                //}

                //if (addComboItemToUserResult)
                // the above is the proper way. DropDownList returns a string[] instead a fking IEnumerable<SelectListItem>. FK that

                MyComboItemManager myComboItemManager = new MyComboItemManager();
                addComboItemToUserResult = myComboItemManager.UpdateComboItemsforUser(user.Id, addNewUserViewModel.ComboItemsStrTable);
                myComboItemManager.DisposeAll();
                myIdentityManager.Dispose();
                return(Json(new { success = true }));
                //else
                //    return HttpNotFound("Could not add Comboitems to User");
            }
            else
            {
                return(HttpNotFound("User data not valid, please try again"));
            }
        }