public UserProfile SeedMembership(MyTeamTrackerContext context)
        {
            //  WebSecurity.InitializeDatabaseConnection(context.Database.Connection.ConnectionString, "UserProfile", "UserId", "UserName", autoCreateTables: true);
            WebSecurity.InitializeDatabaseConnection("data", "UserProfile", "UserId", "UserName", autoCreateTables: true);

            if (!Roles.RoleExists("Administrator"))
                Roles.CreateRole("Administrator");

            if (!WebSecurity.UserExists("pdriscoll"))
                WebSecurity.CreateUserAndAccount(
                    "pdriscoll",
                    "test1234"
                    );

            if (!WebSecurity.UserExists("rwicker"))
                WebSecurity.CreateUserAndAccount(
                    "rwicker",
                    "test1234"
                    );
            if (!WebSecurity.UserExists("test"))
                WebSecurity.CreateUserAndAccount(
                    "test",
                    "testtest"
                    );
            if (!Roles.GetRolesForUser("pdriscoll").Contains("Administrator"))
                Roles.AddUsersToRoles(new[] { "pdriscoll" }, new[] { "Administrator" });

            if (!Roles.GetRolesForUser("rwicker").Contains("Administrator"))
                Roles.AddUsersToRoles(new[] { "rwicker" }, new[] { "Administrator" });
            var userId=WebSecurity.GetUserId("test");
            return context.UserProfiles.Single(x => x.UserId == userId);
        }
예제 #2
0
            public SimpleMembershipInitializer()
            {
                using (var context = new MyTeamTrackerContext())
                  //  context.UserProfiles.Find(1);

                if (!WebSecurity.Initialized)
                    WebSecurity.InitializeDatabaseConnection("context", "UserProfile", "UserId", "UserName", autoCreateTables: true);
            }
        public void Seed(MyTeamTrackerContext context)
        {
            //  var validUser =SeedMembership(context);

               //SeedTeams(context, validUser);
               // SeedPlayers(context);
               // SeedTasks(context);
               // SeedGames(context);
        }
            public SimpleMembershipInitializer()
            {
                Database.SetInitializer<MyTeamTrackerContext>(null);

                try
                {
                    using (var context = new MyTeamTrackerContext())
                    {
                        if (!context.Database.Exists())
                        {
                            // Create the SimpleMembership database without Entity Framework migration schema
                            ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                        }
                    }

                    WebSecurity.InitializeDatabaseConnection("context", "UserProfile", "UserId", "UserName", autoCreateTables: true);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
                }
            }
 public void SeedTeams(MyTeamTrackerContext context, UserProfile coach)
 {
 }
 public void SeedTasks(MyTeamTrackerContext context)
 {
 }
 public void SeedPlayers(MyTeamTrackerContext context)
 {
 }
 public void SeedGames(MyTeamTrackerContext context)
 {
 }
예제 #9
0
 /// <summary>
 /// Initiate a new todo list for new user
 /// </summary>
 /// <param name="userName"></param>
 private static void InitiateDatabaseForNewUser(string userName, string email)
 {
     var context = new MyTeamTrackerContext();
     var user=context.UserProfiles.Single(x => x.UserName == userName);
     user.Email = email;
     context.SaveChanges();
 }
예제 #10
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (MyTeamTrackerContext db = new MyTeamTrackerContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile { UserName = model.UserName});
                        db.SaveChanges();

                        InitiateDatabaseForNewUser(model.UserName, model.Email);

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }