Beispiel #1
0
        public ActionResult WoWProfileInfo([FromServices] AreaDbContext DB)
        {
            WoWModuleModel WoW = new WoWModuleModel("vgf6ne9wt7buaewe48wby99u", 0);

            ViewData["Characters"] = WoW.getCharacters();
            return(View());
        }
        public ActionResult FacebookAuthorized(string state, string code, [FromServices] AreaDbContext DB)
        {
            string username = HttpContext.Session.GetString("username");

            if (String.IsNullOrEmpty(username))
            {
                return(Redirect("http://localhost:5000"));
            }
            var token_uri = "https://graph.facebook.com/v2.11/oauth/access_token";
            var client    = new WebClient {
                UseDefaultCredentials = true
            };

            byte[] response = client.UploadValues(token_uri, new NameValueCollection()
            {
                { "client_id", "130733687642786" },
                { "redirect_uri", "http://localhost:5000/Facebook/FacebookAuthorized" },
                { "client_secret", "f5223fb63a69dfd04c6186ee184a1657" },
                { "code", code }
            });

            // Access_token stored in the following dictionnary
            var jsonResult = JsonConvert.DeserializeObject <Dictionary <string, string> >(System.Text.Encoding.UTF8.GetString(response));

            if (jsonResult["access_token"] != null)
            {
                DB.tokens.Add(new Models.Token {
                    type = "Facebook", username = username, value = jsonResult["access_token"]
                });
                DB.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("Index", "Home"));
        }
Beispiel #3
0
        public async Task <ActionResult> GithubAuthorized(string code, string state, [FromServices] AreaDbContext DB)
        {
            string username = HttpContext.Session.GetString("username");

            if (String.IsNullOrEmpty(username))
            {
                return(Redirect("http://localhost:5000"));
            }
            try {
                var clientId     = "Iv1.81c9b324b18a4188";
                var clientSecret = "d480b95d45b1147557bf97f51f87d0f4f7f9c14a";
                var client       = new GitHubClient(new ProductHeaderValue("AreaNet"));
                if (String.IsNullOrEmpty(code))
                {
                    return(Redirect("http://localhost:5000"));
                }
                var request = new OauthTokenRequest(clientId, clientSecret, code);
                var token   = await client.Oauth.CreateAccessToken(request);

                DB.tokens.Add(new Models.Token {
                    type = "Github", username = username, value = token.AccessToken
                });
                DB.SaveChanges();
            }
            catch
            {
                Console.WriteLine("Error in GithubAuthorize");
                return(Redirect("http://localhost:5000"));
            }
            return(Redirect("http://localhost:5000"));
        }
Beispiel #4
0
        public WoWTwitterArea(AREA area, AreaDbContext DB)
        {
            this.area = area;
            string wow_access_token     = "";
            string twitter_access_token = "";
            string twitter_secret_token = "";

            foreach (var token in DB.tokens)
            {
                if (token.type == "WoW" && token.username == area.username)
                {
                    wow_access_token = token.value;
                }
                if (token.type == "TwitterAccessToken" && token.username == area.username)
                {
                    twitter_access_token = token.value;
                }
                if (token.type == "TwitterAccessTokenSecret" && token.username == area.username)
                {
                    twitter_secret_token = token.value;
                }
            }
            WoW     = new WoWModuleModel(wow_access_token, area.index_action);
            Twitter = new TwitterModule(twitter_access_token, twitter_secret_token, area.index_reaction);
        }
Beispiel #5
0
        public IActionResult ConfirmRegister([FromServices] AreaDbContext DB)
        {
            List <Models.ErrorLog> error = new List <Models.ErrorLog>();

            if (String.IsNullOrEmpty(HttpContext.Session.GetString("tmpCode")))
            {
                ClientGmail client = new ClientGmail();
                Random      rnd    = new Random();
                string      code   = rnd.Next(1000, 9999).ToString();

                HttpContext.Session.SetString("tmpCode", code);
                client.SendMail(HttpContext.Session.GetString("tmpEmail"), code);
            }
            else
            {
                Models.ErrorLog elem = new Models.ErrorLog();
                elem.message = "Wrong code entered";

                elem.enabl = true;
                HttpContext.Session.SetString("tmpCode", "");
                error.Add(elem);
            }
            ViewData["ErrorConf"] = error;
            return(View());
        }
