示例#1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName     = model.Email,
                    Email        = model.Email,
                    PhoneNumber  = model.PhoneNumber,
                    FirstName    = model.FirstName,
                    LastName     = model.LastName,
                    ViewToPublic = model.ViewToPublic,
                    IsAPilot     = GetRoleNameFromRoleId(model.Role.RoleId) == "Pilot" || model.IsAPilot
                };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var    im       = new IdentityManager();
                    string roleName = _db.Roles.Find(model.Role.RoleId).Name;
                    im.AddUserToRole(user.Id, roleName);
                    if (user.IsAPilot)
                    {
                        var pm = new PilotManager();
                        pm.AddPilot(user);
                    }
                    if (roleName != "Admin")
                    {
                        return(RedirectToAction("Index", "Account"));
                    }
                    List <Plane> planes = _db.Planes.ToList();
                    foreach (Plane plane in planes)
                    {
                        UserManager.AddClaim(user.Id, new Claim("PlaneAccess", plane.TailNumber));
                    }
                    //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Account"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#2
0
        //Returns unique online user ID for this player
        public static void GetUserID(out IdType id_type, out string id)
        {
#if UNITY_XBOXONE
            // Xbox One does not want XUID stored in a database, so we are going to treat Xbox One like PC without Steam/GOG. Old method is
            // commented out below for comparison.

            /*
             * id_type = IdType.XBLive;
             * id = XboxOneManager.GetActiveUserXuid();
             */
            id_type = IdType.Local;
            id      = Player.Mp_user_id;
            if (string.IsNullOrEmpty(id))
            {
                id = Guid.NewGuid().ToString();
                Player.Mp_user_id = id;
                PilotManager.SavePreferences();                 // save prefs, which stores Player.Mp_user_id in the profile
            }
            return;
#elif UNITY_PS4
            id_type = IdType.PSN;
            id      = PS4Manager.UserId.ToString();
            return;
#else
            if (CloudProvider == CloudProviders.Steam)
            {
                id_type = IdType.Steam;
                id      = Steamworks.SteamUser.GetSteamID().ToString();
                return;

#if !UNITY_STANDALONE_LINUX
            }
            else if (CloudProvider == CloudProviders.Galaxy)
            {
                id_type = IdType.Galaxy;
                id      = Galaxy.Api.GalaxyInstance.User().GetGalaxyID().ToString();
                return;
#endif
            }
            else
            {
                id_type = IdType.Local;
                id      = PlayerPrefs.GetString("UserID");
                if (id == "")
                {
                    id = Guid.NewGuid().ToString();
                    PlayerPrefs.SetString("UserID", id);
                }
            }
#endif
        }
示例#3
0
        static void ReadControlData()
        {
            string fn = PilotManager.FileName(PilotFileType.CONFIG) + "mod";

            for (int i = 0; i < Controls.m_controllers.Count; i++)
            {
                int[] m_sensitivity = (int[])AccessTools.Field(typeof(Overload.Controller), "m_sensitivity").GetValue(Controls.m_controllers[i]);
                int[] m_deadzone    = (int[])AccessTools.Field(typeof(Overload.Controller), "m_deadzone").GetValue(Controls.m_controllers[i]);

                Controllers.controllers.Add(new Controllers.Controller
                {
                    axes = new List <Controllers.Controller.Axis>()
                });
                for (int j = 0; j < Controls.m_controllers[i].m_axis_count; j++)
                {
                    int   dz_index   = Controls.m_controllers[i].GetAxisDeadzone(j);
                    int   sens_index = Controls.m_controllers[i].GetAxisSensitivity(j);
                    float sens       = (RWInput.sens_multiplier[m_sensitivity[sens_index]] / 2.2f) * 100f;
                    float deadzone   = (Controls.DEADZONE_ADDITIONAL[m_deadzone[dz_index]] / 0.5f) * 100f;

                    Controllers.controllers[i].axes.Add(new Controllers.Controller.Axis()
                    {
                        sensitivity = sens,
                        deadzone    = deadzone
                    });
                }
            }
            Controllers.m_serialized_data = Platform.ReadTextUserData(fn);
            if (Controllers.m_serialized_data == null)
            {
                Controllers.m_serialized_data = String.Empty;
                Debug.Log("No existing .xconfigmod file");
                return;
            }
            using (MemoryStream memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(Controllers.m_serialized_data)))
            {
                using (StreamReader streamReader = new StreamReader(memoryStream))
                {
                    ReadControlDataFromStream(streamReader);
                }
            }
        }
