Ejemplo n.º 1
0
        public ActionResult signup(signupviewmodel user)
        {
            if (ModelState.IsValid)
            {
                using (EFDbContext context = new EFDbContext())
                {
                    useraccounts chuser = context.useraccount.Where(m => m.user_name == user.user_name || m.email == user.email).Select(s => s).FirstOrDefault();



                    //(from s in context.useraccount where s.user_name == user.user_name || s.email == user.email select s).FirstOrDefault();
                    if (chuser == null)
                    {
                        var          keynew   = HashHelper.GeneratePassword(10);
                        var          password = HashHelper.EncodePassword(user.password, keynew);
                        useraccounts useracc  = new useraccounts();
                        useracc.user_name     = user.user_name;
                        useracc.password      = password;
                        useracc.email         = user.email;
                        useracc.password_salt = keynew;
                        useracc.rolenum       = (int?)user.rolenum;
                        context.useraccount.Add(useracc);
                        context.SaveChanges();
                        ModelState.Clear();
                        return(RedirectToAction("Login"));
                    }
                    ViewBag.ErrorMessage = "User Already Exist";
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
Ejemplo n.º 2
0
        private void AddLocations(useraccounts user)
        {
            // Home and last location
            var locations = m_db.griduser.SingleOrDefault(g => g.UserID == user.PrincipalID);

            if (locations != null)
            {
                Vector3 homePosition, homeLookAt, lastPosition, lastLookAt;
                UUID    homeRegionID, lastRegionID;

                Vector3.TryParse(locations.HomePosition, out homePosition);
                Vector3.TryParse(locations.HomeLookAt, out homeLookAt);
                UUID.TryParse(locations.HomeRegionID, out homeRegionID);

                Vector3.TryParse(locations.LastPosition, out lastPosition);
                Vector3.TryParse(locations.LastLookAt, out lastLookAt);
                UUID.TryParse(locations.LastRegionID, out lastRegionID);

                Dictionary <string, string> userData = new Dictionary <string, string>();

                if (homeRegionID != UUID.Zero)
                {
                    userData["HomeLocation"] = SerializeLocation(homeRegionID, homePosition, homeLookAt);
                }
                if (lastRegionID != UUID.Zero)
                {
                    userData["LastLocation"] = SerializeLocation(lastRegionID, lastPosition, lastLookAt);
                }

                if (userData.Count > 0)
                {
                    AddUserData(user.PrincipalID, userData);
                }
            }
        }
Ejemplo n.º 3
0
        private void AddAppearance(useraccounts user)
        {
            // Avatar appearance
            var metadata = from a in m_db.avatars
                           where a.PrincipalID == user.PrincipalID
                           select a;

            OSDMap appearance  = new OSDMap();
            OSDMap attachments = new OSDMap();

            foreach (var entry in metadata)
            {
                if (entry.Name.StartsWith(AP_PREFIX))
                {
                    attachments[entry.Name] = OSD.FromString(entry.Value);
                }
                else
                {
                    string name = entry.Name;
                    if (name == "AvatarHeight")
                    {
                        name = "Height";
                    }
                    if (name == "BodyItem")
                    {
                        name = "ShapeItem";
                    }
                    if (name == "BodyAsset")
                    {
                        name = "ShapeAsset";
                    }

                    if (ALLOWED_APPEARANCE_ENTRIES.Contains(name))
                    {
                        appearance[name] = OSD.FromString(entry.Value);
                    }
                }
            }

            Dictionary <string, string> userData = new Dictionary <string, string>();

            if (appearance.Count > 0)
            {
                userData["LLAppearance"] = OSDParser.SerializeJsonString(appearance);
            }
            if (attachments.Count > 0)
            {
                userData["LLAttachments"] = OSDParser.SerializeJsonString(attachments);
            }

            if (userData.Count > 0)
            {
                AddUserData(user.PrincipalID, userData);
            }
        }
Ejemplo n.º 4
0
        private void CreateUser(useraccounts user, string gridOwner)
        {
            // Create this user
            string name  = user.FirstName + " " + user.LastName;
            string email = user.Email;

            // If this is the grid owner set them to the maximum AccessLevel. Otherwise, make sure
            // their AccessLevel is at least 1 (representing a verified, non-anonymous account)
            int accessLevel = (!String.IsNullOrEmpty(gridOwner) && name.Equals(gridOwner, StringComparison.InvariantCultureIgnoreCase))
                ? 255
                : user.UserLevel;

            accessLevel = Utils.Clamp(accessLevel, 1, 255);
            if (accessLevel == 255)
            {
                m_masterUserSet = true;
            }

            // Cannot have an empty e-mail address
            if (String.IsNullOrEmpty(email))
            {
                email = "INVALID " + UUID.Random().ToString();
            }

            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "AddUser" },
                { "UserID", user.PrincipalID },
                { "Name", name },
                { "Email", email },
                { "AccessLevel", accessLevel.ToString() }
            };

            OSDMap response = WebUtil.PostToService(m_userUrl, requestArgs);

            if (response["Success"].AsBoolean())
            {
                Dictionary <string, string> userData = new Dictionary <string, string>
                {
                    { "CreationDate", (user.Created.HasValue ? user.Created.Value : (int)Utils.DateTimeToUnixTime(DateTime.UtcNow)).ToString() },
                    { "UserFlags", user.UserFlags.ToString() },
                    { "UserTitle", user.UserTitle }
                };
                AddUserData(user.PrincipalID, userData);
            }
            else
            {
                Console.WriteLine("Failed to store user account for " + name + ": " + response["Message"].AsString());
            }

            AddLocations(user);
            AddAppearance(user);
            AddIdentity(user);
        }
Ejemplo n.º 5
0
        private void AddIdentity(useraccounts user)
        {
            string name = user.FirstName + " " + user.LastName;

            // Create the user identity
            var auth = m_db.auth.SingleOrDefault(a => a.UUID == user.PrincipalID);

            if (auth != null && auth.accountType == USER_ACCOUNT_TYPE)
            {
                string credential = auth.passwordHash;

                // If the password is actually salted store "hash:salt"
                if (!String.IsNullOrEmpty(auth.passwordSalt))
                {
                    credential += ":" + auth.passwordSalt;
                }

                // Make sure $1$ is prepended (our md5hash format in SimianGrid requires this)
                if (!credential.StartsWith("$1$"))
                {
                    credential = "$1$" + credential;
                }

                NameValueCollection requestArgs = new NameValueCollection
                {
                    { "RequestMethod", "AddIdentity" },
                    { "Identifier", name },
                    { "Credential", credential },
                    { "Type", "md5hash" },
                    { "UserID", user.PrincipalID }
                };

                OSDMap response = WebUtil.PostToService(m_userUrl, requestArgs);
                bool   success  = response["Success"].AsBoolean();

                Console.Write(".");

                if (!success)
                {
                    Console.WriteLine("Failed to set password for {0} ({1})", name, user.PrincipalID);
                }
            }
            else
            {
                Console.WriteLine("No authorization info found for " + name);
            }
        }