Beispiel #6
0
        public void  run(AreaDbContext DB)
        {
            List <WoWCharacterModel> characters = DB.wowcharactermodels.ToList();

            if (WoW.getIndex() == 6)
            {
                List <WoWCharacterModel> new_characters = WoW.getCharacters();
                foreach (var character in new_characters)
                {
                    if (!WoW.alreadyExists(characters, character))
                    {
                        DB.wowcharactermodels.Add(character);
                        DB.SaveChanges();
                        Twitter.postReaction(WoW.getCharacterAction(character));
                    }
                }
            }
            else
            {
                foreach (var character in characters)
                {
                    if (WoW.checkAndUpdateCharacter(character, DB))
                    {
                        Twitter.postReaction(WoW.getCharacterAction(character));
                    }
                }
            }
        }
Beispiel #7
0
 public static IArea create(AREA area, AreaDbContext DB)
 {
     if (area.type == 1)
     {
         return(new WoWSpotifyArea(area, DB));
     }
     if (area.type == 2)
     {
         return(new WoWTwitterArea(area, DB));
     }
     if (area.type == 3)
     {
         return(new GithubFacebookArea(area, DB));
     }
     if (area.type == 4)
     {
         return(new SpotifyTwitterArea(area, DB));
     }
     if (area.type == 5)
     {
         return(new TwitterSpotifyArea(area, DB));
     }
     if (area.type == 6)
     {
         return(new FacebookTwitterArea(area, DB));
     }
     if (area.type == 7)
     {
         return(new FacebookSpotifyArea(area, DB));
     }
     return(null);
 }
Beispiel #8
0
 public void     updateCharacter(int stat, WoWCharacterModel character, AreaDbContext DB)
 {
     if (index == 1)
     {
         character.deaths = stat;
     }
     if (index == 2)
     {
         character.facepalmed = stat;
     }
     if (index == 3)
     {
         character.level = stat;
     }
     if (index == 4)
     {
         character.questsDone = stat;
     }
     if (index == 5)
     {
         character.fishCaught = stat;
     }
     DB.wowcharactermodels.Update(character);
     DB.SaveChanges();
 }
Beispiel #9
0
 public IActionResult Index([FromServices] AreaDbContext DB)
 {
     if (IsLog(DB))
     {
         return(View());
     }
     return(RedirectToAction("Login"));
 }
Beispiel #10
0
 public IActionResult ManageArea([FromServices] AreaDbContext DB)
 {
     if (IsLog(DB))
     {
         return(RedirectToAction("ManageArea", "ManageArea"));
     }
     return(RedirectToAction("Login"));
 }
Beispiel #11
0
 public IActionResult Login([FromServices] AreaDbContext DB, FormLogin model)
 {
     if (!String.IsNullOrEmpty(model.username) && !String.IsNullOrEmpty(model.password))
     {
         HttpContext.Session.SetString("username", model.username);
         HttpContext.Session.SetString("passwd", model.password);
     }
     return(RedirectToAction("Index"));
 }
Beispiel #12
0
 public WoWCharacterModel findCharacterModel(string realm, string name, AreaDbContext DB)
 {
     foreach (var character in DB.wowcharactermodels)
     {
         if (character.realm == realm && character.name == name)
         {
             return(character);
         }
     }
     return(null);
 }
Beispiel #13
0
        public ActionResult WoWTestView(string realm, string name, [FromServices] AreaDbContext DB)
        {
            WoWModuleModel    WoW       = new WoWModuleModel("vgf6ne9wt7buaewe48wby99u", 0);
            WoWCharacterModel character = WoW.getAllInfos(realm, name);

            ViewData["Level"]      = character.level;
            ViewData["Deaths"]     = character.deaths;
            ViewData["Quests"]     = character.questsDone;
            ViewData["Facepalmed"] = character.facepalmed;
            ViewData["Fish"]       = character.fishCaught;
            return(View());
        }
        public void  run(AreaDbContext DB)
        {
            string action = Github.getAction();

            if (action != area.last_event)
            {
                Facebook.PostOnFacebook(action);
                area.last_event = action;
                DB.areas.Update(area);
                DB.SaveChanges();
            }
        }
