Exemplo n.º 1
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(this.RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                //// Insert a new user into the database
                using (CommunityDaysDb db = new CommunityDaysDb())
                {
                    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();

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

                        return(this.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(this.View(model));
        }
Exemplo n.º 2
0
            public SimpleMembershipInitializer()
            {
                Database.SetInitializer <CommunityDaysDb>(null);

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

                    ////  WebSecurity.InitializeDatabaseConnection("DefaultConnection", "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);
                }
            }
Exemplo n.º 3
0
        public void ExternalWebOpportunityCreate()
        {
            int             id     = 1;
            CommunityDaysDb db     = new CommunityDaysDb();
            var             status = new OpportunityStatus
            {
                OpportunityStatusId          = id,
                OpportunityStatusDescription = "First status"
            };

            var user = new UserProfile
            {
                UserId   = id,
                UserName = "******"
            };

            var company = new Company
            {
                CompanyId   = id,
                CompanyName = "First Company"
            };

            db.Company.Add(company);
            db.UserProfiles.Add(user);
            db.OpportunityStatus.Add(status);
            db.SaveChanges();

            // Arrange
            OpportunityController controller = new OpportunityController();
            var model = new Opportunity
            {
                OpportunityId                    = id,
                OpportunityStatusId              = id,
                CompanyId                        = id,
                MinNumberofVolunteers            = id,
                MaxNumberofVolunteers            = id,
                OpportunityLocationName          = "ABERFELDY",
                OpportunityPostcode              = "BD23 1PT",
                OpportunityTitle                 = "BREADALBANE CANOE CLUB EVENT",
                OpportunityDescription           = "ASSIST AS HELPERS AT OUR SLALOM KAYAKING COMPETITION IN ABERFELDY 1ST & 2ND OF APRIL - CAR PARKING, CATERING TENT, HELPING CHILDREN GET IN AND OUT OF BOATS, HELP CARRY BOATS, ETC. OUR OTHER COMPETITION AT GRANDTULLY ON THE 30TH AND 31ST OF MARCH WOULD BENEFIT FROM ANY HELPERS AS WELL. IT IS A PREMIER EVENT AND SOME PREVIOUS OLYMPIC MEDALISTS COMPETE THERE. THE ADVENTURE SHOW ALSO FILMS THE EVENT.",
                OpportunityDate                  = System.DateTime.Now.AddDays(5).ToShortDateString(),
                OpportunityCreatedDate           = System.DateTime.Now,
                OpportunityAdditionalInformation = "Created: " + System.DateTime.Now.ToString()
            };

            /*var parentmodel = new OpportunityViewModelExternalWeb.ViewModels.OpportunityViewModel
             * {
             *  Opportunity = model,
             *  EventDate = System.DateTime.Now
             * };
             *
             * // Act
             * var redirectToRouteResult = controller.Create(model) as RedirectToRouteResult;
             * //ViewResult result = controller.Edit(id) as ViewResult;
             * //Opportunity modelResult = (Opportunity)result.ViewData.Model;
             *
             * // Assert
             * Assert.IsNotNull(redirectToRouteResult);
             * Assert.AreEqual("Index", redirectToRouteResult.RouteValues["Action"]);
             * Assert.AreEqual("OpportunityController", redirectToRouteResult.RouteValues["controller"]);
             * //Assert.AreEqual(model.OpportunityId, modelResult.OpportunityId);
             * */
        }