Esempio n. 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            //BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();

            PhotoBookContext context = new PhotoBookContext();
            if (!WebSecurity.Initialized)
                WebSecurity.InitializeDatabaseConnection("PhotoBookContext",
                    "Users", "ID", "UserName", autoCreateTables: true);

            ControllerBuilder.Current.SetControllerFactory(new PhotoBookControllerFactory());
            BootStrapper.ConfigureDependencies();

            var container = ObjectFactory.Container;
            GlobalConfiguration.Configuration.DependencyResolver = new StructureMapDependencyResolver(container);

            //GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            //GlobalConfiguration.Configuration.Formatters.Remove(
            //    GlobalConfiguration.Configuration.Formatters.XmlFormatter);
        }
Esempio n. 2
0
 public Repository(PhotoBookContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     this._context = context;
     this._dbSet   = context.Set <T>();
 }
Esempio n. 3
0
 public TagRepository(PhotoBookContext context) : base(context)
 {
 }
Esempio n. 4
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 (PhotoBookContext db = new PhotoBookContext())
                {
                    User user = db.User.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.User.Add(new User { UserName = model.UserName });
                        db.SaveChanges();

                        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);
        }
Esempio n. 5
0
 public UserRepository(PhotoBookContext context) : base(context)
 {
 }