Beispiel #15
0
        public bool   checkAndUpdateCharacter(WoWCharacterModel charact, AreaDbContext DB)
        {
            int stat = getNewCharacterStat(charact.realm, charact.name);

            if (stat > getCurrentCharacterStat(charact))
            {
                Console.WriteLine(charact.name + " stat: " + stat + " current_stat : " + getCurrentCharacterStat(charact));
                updateCharacter(stat, charact, DB);
                return(true);
            }
            return(false);
        }
Beispiel #16
0
        public ActionResult ManageArea([FromServices] AreaDbContext DB)
        {
            string username = HttpContext.Session.GetString("username");

            if (String.IsNullOrEmpty(username))
            {
                return(RedirectToAction("Login", "Home"));
            }
            ViewData["active_areas"]      = getActiveAreas(DB, username);
            ViewData["available_areas"]   = getAvailableAreas(DB, username);
            ViewData["unavailable_areas"] = getUnavailableAreas(DB, username);
            return(View());
        }
Beispiel #17
0
        public static AreaType  findAreaTypeById(AreaDbContext DB, int id)
        {
            List <AreaType> areatypes = DB.areatypes.ToList();

            foreach (var areatype in areatypes)
            {
                if (areatype.id == id)
                {
                    return(areatype);
                }
            }
            return(null);
        }
        public void run(AreaDbContext DB)
        {
            string tweet = twitter.getAction();

            if (tweet == null || tweet == last_event)
            {
                return;
            }
            last_event      = tweet;
            area.last_event = tweet;
            DB.areas.Update(area);
            DB.SaveChanges();
            spotify.postReaction(tweet);
        }
Beispiel #19
0
        public void run(AreaDbContext DB)
        {
            string info = facebook.getAction();

            if (info == null || info == last_event)
            {
                return;
            }
            last_event      = info;
            area.last_event = info;
            DB.areas.Update(area);
            DB.SaveChanges();
            twitter.postReaction(info);
        }
Beispiel #20
0
        public IActionResult Register([FromServices] AreaDbContext DB)
        {
            List <Models.ErrorLog> error = new List <Models.ErrorLog>();

            Models.ErrorLog elem = new Models.ErrorLog();
            elem.message = "Passwords don't match";

            elem.enabl = !(HttpContext.Session.GetString("tmpPass") == HttpContext.Session.GetString("tmpConfirm"));
            HttpContext.Session.SetString("tmpConfirm", "");
            HttpContext.Session.SetString("tmpPass", "");
            error.Add(elem);
            ViewData["ErrorReg"] = error;
            return(View());
        }
Beispiel #21
0
        public void run(AreaDbContext DB)
        {
            string music = spotify.getAction();

            if (music == null || music == last_event)
            {
                return;
            }
            last_event      = music;
            area.last_event = music;
            DB.areas.Update(area);
            DB.SaveChanges();
            twitter.postReaction("Currently play: " + music);
        }
Beispiel #22
0
        public IActionResult Login([FromServices] AreaDbContext DB)
        {
            List <Models.ErrorLog> error = new List <Models.ErrorLog>();

            Models.ErrorLog elem = new Models.ErrorLog();
            elem.message = "Wrong User or Password";

            elem.enabl = !(String.IsNullOrEmpty(HttpContext.Session.GetString("username")) && String.IsNullOrEmpty(HttpContext.Session.GetString("password")));
            HttpContext.Session.SetString("username", "");
            HttpContext.Session.SetString("passwd", "");
            error.Add(elem);
            ViewData["ErrorLog"] = error;
            return(View());
        }
Beispiel #23
0
 public IActionResult Register([FromServices] AreaDbContext DB, FormRegister model)
 {
     if (!String.IsNullOrEmpty(model.username) && !String.IsNullOrEmpty(model.password) &&
         !String.IsNullOrEmpty(model.confirmation) && !String.IsNullOrEmpty(model.email))
     {
         HttpContext.Session.SetString("tmpUser", model.username);
         HttpContext.Session.SetString("tmpPass", model.password);
         HttpContext.Session.SetString("tmpConfirm", model.confirmation);
         HttpContext.Session.SetString("tmpEmail", model.email);
         if (model.password == model.confirmation)
         {
             return(RedirectToAction("ConfirmRegister"));
         }
     }
     return(RedirectToAction("Register"));
 }
