예제 #1
0
        // This URL is registered as the application's callback at http://dev.twitter.com
        public ActionResult AuthorizeCallback(string oauth_token, string oauth_verifier)
        {
            var requestToken = new OAuthRequestToken { Token = oauth_token };

            // Step 3 - Exchange the Request Token for an Access Token
            TwitterService service = new TwitterService(TwitterConsumerKey, TwitterConsumerSecret);
            OAuthAccessToken accessToken = service.GetAccessToken(requestToken, oauth_verifier);
            // Step 4 - User authenticates using the Access Token
            service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);

            String token = accessToken.Token + " " + accessToken.TokenSecret;

            DatabaseContext db = new DatabaseContext();
            db.SocAccounts.Add(new SocAccount(2, token, getUserId()));
            db.SaveChanges();
            return View();
        }
            public SimpleMembershipInitializer()
            {
                Database.SetInitializer<DatabaseContext>(null);

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

                    WebSecurity.InitializeDatabaseConnection("DatabaseContext", "Users", "Id", "Email", 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);
                }
            }
예제 #3
0
 public int getUserId()
 {
     DatabaseContext db = new DatabaseContext();
     string login = HttpContext.User.Identity.Name;
     return db.Users.Where(u => u.Email == login).FirstOrDefault().Id;
 }
예제 #4
0
        public static Tuple<String, String, String> getCommentData(ClientComment cc)
        {
            DatabaseContext db = new DatabaseContext();
            int ID_GROUP = db.ContentsInGroups.Join(db.ClientComments,
                c => c.ID_CIG,
                q => q.ID_CIG,
                (c, q) => new { c, q }).Select(w => w.c.ID_GROUP).First();
            String VK_ID_GR = db.Groups.Where(g => g.ID == ID_GROUP).Select(w => w.ID_GROUP).Single();

            int ID_POST = db.ContentsInGroups.Where(c => c.ID_CIG == cc.ID_CIG).Select(c => c.ID_POST).Single();

            WebClient wc = new WebClient();
            wc.Encoding = Encoding.UTF8;
            String test = "https://api.vk.com/method/wall.getComments?owner_id=-" + VK_ID_GR + "&post_id=" + ID_POST + "&start_comment_id=" + cc.ID_COMMENT + "&count=1&v=5.37";
            String answer = wc.DownloadString("https://api.vk.com/method/wall.getComments?owner_id=-" + VK_ID_GR + "&post_id=" + ID_POST + "&start_comment_id=" + cc.ID_COMMENT + "&count=1&v=5.37");
            JObject obj = JObject.Parse(answer);
            String text = obj["response"]["items"].First["text"].ToString();

            String clientName = db.Clients.Where(c => c.ID_CL == cc.ID_CL).Select(c => c.NAME).Single();
            String client_ID_VK = db.Clients.Where(c => c.ID_CL == cc.ID_CL).Select(c => c.ID_VK).Single();
            answer = wc.DownloadString("https://api.vk.com/method/users.get?user_ids=" + client_ID_VK + "&fields=photo_50");
            obj = JObject.Parse(answer);
            String photoUrl = obj["response"].First["photo_50"].ToString();

            return new Tuple<string, string, string>(photoUrl, clientName, text);
        }
예제 #5
0
        public static List<Tuple<String, String>> getAdmGroups()
        {
            int userId = getUserId();
            WebClient wc = new WebClient();
            wc.Encoding = Encoding.UTF8;
            DatabaseContext db = new DatabaseContext();
            int idAcc = db.SocAccounts.Where(s => s.ID_USER == userId && s.SOCNET_TYPE == 0).Select(s => s.ID_AC).Single();
            var admGroups = db.Groups.Where(g => g.ID_AC == idAcc).Select(g => g.ID_GROUP).ToList();

            String token = db.SocAccounts.Where(s => s.ID_USER == userId && s.SOCNET_TYPE == 0).Select(s => s.TOKEN).Single();
            String answer = wc.DownloadString("https://api.vk.com/method/groups.get?filter=admin&access_token=" + token);
            JObject obj = JObject.Parse(answer);
            JToken jtoken = obj["response"].First;
            List<String> ids = new List<String>();
            do
            {
                ids.Add((String)jtoken);
                jtoken = jtoken.Next;
            }
            while (jtoken != null);
            List<Tuple<String, String>> groups = new List<Tuple<String, string>>();
            foreach (String id in ids)
            {
                if (!admGroups.Contains(id))
                    groups.Add(new Tuple<String, string>(id, getGroupNameById(id)));
            }
            return groups;
        }
예제 #6
0
        public RedirectResult getToken(String url)
        {
            String code = url.Split('=')[1];
            WebClient wc = new WebClient();
            wc.Encoding = Encoding.UTF8;
            String test = "https://oauth.vk.com/access_token?client_id=" + client_id + "&client_secret=" + client_secret + "&code=" + code + "&redirect_uri=" + redirect_uri;
            String access_token = wc.DownloadString("https://oauth.vk.com/access_token?client_id=" + client_id + "&client_secret=" + client_secret + "&code=" + code);
            JObject obj = JObject.Parse(access_token);
            String VkToken = (string)obj["access_token"];

            DatabaseContext db = new DatabaseContext();

            string login = HttpContext.User.Identity.Name;
            User user = db.Users.Where(u => u.Email == login).FirstOrDefault();
            SocAccount socAcc = new SocAccount(0, VkToken, user.Id);
            db.SocAccounts.Add(socAcc);
            db.SaveChanges();
            /*  if (user != null)
              {
                  db.Entry(socAcc).State = EntityState.Modified;
                  db.SaveChanges();
              }         */
            return RedirectPermanent("~/Tool/SocStudio/");
        }
예제 #7
0
 public static List<ClientComment> getSocialCommentsFromGroup(int ID_GROUP)
 {
     DatabaseContext db = new DatabaseContext();
     List<ClientComment> ccs = db.ClientComments
          .Join(db.ContentsInGroups,
          c => c.ID_CIG,
          q => q.ID_CIG,
          (c, q) => new { c, q }).Where(w => w.q.ID_GROUP == ID_GROUP).Select(v => v.c).ToList();
     return ccs;
 }