コード例 #1
0
ファイル: Global.asax.cs プロジェクト: thiago-vivas/Blog
        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);
        }
コード例 #2
0
 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;
 }
コード例 #7
0
 public CommentsRepositories(BlogEntities BlogEntities)
 {
     this.db = BlogEntities;
 }
コード例 #8
0
 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;
 }