Beispiel #24
0
 public IActionResult ConfirmRegister([FromServices] AreaDbContext DB, FormCode model)
 {
     if (!String.IsNullOrEmpty(model.code))
     {
         if (model.code == HttpContext.Session.GetString("tmpCode"))
         {
             DB.users.Add(new Models.User {
                 username = HttpContext.Session.GetString("tmpUser"), password = HttpContext.Session.GetString("tmpPass"), email = HttpContext.Session.GetString("tmpEmail"), enabled = true
             });
             DB.SaveChanges();
             HttpContext.Session.SetString("tmpCode", "");
             return(RedirectToAction("Index"));
         }
     }
     return(RedirectToAction("ConfirmRegister"));
 }
Beispiel #25
0
        private List <AreaType> getActiveAreas(AreaDbContext DB, string username)
        {
            List <AreaType> active_areatypes = new List <AreaType>();
            List <AREA>     active_areas     = DB.areas.ToList();

            foreach (var active_area in active_areas)
            {
                if (active_area.username == username)
                {
                    AreaType active_areatype = AreaType.findAreaTypeById(DB, active_area.type);
                    if (active_areatype != null)
                    {
                        active_areatypes.Add(active_areatype);
                    }
                }
            }
            return(active_areatypes);
        }
 public FacebookSpotifyArea(AREA area, AreaDbContext DB)
 {
     this.area       = area;
     this.username   = area.username;
     this.last_event = area.last_event;
     foreach (var token in DB.tokens)
     {
         if (token.type == "Spotify" && token.username == area.username)
         {
             spotifyToken = token.value;
         }
         if (token.type == "Facebook" && token.username == area.username)
         {
             facebookToken = token.value;
         }
     }
     spotify  = new SpotifyModule(spotifyToken, area.index_reaction);
     facebook = new FacebookModule(facebookToken, area.index_action);
 }
        public GithubFacebookArea(AREA area, AreaDbContext DB)
        {
            this.area = area;
            string github_access_token   = "";
            string facebook_access_token = "";

            foreach (var token in DB.tokens)
            {
                if (token.type == "Github" && token.username == area.username)
                {
                    github_access_token = token.value;
                }
                if (token.type == "Facebook" && token.username == area.username)
                {
                    facebook_access_token = token.value;
                }
            }
            Github   = new GithubModuleModel(github_access_token, area.index_action);
            Facebook = new FacebookModule(facebook_access_token, area.index_reaction);
        }
Beispiel #28
0
        public WoWSpotifyArea(AREA area, AreaDbContext DB)
        {
            this.area = area;
            string wow_access_token     = "";
            string spotify_access_token = "";

            foreach (var token in DB.tokens)
            {
                if (token.type == "WoW" && token.username == area.username)
                {
                    wow_access_token = token.value;
                }
                if (token.type == "Spotify" && token.username == area.username)
                {
                    spotify_access_token = token.value;
                }
            }
            WoW     = new WoWModuleModel(wow_access_token, area.index_action);
            Spotify = new SpotifyModule(spotify_access_token, area.index_reaction);
        }
Beispiel #29
0
        private List <AreaType> getUnavailableAreas(AreaDbContext DB, string username)
        {
            List <AreaType> unavailable_areatypes = new List <AreaType>();
            List <AreaType> all_areatypes         = DB.areatypes.ToList();
            AREA            tmp = new AREA();

            tmp.username       = username;
            tmp.index_action   = 0;
            tmp.index_reaction = 0;
            tmp.last_event     = "";
            foreach (var area_type in all_areatypes)
            {
                tmp.type = area_type.id;
                IArea type = AreaFactory.create(tmp, DB);
                if (type != null && !type.isAvailable())
                {
                    unavailable_areatypes.Add(area_type);
                }
            }
            return(unavailable_areatypes);
        }
Beispiel #30
0
 public SpotifyTwitterArea(AREA area, AreaDbContext DB)
 {
     this.area       = area;
     this.username   = area.username;
     this.last_event = area.last_event;
     foreach (var token in DB.tokens)
     {
         if (token.type == "Spotify" && token.username == area.username)
         {
             spotifyToken = token.value;
         }
         if (token.type == "TwitterAccessToken" && token.username == area.username)
         {
             twitterToken = token.value;
         }
         if (token.type == "TwitterAccessTokenSecret" && token.username == area.username)
         {
             twitterTokenSecret = token.value;
         }
     }
     spotify = new SpotifyModule(spotifyToken, area.index_action);
     twitter = new TwitterModule(twitterToken, twitterTokenSecret, area.index_reaction);
 }