示例#4
0
        public ActionResult DeleteConfirmed(ApplicationUser userId)
        {
            ApplicationUser user = _db.Users.Find(userId.Id);

            if (user.IsAPilot)
            {
                var pm = new PilotManager();
                pm.RemovePilot(user);
            }

            List <IdentityUserClaim> claims = user.Claims.ToList();

            foreach (IdentityUserClaim claim in claims)
            {
                user.Claims.Remove(claim);
            }


            _db.Users.Remove(user);

            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
示例#5
0
        public static void SaveActivePilot()
        {
            if (!PilotManager.Exists(PilotManager.ActivePilot))
            {
                return;
            }
            try
            {
                string filepath = Path.Combine(Application.persistentDataPath, PilotManager.ActivePilot + file_extension);

                using (StreamWriter w = File.CreateText(filepath))
                {
                    w.WriteLine("[SECTION: AUTOSELECT]");
                    Section_AutoSelect.Save(w);
                    w.WriteLine("[/END]");

                    w.WriteLine("[SECTION: JOYSTICKCURVE]");
                    Section_JoystickCurve.Save(w);
                    w.WriteLine("[/END]");

                    //...

                    if (unknown_sections != null)
                    {
                        foreach (string line in unknown_sections)
                        {
                            w.WriteLine(line);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Log("Error in ExtendedConfig.SaveActivePilot(): " + ex);
            }
        }
示例#6
0
        public async Task <ActionResult> Edit(EditViewModel idModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(idModel));
            }
            List <IdentityRole> roleUserList = _db.Roles.ToList();

            foreach (IdentityRole userRole in roleUserList)
            {
                List <IdentityUserRole> userRoleList = userRole.Users.ToList();
                foreach (IdentityUserRole u in userRoleList.Where(u => u.UserId == idModel.Id))
                {
                    AddOrRemoveFromRole(u.UserId, u.RoleId);
                }
            }
            AddOrRemoveFromRole(idModel.Id, idModel.RoleId);

            _db.SaveChanges();
            ApplicationUser user = await UserManager.FindByIdAsync(idModel.Id);

            user.UserName     = idModel.Email;
            user.Email        = idModel.Email;
            user.PhoneNumber  = idModel.PhoneNumber;
            user.FirstName    = idModel.FirstName;
            user.LastName     = idModel.LastName;
            user.ViewToPublic = idModel.ViewToPublic;
            user.IsAPilot     = GetRoleNameFromUserId(idModel.Id) == "Pilot" || idModel.IsAPilot;


            IdentityResult result = await UserManager.UpdateAsync(user);

            if (result.Succeeded)
            {
                var pm = new PilotManager();
                if (user.IsAPilot)
                {
                    if (!pm.PilotExists(user))
                    {
                        pm.AddPilot(user);
                    }
                }
                else
                {
                    if (pm.PilotExists(user))
                    {
                        pm.RemovePilot(user);
                    }
                }
                if (GetRoleNameFromRoleId(idModel.RoleId) != "Admin")
                {
                    return(RedirectToAction("Index"));
                }
                List <Plane>  planes = _db.Planes.ToList();
                List <string> claims =
                    user.Claims.Where(c => c.ClaimType == "PlaneAccess").Select(c => c.ClaimValue).ToList();
                foreach (Plane plane in planes)
                {
                    if (!claims.Contains(plane.TailNumber))
                    {
                        UserManager.AddClaim(user.Id, new Claim("PlaneAccess", plane.TailNumber));
                    }
                }
                return(RedirectToAction("Index"));
            }
            MessageBox.Show(result.Errors.FirstOrDefault());
            return(View(idModel));
        }