예제 #1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            BlogEntities db = new BlogEntities();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();
            Database.SetInitializer<BlogEntities>(null);
        }
 public CompaintRepositories(BlogEntities BlogEntities)
 {
     this.db = BlogEntities;
 }
예제 #3
0
 public PhotoRepositories(BlogEntities BlogEntities)
 {
     this.db = BlogEntities;
 }
예제 #4
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model)
        {
            string provider = null;
            string providerUserId = null;
            string returnUrl = 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 (BlogEntities db = new BlogEntities())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.Name.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        //pegando a imagem do perfil do facebook e passando para base64
                        Image image = null;
                        string base64String = null;
                        string URL = "https://graph.facebook.com/" + providerUserId + "/picture";

                        HttpWebRequest req = (System.Net.HttpWebRequest)HttpWebRequest.Create(URL);
                        req.AllowWriteStreamBuffering = true;
                        req.Timeout = 20000;
                        WebResponse resp = req.GetResponse();
                        System.IO.Stream stream = resp.GetResponseStream();
                        image = Image.FromStream(stream);
                        resp.Close();
                        using (MemoryStream ms = new MemoryStream())
                        {
                            // Convert Image to byte[]
                            image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                            byte[] imageBytes = ms.ToArray();

                            // Convert byte[] to Base64 String
                            base64String = Convert.ToBase64String(imageBytes);

                        }
                        //fim da conversão da imagem
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile { UserName = model.Name, FacebookProfileImgUrl = base64String, UserLink = model.Link });
                        db.SaveChanges();

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

                        return RedirectToAction("Index", "Home");
                        //return RedirectToLocal(returnUrl);
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return RedirectToAction("Index", "Home");
        }
예제 #5
0
 public UserRepositories(BlogEntities BlogEntities)
 {
     this.db = BlogEntities;
 }
예제 #6
0
 public CategoriesRepositories(BlogEntities BlogEntities)
 {
     this.db = BlogEntities;
 }
 public CommentsRepositories(BlogEntities BlogEntities)
 {
     this.db = BlogEntities;
 }
 public ArticleRepositories(BlogEntities BlogEntities)
 {
     this.db = BlogEntities;
 }
예제 #9
0
 public RepositoryContainer()
 {
     this.db = new BlogEntities();
 }
예제 #10
0
 public AlbumRepositories(BlogEntities BlogEntities)
 {
     this.db = BlogEntities;
 }
예제 #11
0
 public TagsRepositories(BlogEntities BlogEntities)
 {
     this.db = BlogEntities;
 }